1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_BROWSER_CONTENT_HASH_READER_H_
6 #define EXTENSIONS_BROWSER_CONTENT_HASH_READER_H_
10 #include "base/files/file_path.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/version.h"
14 #include "extensions/browser/content_verifier_delegate.h"
16 namespace extensions
{
18 // This class creates an object that will read expected hashes that may have
19 // been fetched/calculated by the ContentHashFetcher, and vends them out for
20 // use in ContentVerifyJob's.
21 class ContentHashReader
: public base::RefCountedThreadSafe
<ContentHashReader
> {
23 // Create one of these to get expected hashes for the file at |relative_path|
24 // within an extension.
25 ContentHashReader(const std::string
& extension_id
,
26 const base::Version
& extension_version
,
27 const base::FilePath
& extension_root
,
28 const base::FilePath
& relative_path
,
29 const ContentVerifierKey
& key
);
31 const std::string
& extension_id() const { return extension_id_
; }
32 const base::FilePath
& relative_path() const { return relative_path_
; }
34 // This should be called to initialize this object (reads the expected hashes
35 // from storage, etc.). Must be called on a thread that is allowed to do file
36 // I/O. Returns a boolean indicating success/failure. On failure, this object
37 // should likely be discarded.
40 // Return the number of blocks and block size, respectively. Only valid after
42 int block_count() const;
43 int block_size() const;
45 // Returns a pointer to the expected sha256 hash value for the block at the
46 // given index. Only valid after calling Init().
47 bool GetHashForBlock(int block_index
, const std::string
** result
) const;
50 friend class base::RefCountedThreadSafe
<ContentHashReader
>;
51 virtual ~ContentHashReader();
53 bool ReadHashes(const base::FilePath
& hashes_file
);
55 std::string extension_id_
;
56 base::Version extension_version_
;
57 base::FilePath extension_root_
;
58 base::FilePath relative_path_
;
59 ContentVerifierKey key_
;
61 DISALLOW_COPY_AND_ASSIGN(ContentHashReader
);
64 } // namespace extensions
66 #endif // EXTENSIONS_BROWSER_CONTENT_HASH_READER_H_