| 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_VERIFY_JOB_H_ | 5 #ifndef EXTENSIONS_BROWSER_CONTENT_VERIFY_JOB_H_ |
| 6 #define EXTENSIONS_BROWSER_CONTENT_VERIFY_JOB_H_ | 6 #define EXTENSIONS_BROWSER_CONTENT_VERIFY_JOB_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // Objects of this class are responsible for verifying that the actual content | 27 // Objects of this class are responsible for verifying that the actual content |
| 28 // read from an extension file matches an expected set of hashes. This class | 28 // read from an extension file matches an expected set of hashes. This class |
| 29 // can be created on any thread but the rest of the methods should be called | 29 // can be created on any thread but the rest of the methods should be called |
| 30 // from only one thread. | 30 // from only one thread. |
| 31 class ContentVerifyJob : public base::RefCountedThreadSafe<ContentVerifyJob> { | 31 class ContentVerifyJob : public base::RefCountedThreadSafe<ContentVerifyJob> { |
| 32 public: | 32 public: |
| 33 enum FailureReason { | 33 enum FailureReason { |
| 34 // No failure. | 34 // No failure. |
| 35 NONE, | 35 NONE, |
| 36 | 36 |
| 37 // Failed because there were no expected hashes. | 37 // Failed because there were no expected hashes at all (eg they haven't |
| 38 NO_HASHES, | 38 // been fetched yet). |
| 39 MISSING_ALL_HASHES, |
| 40 |
| 41 // Failed because this file wasn't found in the list of expected hashes. |
| 42 NO_HASHES_FOR_FILE, |
| 39 | 43 |
| 40 // Some of the content read did not match the expected hash. | 44 // Some of the content read did not match the expected hash. |
| 41 HASH_MISMATCH | 45 HASH_MISMATCH |
| 42 }; | 46 }; |
| 43 typedef base::Callback<void(FailureReason)> FailureCallback; | 47 typedef base::Callback<void(FailureReason)> FailureCallback; |
| 44 | 48 |
| 45 // The |failure_callback| will be called at most once if there was a failure. | 49 // The |failure_callback| will be called at most once if there was a failure. |
| 46 ContentVerifyJob(ContentHashReader* hash_reader, | 50 ContentVerifyJob(ContentHashReader* hash_reader, |
| 47 const FailureCallback& failure_callback); | 51 const FailureCallback& failure_callback); |
| 48 | 52 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 74 | 78 |
| 75 static void SetDelegateForTests(TestDelegate* delegate); | 79 static void SetDelegateForTests(TestDelegate* delegate); |
| 76 | 80 |
| 77 private: | 81 private: |
| 78 DISALLOW_COPY_AND_ASSIGN(ContentVerifyJob); | 82 DISALLOW_COPY_AND_ASSIGN(ContentVerifyJob); |
| 79 | 83 |
| 80 virtual ~ContentVerifyJob(); | 84 virtual ~ContentVerifyJob(); |
| 81 friend class base::RefCountedThreadSafe<ContentVerifyJob>; | 85 friend class base::RefCountedThreadSafe<ContentVerifyJob>; |
| 82 | 86 |
| 83 // Called each time we're done adding bytes for the current block, and are | 87 // Called each time we're done adding bytes for the current block, and are |
| 84 // ready to finish the hash operation for those bytes and make sure it matches | 88 // ready to finish the hash operation for those bytes and make sure it |
| 85 // what was expected for that block. | 89 // matches what was expected for that block. Returns true if everything is |
| 86 void FinishBlock(); | 90 // still ok so far, or false if a mismatch was detected. |
| 91 bool FinishBlock(); |
| 87 | 92 |
| 88 // Dispatches the failure callback with the given reason. | 93 // Dispatches the failure callback with the given reason. |
| 89 void DispatchFailureCallback(FailureReason reason); | 94 void DispatchFailureCallback(FailureReason reason); |
| 90 | 95 |
| 91 // Called when our ContentHashReader has finished initializing. | 96 // Called when our ContentHashReader has finished initializing. |
| 92 void OnHashesReady(bool success); | 97 void OnHashesReady(bool success); |
| 93 | 98 |
| 94 // Indicates whether the caller has told us they are done calling BytesRead. | 99 // Indicates whether the caller has told us they are done calling BytesRead. |
| 95 bool done_reading_; | 100 bool done_reading_; |
| 96 | 101 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 111 scoped_ptr<crypto::SecureHash> current_hash_; | 116 scoped_ptr<crypto::SecureHash> current_hash_; |
| 112 | 117 |
| 113 // The number of bytes we've already input into |current_hash_|. | 118 // The number of bytes we've already input into |current_hash_|. |
| 114 int current_hash_byte_count_; | 119 int current_hash_byte_count_; |
| 115 | 120 |
| 116 scoped_refptr<ContentHashReader> hash_reader_; | 121 scoped_refptr<ContentHashReader> hash_reader_; |
| 117 | 122 |
| 118 // Called once if verification fails. | 123 // Called once if verification fails. |
| 119 FailureCallback failure_callback_; | 124 FailureCallback failure_callback_; |
| 120 | 125 |
| 126 // Set to true if we detected a mismatch and called the failure callback. |
| 127 bool failed_; |
| 128 |
| 121 // For ensuring methods on called on the right thread. | 129 // For ensuring methods on called on the right thread. |
| 122 base::ThreadChecker thread_checker_; | 130 base::ThreadChecker thread_checker_; |
| 123 }; | 131 }; |
| 124 | 132 |
| 125 } // namespace extensions | 133 } // namespace extensions |
| 126 | 134 |
| 127 #endif // EXTENSIONS_BROWSER_CONTENT_VERIFY_JOB_H_ | 135 #endif // EXTENSIONS_BROWSER_CONTENT_VERIFY_JOB_H_ |
| OLD | NEW |