| 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 #include "extensions/browser/content_verify_job.h" | 5 #include "extensions/browser/content_verify_job.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 queue_.append(data, count); | 89 queue_.append(data, count); |
| 90 return; | 90 return; |
| 91 } | 91 } |
| 92 DCHECK_GE(count, 0); | 92 DCHECK_GE(count, 0); |
| 93 int bytes_added = 0; | 93 int bytes_added = 0; |
| 94 | 94 |
| 95 while (bytes_added < count) { | 95 while (bytes_added < count) { |
| 96 if (current_block_ >= hash_reader_->block_count()) | 96 if (current_block_ >= hash_reader_->block_count()) |
| 97 return DispatchFailureCallback(HASH_MISMATCH); | 97 return DispatchFailureCallback(HASH_MISMATCH); |
| 98 | 98 |
| 99 if (!current_hash_.get()) { | 99 if (!current_hash_) { |
| 100 current_hash_byte_count_ = 0; | 100 current_hash_byte_count_ = 0; |
| 101 current_hash_.reset( | 101 current_hash_ = crypto::SecureHash::Create(crypto::SecureHash::SHA256); |
| 102 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); | |
| 103 } | 102 } |
| 104 // Compute how many bytes we should hash, and add them to the current hash. | 103 // Compute how many bytes we should hash, and add them to the current hash. |
| 105 int bytes_to_hash = | 104 int bytes_to_hash = |
| 106 std::min(hash_reader_->block_size() - current_hash_byte_count_, | 105 std::min(hash_reader_->block_size() - current_hash_byte_count_, |
| 107 count - bytes_added); | 106 count - bytes_added); |
| 108 DCHECK_GT(bytes_to_hash, 0); | 107 DCHECK_GT(bytes_to_hash, 0); |
| 109 current_hash_->Update(data + bytes_added, bytes_to_hash); | 108 current_hash_->Update(data + bytes_added, bytes_to_hash); |
| 110 bytes_added += bytes_to_hash; | 109 bytes_added += bytes_to_hash; |
| 111 current_hash_byte_count_ += bytes_to_hash; | 110 current_hash_byte_count_ += bytes_to_hash; |
| 112 total_bytes_read_ += bytes_to_hash; | 111 total_bytes_read_ += bytes_to_hash; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 << " reason:" << reason; | 213 << " reason:" << reason; |
| 215 failure_callback_.Run(reason); | 214 failure_callback_.Run(reason); |
| 216 failure_callback_.Reset(); | 215 failure_callback_.Reset(); |
| 217 } | 216 } |
| 218 if (g_test_observer) | 217 if (g_test_observer) |
| 219 g_test_observer->JobFinished( | 218 g_test_observer->JobFinished( |
| 220 hash_reader_->extension_id(), hash_reader_->relative_path(), failed_); | 219 hash_reader_->extension_id(), hash_reader_->relative_path(), failed_); |
| 221 } | 220 } |
| 222 | 221 |
| 223 } // namespace extensions | 222 } // namespace extensions |
| OLD | NEW |