| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef EXTENSIONS_BROWSER_CONTENT_HASH_READER_H_ | 5 #ifndef EXTENSIONS_BROWSER_CONTENT_HASH_READER_H_ |
| 6 #define EXTENSIONS_BROWSER_CONTENT_HASH_READER_H_ | 6 #define EXTENSIONS_BROWSER_CONTENT_HASH_READER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 const std::string& extension_id() const { return extension_id_; } | 33 const std::string& extension_id() const { return extension_id_; } |
| 34 const base::FilePath& relative_path() const { return relative_path_; } | 34 const base::FilePath& relative_path() const { return relative_path_; } |
| 35 | 35 |
| 36 // This should be called to initialize this object (reads the expected hashes | 36 // This should be called to initialize this object (reads the expected hashes |
| 37 // from storage, etc.). Must be called on a thread that is allowed to do file | 37 // from storage, etc.). Must be called on a thread that is allowed to do file |
| 38 // I/O. Returns a boolean indicating success/failure. On failure, this object | 38 // I/O. Returns a boolean indicating success/failure. On failure, this object |
| 39 // should likely be discarded. | 39 // should likely be discarded. |
| 40 bool Init(); | 40 bool Init(); |
| 41 | 41 |
| 42 // Indicates whether the content in question exists in the local extension | |
| 43 // installation. This may be |false| if Init fails. | |
| 44 bool content_exists() const { return content_exists_; } | |
| 45 | |
| 46 // These return whether we found valid verified_contents.json / | 42 // These return whether we found valid verified_contents.json / |
| 47 // computed_hashes.json files respectively. Note that both of these can be | 43 // computed_hashes.json files respectively. Note that both of these can be |
| 48 // true but we still didn't find an entry for |relative_path_| in them. | 44 // true but we still didn't find an entry for |relative_path_| in them. |
| 49 bool have_verified_contents() const { return have_verified_contents_; } | 45 bool have_verified_contents() const { return have_verified_contents_; } |
| 50 bool have_computed_hashes() const { return have_computed_hashes_; } | 46 bool have_computed_hashes() const { return have_computed_hashes_; } |
| 47 // Returns whether or not this resource's entry exists in |
| 48 // verified_contents.json (given that both |have_verified_contents_| and |
| 49 // |have_computed_hashes_| are true). |
| 50 bool file_missing_from_verified_contents() const { |
| 51 return file_missing_from_verified_contents_; |
| 52 } |
| 51 | 53 |
| 52 // Return the number of blocks and block size, respectively. Only valid after | 54 // Return the number of blocks and block size, respectively. Only valid after |
| 53 // calling Init(). | 55 // calling Init(). |
| 54 int block_count() const; | 56 int block_count() const; |
| 55 int block_size() const; | 57 int block_size() const; |
| 56 | 58 |
| 57 // Returns a pointer to the expected sha256 hash value for the block at the | 59 // Returns a pointer to the expected sha256 hash value for the block at the |
| 58 // given index. Only valid after calling Init(). | 60 // given index. Only valid after calling Init(). |
| 59 bool GetHashForBlock(int block_index, const std::string** result) const; | 61 bool GetHashForBlock(int block_index, const std::string** result) const; |
| 60 | 62 |
| 61 private: | 63 private: |
| 62 friend class base::RefCountedThreadSafe<ContentHashReader>; | 64 friend class base::RefCountedThreadSafe<ContentHashReader>; |
| 63 virtual ~ContentHashReader(); | 65 virtual ~ContentHashReader(); |
| 64 | 66 |
| 65 enum InitStatus { NOT_INITIALIZED, SUCCESS, FAILURE }; | 67 enum InitStatus { NOT_INITIALIZED, SUCCESS, FAILURE }; |
| 66 | 68 |
| 67 std::string extension_id_; | 69 std::string extension_id_; |
| 68 base::Version extension_version_; | 70 base::Version extension_version_; |
| 69 base::FilePath extension_root_; | 71 base::FilePath extension_root_; |
| 70 base::FilePath relative_path_; | 72 base::FilePath relative_path_; |
| 71 ContentVerifierKey key_; | 73 ContentVerifierKey key_; |
| 72 | 74 |
| 73 InitStatus status_; | 75 InitStatus status_; |
| 74 | 76 |
| 75 bool content_exists_; | |
| 76 | |
| 77 bool have_verified_contents_; | 77 bool have_verified_contents_; |
| 78 bool have_computed_hashes_; | 78 bool have_computed_hashes_; |
| 79 bool file_missing_from_verified_contents_; |
| 79 | 80 |
| 80 // The blocksize used for generating the hashes. | 81 // The blocksize used for generating the hashes. |
| 81 int block_size_; | 82 int block_size_; |
| 82 | 83 |
| 83 std::vector<std::string> hashes_; | 84 std::vector<std::string> hashes_; |
| 84 | 85 |
| 85 DISALLOW_COPY_AND_ASSIGN(ContentHashReader); | 86 DISALLOW_COPY_AND_ASSIGN(ContentHashReader); |
| 86 }; | 87 }; |
| 87 | 88 |
| 88 } // namespace extensions | 89 } // namespace extensions |
| 89 | 90 |
| 90 #endif // EXTENSIONS_BROWSER_CONTENT_HASH_READER_H_ | 91 #endif // EXTENSIONS_BROWSER_CONTENT_HASH_READER_H_ |
| OLD | NEW |