| 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 | 10 |
| 10 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/version.h" | 14 #include "base/version.h" |
| 14 #include "extensions/browser/content_verifier_delegate.h" | 15 #include "extensions/browser/content_verifier_delegate.h" |
| 15 | 16 |
| 16 namespace extensions { | 17 namespace extensions { |
| 17 | 18 |
| 19 class VerifiedContents; |
| 20 |
| 18 // This class creates an object that will read expected hashes that may have | 21 // 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 | 22 // been fetched/calculated by the ContentHashFetcher, and vends them out for |
| 20 // use in ContentVerifyJob's. | 23 // use in ContentVerifyJob's. |
| 21 class ContentHashReader : public base::RefCountedThreadSafe<ContentHashReader> { | 24 class ContentHashReader : public base::RefCountedThreadSafe<ContentHashReader> { |
| 22 public: | 25 public: |
| 23 // Create one of these to get expected hashes for the file at |relative_path| | 26 // Create one of these to get expected hashes for the file at |relative_path| |
| 24 // within an extension. | 27 // within an extension. |
| 25 ContentHashReader(const std::string& extension_id, | 28 ContentHashReader(const std::string& extension_id, |
| 26 const base::Version& extension_version, | 29 const base::Version& extension_version, |
| 27 const base::FilePath& extension_root, | 30 const base::FilePath& extension_root, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 43 int block_size() const; | 46 int block_size() const; |
| 44 | 47 |
| 45 // Returns a pointer to the expected sha256 hash value for the block at the | 48 // Returns a pointer to the expected sha256 hash value for the block at the |
| 46 // given index. Only valid after calling Init(). | 49 // given index. Only valid after calling Init(). |
| 47 bool GetHashForBlock(int block_index, const std::string** result) const; | 50 bool GetHashForBlock(int block_index, const std::string** result) const; |
| 48 | 51 |
| 49 private: | 52 private: |
| 50 friend class base::RefCountedThreadSafe<ContentHashReader>; | 53 friend class base::RefCountedThreadSafe<ContentHashReader>; |
| 51 virtual ~ContentHashReader(); | 54 virtual ~ContentHashReader(); |
| 52 | 55 |
| 53 bool ReadHashes(const base::FilePath& hashes_file); | 56 enum InitStatus { NOT_INITIALIZED, SUCCESS, FAILURE }; |
| 54 | 57 |
| 55 std::string extension_id_; | 58 std::string extension_id_; |
| 56 base::Version extension_version_; | 59 base::Version extension_version_; |
| 57 base::FilePath extension_root_; | 60 base::FilePath extension_root_; |
| 58 base::FilePath relative_path_; | 61 base::FilePath relative_path_; |
| 59 ContentVerifierKey key_; | 62 ContentVerifierKey key_; |
| 60 | 63 |
| 64 InitStatus status_; |
| 65 |
| 66 // The blocksize used for generating the hashes. |
| 67 int block_size_; |
| 68 |
| 69 scoped_ptr<VerifiedContents> verified_contents_; |
| 70 |
| 71 std::vector<std::string> hashes_; |
| 72 |
| 61 DISALLOW_COPY_AND_ASSIGN(ContentHashReader); | 73 DISALLOW_COPY_AND_ASSIGN(ContentHashReader); |
| 62 }; | 74 }; |
| 63 | 75 |
| 64 } // namespace extensions | 76 } // namespace extensions |
| 65 | 77 |
| 66 #endif // EXTENSIONS_BROWSER_CONTENT_HASH_READER_H_ | 78 #endif // EXTENSIONS_BROWSER_CONTENT_HASH_READER_H_ |
| OLD | NEW |