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" |
11 #include "base/task_runner_util.h" | 11 #include "base/task_runner_util.h" |
12 #include "base/timer/elapsed_timer.h" | 12 #include "base/timer/elapsed_timer.h" |
13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
14 #include "crypto/secure_hash.h" | 14 #include "crypto/secure_hash.h" |
15 #include "crypto/sha2.h" | 15 #include "crypto/sha2.h" |
16 #include "extensions/browser/content_hash_reader.h" | 16 #include "extensions/browser/content_hash_reader.h" |
17 | 17 |
18 namespace extensions { | 18 namespace extensions { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 ContentVerifyJob::TestDelegate* g_test_delegate = NULL; | 22 ContentVerifyJob::TestDelegate* g_test_delegate = nullptr; |
23 | 23 |
24 class ScopedElapsedTimer { | 24 class ScopedElapsedTimer { |
25 public: | 25 public: |
26 ScopedElapsedTimer(base::TimeDelta* total) : total_(total) { DCHECK(total_); } | 26 ScopedElapsedTimer(base::TimeDelta* total) : total_(total) { DCHECK(total_); } |
27 | 27 |
28 ~ScopedElapsedTimer() { *total_ += timer.Elapsed(); } | 28 ~ScopedElapsedTimer() { *total_ += timer.Elapsed(); } |
29 | 29 |
30 private: | 30 private: |
31 // Some total amount of time we should add our elapsed time to at | 31 // Some total amount of time we should add our elapsed time to at |
32 // destruction. | 32 // destruction. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(); | 140 current_hash_.reset(); |
141 current_hash_byte_count_ = 0; | 141 current_hash_byte_count_ = 0; |
142 | 142 |
143 int block = current_block_++; | 143 int block = current_block_++; |
144 | 144 |
145 const std::string* expected_hash = NULL; | 145 const std::string* expected_hash = nullptr; |
146 if (!hash_reader_->GetHashForBlock(block, &expected_hash) || | 146 if (!hash_reader_->GetHashForBlock(block, &expected_hash) || |
147 *expected_hash != final) | 147 *expected_hash != final) |
148 return false; | 148 return false; |
149 | 149 |
150 return true; | 150 return true; |
151 } | 151 } |
152 | 152 |
153 void ContentVerifyJob::OnHashesReady(bool success) { | 153 void ContentVerifyJob::OnHashesReady(bool success) { |
154 if (!success && !g_test_delegate) { | 154 if (!success && !g_test_delegate) { |
155 if (!hash_reader_->content_exists()) { | 155 if (!hash_reader_->content_exists()) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 if (!failure_callback_.is_null()) { | 188 if (!failure_callback_.is_null()) { |
189 VLOG(1) << "job failed for " << hash_reader_->extension_id() << " " | 189 VLOG(1) << "job failed for " << hash_reader_->extension_id() << " " |
190 << hash_reader_->relative_path().MaybeAsASCII() | 190 << hash_reader_->relative_path().MaybeAsASCII() |
191 << " reason:" << reason; | 191 << " reason:" << reason; |
192 failure_callback_.Run(reason); | 192 failure_callback_.Run(reason); |
193 failure_callback_.Reset(); | 193 failure_callback_.Reset(); |
194 } | 194 } |
195 } | 195 } |
196 | 196 |
197 } // namespace extensions | 197 } // namespace extensions |
OLD | NEW |