Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Side by Side Diff: extensions/browser/content_verify_job.cc

Issue 2928693002: [Content verification] Fix a bug for files that are multiple of 4k bytes. (Closed)
Patch Set: address comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | extensions/browser/content_verify_job_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 if (!FinishBlock()) { 135 if (!FinishBlock()) {
136 DispatchFailureCallback(HASH_MISMATCH); 136 DispatchFailureCallback(HASH_MISMATCH);
137 } else if (g_test_observer) { 137 } else if (g_test_observer) {
138 g_test_observer->JobFinished(hash_reader_->extension_id(), 138 g_test_observer->JobFinished(hash_reader_->extension_id(),
139 hash_reader_->relative_path(), NONE); 139 hash_reader_->relative_path(), NONE);
140 } 140 }
141 } 141 }
142 } 142 }
143 143
144 bool ContentVerifyJob::FinishBlock() { 144 bool ContentVerifyJob::FinishBlock() {
145 if (!done_reading_ && current_hash_byte_count_ == 0) 145 if (current_hash_byte_count_ == 0) {
146 return true; 146 if (!done_reading_ ||
147 // If we have checked all blocks already, then nothing else to do here.
148 current_block_ == hash_reader_->block_count()) {
149 return true;
150 }
151 }
147 if (!current_hash_) { 152 if (!current_hash_) {
148 // This happens when we fail to read the resource. Compute empty content's 153 // This happens when we fail to read the resource. Compute empty content's
149 // hash in this case. 154 // hash in this case.
150 current_hash_ = crypto::SecureHash::Create(crypto::SecureHash::SHA256); 155 current_hash_ = crypto::SecureHash::Create(crypto::SecureHash::SHA256);
151 } 156 }
152 std::string final(crypto::kSHA256Length, 0); 157 std::string final(crypto::kSHA256Length, 0);
153 current_hash_->Finish(base::string_as_array(& final), final.size()); 158 current_hash_->Finish(base::string_as_array(& final), final.size());
154 current_hash_.reset(); 159 current_hash_.reset();
155 current_hash_byte_count_ = 0; 160 current_hash_byte_count_ = 0;
156 161
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 << " reason:" << reason; 232 << " reason:" << reason;
228 std::move(failure_callback_).Run(reason); 233 std::move(failure_callback_).Run(reason);
229 } 234 }
230 if (g_test_observer) { 235 if (g_test_observer) {
231 g_test_observer->JobFinished(hash_reader_->extension_id(), 236 g_test_observer->JobFinished(hash_reader_->extension_id(),
232 hash_reader_->relative_path(), reason); 237 hash_reader_->relative_path(), reason);
233 } 238 }
234 } 239 }
235 240
236 } // namespace extensions 241 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/browser/content_verify_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698