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

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

Issue 1226163010: Fix content verifier problem with content scripts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merged latest head Created 5 years, 5 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 | « extensions/browser/content_verifier.cc ('k') | no next file » | 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.h" 9 #include "base/metrics/histogram.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 return; 125 return;
126 if (g_test_delegate) { 126 if (g_test_delegate) {
127 FailureReason reason = 127 FailureReason reason =
128 g_test_delegate->DoneReading(hash_reader_->extension_id()); 128 g_test_delegate->DoneReading(hash_reader_->extension_id());
129 if (reason != NONE) { 129 if (reason != NONE) {
130 DispatchFailureCallback(reason); 130 DispatchFailureCallback(reason);
131 return; 131 return;
132 } 132 }
133 } 133 }
134 done_reading_ = true; 134 done_reading_ = true;
135 if (hashes_ready_ && !FinishBlock()) 135 if (hashes_ready_) {
136 DispatchFailureCallback(HASH_MISMATCH); 136 if (!FinishBlock())
137 137 DispatchFailureCallback(HASH_MISMATCH);
138 if (!failed_ && g_test_observer) 138 else if (g_test_observer)
139 g_test_observer->JobFinished( 139 g_test_observer->JobFinished(hash_reader_->extension_id(),
140 hash_reader_->extension_id(), hash_reader_->relative_path(), failed_); 140 hash_reader_->relative_path(), failed_);
141 }
141 } 142 }
142 143
143 bool ContentVerifyJob::FinishBlock() { 144 bool ContentVerifyJob::FinishBlock() {
144 if (current_hash_byte_count_ <= 0) 145 if (current_hash_byte_count_ <= 0)
145 return true; 146 return true;
146 std::string final(crypto::kSHA256Length, 0); 147 std::string final(crypto::kSHA256Length, 0);
147 current_hash_->Finish(string_as_array(&final), final.size()); 148 current_hash_->Finish(string_as_array(&final), final.size());
148 current_hash_.reset(); 149 current_hash_.reset();
149 current_hash_byte_count_ = 0; 150 current_hash_byte_count_ = 0;
150 151
(...skipping 24 matching lines...) Expand all
175 hashes_ready_ = true; 176 hashes_ready_ = true;
176 if (!queue_.empty()) { 177 if (!queue_.empty()) {
177 std::string tmp; 178 std::string tmp;
178 queue_.swap(tmp); 179 queue_.swap(tmp);
179 BytesRead(tmp.size(), string_as_array(&tmp)); 180 BytesRead(tmp.size(), string_as_array(&tmp));
180 } 181 }
181 if (done_reading_) { 182 if (done_reading_) {
182 ScopedElapsedTimer timer(&time_spent_); 183 ScopedElapsedTimer timer(&time_spent_);
183 if (!FinishBlock()) 184 if (!FinishBlock())
184 DispatchFailureCallback(HASH_MISMATCH); 185 DispatchFailureCallback(HASH_MISMATCH);
186 else if (g_test_observer) {
187 g_test_observer->JobFinished(hash_reader_->extension_id(),
188 hash_reader_->relative_path(), failed_);
189 }
185 } 190 }
186 } 191 }
187 192
188 // static 193 // static
189 void ContentVerifyJob::SetDelegateForTests(TestDelegate* delegate) { 194 void ContentVerifyJob::SetDelegateForTests(TestDelegate* delegate) {
190 g_test_delegate = delegate; 195 g_test_delegate = delegate;
191 } 196 }
192 197
193 // static 198 // static
194 void ContentVerifyJob::SetObserverForTests(TestObserver* observer) { 199 void ContentVerifyJob::SetObserverForTests(TestObserver* observer) {
195 g_test_observer = observer; 200 g_test_observer = observer;
196 } 201 }
197 202
198 void ContentVerifyJob::DispatchFailureCallback(FailureReason reason) { 203 void ContentVerifyJob::DispatchFailureCallback(FailureReason reason) {
199 DCHECK(!failed_); 204 DCHECK(!failed_);
200 failed_ = true; 205 failed_ = true;
201 if (!failure_callback_.is_null()) { 206 if (!failure_callback_.is_null()) {
202 VLOG(1) << "job failed for " << hash_reader_->extension_id() << " " 207 VLOG(1) << "job failed for " << hash_reader_->extension_id() << " "
203 << hash_reader_->relative_path().MaybeAsASCII() 208 << hash_reader_->relative_path().MaybeAsASCII()
204 << " reason:" << reason; 209 << " reason:" << reason;
205 failure_callback_.Run(reason); 210 failure_callback_.Run(reason);
206 failure_callback_.Reset(); 211 failure_callback_.Reset();
207 } 212 }
208 if (g_test_observer) 213 if (g_test_observer)
209 g_test_observer->JobFinished( 214 g_test_observer->JobFinished(
210 hash_reader_->extension_id(), hash_reader_->relative_path(), failed_); 215 hash_reader_->extension_id(), hash_reader_->relative_path(), failed_);
211 } 216 }
212 217
213 } // namespace extensions 218 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/content_verifier.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698