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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_) { | 135 if (hashes_ready_ && !FinishBlock()) |
136 if (!FinishBlock()) | 136 DispatchFailureCallback(HASH_MISMATCH); |
137 DispatchFailureCallback(HASH_MISMATCH); | 137 |
138 else if (g_test_observer) | 138 if (!failed_ && g_test_observer) |
139 g_test_observer->JobFinished(hash_reader_->extension_id(), | 139 g_test_observer->JobFinished( |
140 hash_reader_->relative_path(), failed_); | 140 hash_reader_->extension_id(), hash_reader_->relative_path(), failed_); |
141 } | |
142 } | 141 } |
143 | 142 |
144 bool ContentVerifyJob::FinishBlock() { | 143 bool ContentVerifyJob::FinishBlock() { |
145 if (current_hash_byte_count_ <= 0) | 144 if (current_hash_byte_count_ <= 0) |
146 return true; | 145 return true; |
147 std::string final(crypto::kSHA256Length, 0); | 146 std::string final(crypto::kSHA256Length, 0); |
148 current_hash_->Finish(string_as_array(&final), final.size()); | 147 current_hash_->Finish(string_as_array(&final), final.size()); |
149 current_hash_.reset(); | 148 current_hash_.reset(); |
150 current_hash_byte_count_ = 0; | 149 current_hash_byte_count_ = 0; |
151 | 150 |
(...skipping 24 matching lines...) Expand all Loading... |
176 hashes_ready_ = true; | 175 hashes_ready_ = true; |
177 if (!queue_.empty()) { | 176 if (!queue_.empty()) { |
178 std::string tmp; | 177 std::string tmp; |
179 queue_.swap(tmp); | 178 queue_.swap(tmp); |
180 BytesRead(tmp.size(), string_as_array(&tmp)); | 179 BytesRead(tmp.size(), string_as_array(&tmp)); |
181 } | 180 } |
182 if (done_reading_) { | 181 if (done_reading_) { |
183 ScopedElapsedTimer timer(&time_spent_); | 182 ScopedElapsedTimer timer(&time_spent_); |
184 if (!FinishBlock()) | 183 if (!FinishBlock()) |
185 DispatchFailureCallback(HASH_MISMATCH); | 184 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 } | |
190 } | 185 } |
191 } | 186 } |
192 | 187 |
193 // static | 188 // static |
194 void ContentVerifyJob::SetDelegateForTests(TestDelegate* delegate) { | 189 void ContentVerifyJob::SetDelegateForTests(TestDelegate* delegate) { |
195 g_test_delegate = delegate; | 190 g_test_delegate = delegate; |
196 } | 191 } |
197 | 192 |
198 // static | 193 // static |
199 void ContentVerifyJob::SetObserverForTests(TestObserver* observer) { | 194 void ContentVerifyJob::SetObserverForTests(TestObserver* observer) { |
200 g_test_observer = observer; | 195 g_test_observer = observer; |
201 } | 196 } |
202 | 197 |
203 void ContentVerifyJob::DispatchFailureCallback(FailureReason reason) { | 198 void ContentVerifyJob::DispatchFailureCallback(FailureReason reason) { |
204 DCHECK(!failed_); | 199 DCHECK(!failed_); |
205 failed_ = true; | 200 failed_ = true; |
206 if (!failure_callback_.is_null()) { | 201 if (!failure_callback_.is_null()) { |
207 VLOG(1) << "job failed for " << hash_reader_->extension_id() << " " | 202 VLOG(1) << "job failed for " << hash_reader_->extension_id() << " " |
208 << hash_reader_->relative_path().MaybeAsASCII() | 203 << hash_reader_->relative_path().MaybeAsASCII() |
209 << " reason:" << reason; | 204 << " reason:" << reason; |
210 failure_callback_.Run(reason); | 205 failure_callback_.Run(reason); |
211 failure_callback_.Reset(); | 206 failure_callback_.Reset(); |
212 } | 207 } |
213 if (g_test_observer) | 208 if (g_test_observer) |
214 g_test_observer->JobFinished( | 209 g_test_observer->JobFinished( |
215 hash_reader_->extension_id(), hash_reader_->relative_path(), failed_); | 210 hash_reader_->extension_id(), hash_reader_->relative_path(), failed_); |
216 } | 211 } |
217 | 212 |
218 } // namespace extensions | 213 } // namespace extensions |
OLD | NEW |