OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef EXTENSIONS_BROWSER_CONTENT_HASH_READER_H_ |
| 6 #define EXTENSIONS_BROWSER_CONTENT_HASH_READER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 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" |
| 15 |
| 16 namespace extensions { |
| 17 |
| 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> { |
| 22 public: |
| 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); |
| 30 |
| 31 const std::string& extension_id() const { return extension_id_; } |
| 32 const base::FilePath& relative_path() const { return relative_path_; } |
| 33 |
| 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. |
| 38 bool Init(); |
| 39 |
| 40 // Return the number of blocks and block size, respectively. Only valid after |
| 41 // calling Init(). |
| 42 int block_count() const; |
| 43 int block_size() const; |
| 44 |
| 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; |
| 48 |
| 49 private: |
| 50 friend class base::RefCountedThreadSafe<ContentHashReader>; |
| 51 virtual ~ContentHashReader(); |
| 52 |
| 53 bool ReadHashes(const base::FilePath& hashes_file); |
| 54 |
| 55 std::string extension_id_; |
| 56 base::Version extension_version_; |
| 57 base::FilePath extension_root_; |
| 58 base::FilePath relative_path_; |
| 59 ContentVerifierKey key_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(ContentHashReader); |
| 62 }; |
| 63 |
| 64 } // namespace extensions |
| 65 |
| 66 #endif // EXTENSIONS_BROWSER_CONTENT_HASH_READER_H_ |
OLD | NEW |