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