| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 done_reading_ = true; | 130 done_reading_ = true; |
| 131 if (hashes_ready_ && !FinishBlock()) | 131 if (hashes_ready_ && !FinishBlock()) |
| 132 DispatchFailureCallback(HASH_MISMATCH); | 132 DispatchFailureCallback(HASH_MISMATCH); |
| 133 } | 133 } |
| 134 | 134 |
| 135 bool ContentVerifyJob::FinishBlock() { | 135 bool ContentVerifyJob::FinishBlock() { |
| 136 if (current_hash_byte_count_ <= 0) | 136 if (current_hash_byte_count_ <= 0) |
| 137 return true; | 137 return true; |
| 138 std::string final(crypto::kSHA256Length, 0); | 138 std::string final(crypto::kSHA256Length, 0); |
| 139 current_hash_->Finish(string_as_array(&final), final.size()); | 139 current_hash_->Finish(string_as_array(&final), final.size()); |
| 140 current_hash_.reset(); |
| 141 current_hash_byte_count_ = 0; |
| 142 |
| 143 int block = current_block_++; |
| 140 | 144 |
| 141 const std::string* expected_hash = NULL; | 145 const std::string* expected_hash = NULL; |
| 142 if (!hash_reader_->GetHashForBlock(current_block_, &expected_hash) || | 146 if (!hash_reader_->GetHashForBlock(block, &expected_hash) || |
| 143 *expected_hash != final) | 147 *expected_hash != final) |
| 144 return false; | 148 return false; |
| 145 | 149 |
| 146 current_hash_.reset(); | |
| 147 current_hash_byte_count_ = 0; | |
| 148 current_block_++; | |
| 149 return true; | 150 return true; |
| 150 } | 151 } |
| 151 | 152 |
| 152 void ContentVerifyJob::OnHashesReady(bool success) { | 153 void ContentVerifyJob::OnHashesReady(bool success) { |
| 153 if (!success && !g_test_delegate) { | 154 if (!success && !g_test_delegate) { |
| 154 if (hash_reader_->have_verified_contents() && | 155 if (hash_reader_->have_verified_contents() && |
| 155 hash_reader_->have_computed_hashes()) | 156 hash_reader_->have_computed_hashes()) |
| 156 DispatchFailureCallback(NO_HASHES_FOR_FILE); | 157 DispatchFailureCallback(NO_HASHES_FOR_FILE); |
| 157 else | 158 else |
| 158 DispatchFailureCallback(MISSING_ALL_HASHES); | 159 DispatchFailureCallback(MISSING_ALL_HASHES); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 183 if (!failure_callback_.is_null()) { | 184 if (!failure_callback_.is_null()) { |
| 184 VLOG(1) << "job failed for " << hash_reader_->extension_id() << " " | 185 VLOG(1) << "job failed for " << hash_reader_->extension_id() << " " |
| 185 << hash_reader_->relative_path().MaybeAsASCII() | 186 << hash_reader_->relative_path().MaybeAsASCII() |
| 186 << " reason:" << reason; | 187 << " reason:" << reason; |
| 187 failure_callback_.Run(reason); | 188 failure_callback_.Run(reason); |
| 188 failure_callback_.Reset(); | 189 failure_callback_.Reset(); |
| 189 } | 190 } |
| 190 } | 191 } |
| 191 | 192 |
| 192 } // namespace extensions | 193 } // namespace extensions |
| OLD | NEW |