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_hash_fetcher.h" | 5 #include "extensions/browser/content_hash_fetcher.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/base64.h" | 13 #include "base/base64.h" |
14 #include "base/files/file_enumerator.h" | 14 #include "base/files/file_enumerator.h" |
15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
16 #include "base/json/json_reader.h" | 16 #include "base/json/json_reader.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
19 #include "base/metrics/histogram_macros.h" | 19 #include "base/metrics/histogram_macros.h" |
20 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
21 #include "base/task_scheduler/post_task.h" | 21 #include "base/task_runner_util.h" |
| 22 #include "base/threading/sequenced_worker_pool.h" |
22 #include "base/timer/elapsed_timer.h" | 23 #include "base/timer/elapsed_timer.h" |
23 #include "base/version.h" | 24 #include "base/version.h" |
24 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
25 #include "crypto/sha2.h" | 26 #include "crypto/sha2.h" |
26 #include "extensions/browser/computed_hashes.h" | 27 #include "extensions/browser/computed_hashes.h" |
27 #include "extensions/browser/content_hash_tree.h" | 28 #include "extensions/browser/content_hash_tree.h" |
28 #include "extensions/browser/content_verifier_delegate.h" | 29 #include "extensions/browser/content_verifier_delegate.h" |
29 #include "extensions/browser/verified_contents.h" | 30 #include "extensions/browser/verified_contents.h" |
30 #include "extensions/common/constants.h" | 31 #include "extensions/common/constants.h" |
31 #include "extensions/common/extension.h" | 32 #include "extensions/common/extension.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 block_size_(4096), | 189 block_size_(4096), |
189 cancelled_(false) { | 190 cancelled_(false) { |
190 bool got_id = | 191 bool got_id = |
191 content::BrowserThread::GetCurrentThreadIdentifier(&creation_thread_); | 192 content::BrowserThread::GetCurrentThreadIdentifier(&creation_thread_); |
192 DCHECK(got_id); | 193 DCHECK(got_id); |
193 } | 194 } |
194 | 195 |
195 void ContentHashFetcherJob::Start() { | 196 void ContentHashFetcherJob::Start() { |
196 base::FilePath verified_contents_path = | 197 base::FilePath verified_contents_path = |
197 file_util::GetVerifiedContentsPath(extension_path_); | 198 file_util::GetVerifiedContentsPath(extension_path_); |
198 base::PostTaskWithTraitsAndReplyWithResult( | 199 base::PostTaskAndReplyWithResult( |
199 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( | 200 content::BrowserThread::GetBlockingPool(), |
200 base::TaskPriority::USER_VISIBLE), | 201 FROM_HERE, |
201 base::Bind(&ContentHashFetcherJob::LoadVerifiedContents, this, | 202 base::Bind(&ContentHashFetcherJob::LoadVerifiedContents, |
| 203 this, |
202 verified_contents_path), | 204 verified_contents_path), |
203 base::Bind(&ContentHashFetcherJob::DoneCheckingForVerifiedContents, | 205 base::Bind(&ContentHashFetcherJob::DoneCheckingForVerifiedContents, |
204 this)); | 206 this)); |
205 } | 207 } |
206 | 208 |
207 void ContentHashFetcherJob::Cancel() { | 209 void ContentHashFetcherJob::Cancel() { |
208 base::AutoLock autolock(cancelled_lock_); | 210 base::AutoLock autolock(cancelled_lock_); |
209 cancelled_ = true; | 211 cancelled_ = true; |
210 } | 212 } |
211 | 213 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 // the right cookies). TODO(asargent) - It would be a nice enhancement to | 282 // the right cookies). TODO(asargent) - It would be a nice enhancement to |
281 // move to parsing this in a sandboxed helper (crbug.com/372878). | 283 // move to parsing this in a sandboxed helper (crbug.com/372878). |
282 std::unique_ptr<base::Value> parsed(base::JSONReader::Read(*response)); | 284 std::unique_ptr<base::Value> parsed(base::JSONReader::Read(*response)); |
283 if (parsed) { | 285 if (parsed) { |
284 VLOG(1) << "JSON parsed ok for " << extension_id_; | 286 VLOG(1) << "JSON parsed ok for " << extension_id_; |
285 | 287 |
286 parsed.reset(); // no longer needed | 288 parsed.reset(); // no longer needed |
287 base::FilePath destination = | 289 base::FilePath destination = |
288 file_util::GetVerifiedContentsPath(extension_path_); | 290 file_util::GetVerifiedContentsPath(extension_path_); |
289 size_t size = response->size(); | 291 size_t size = response->size(); |
290 base::PostTaskWithTraitsAndReplyWithResult( | 292 base::PostTaskAndReplyWithResult( |
291 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( | 293 content::BrowserThread::GetBlockingPool(), |
292 base::TaskPriority::USER_VISIBLE), | 294 FROM_HERE, |
293 base::Bind(&WriteFileHelper, destination, base::Passed(&response)), | 295 base::Bind(&WriteFileHelper, destination, base::Passed(&response)), |
294 base::Bind(&ContentHashFetcherJob::OnVerifiedContentsWritten, this, | 296 base::Bind( |
295 size)); | 297 &ContentHashFetcherJob::OnVerifiedContentsWritten, this, size)); |
296 } else { | 298 } else { |
297 DoneFetchingVerifiedContents(false); | 299 DoneFetchingVerifiedContents(false); |
298 } | 300 } |
299 } | 301 } |
300 | 302 |
301 void ContentHashFetcherJob::OnVerifiedContentsWritten(size_t expected_size, | 303 void ContentHashFetcherJob::OnVerifiedContentsWritten(size_t expected_size, |
302 int write_result) { | 304 int write_result) { |
303 bool success = | 305 bool success = |
304 (write_result >= 0 && static_cast<size_t>(write_result) == expected_size); | 306 (write_result >= 0 && static_cast<size_t>(write_result) == expected_size); |
305 DoneFetchingVerifiedContents(success); | 307 DoneFetchingVerifiedContents(success); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 | 499 |
498 for (JobMap::iterator i = jobs_.begin(); i != jobs_.end(); ++i) { | 500 for (JobMap::iterator i = jobs_.begin(); i != jobs_.end(); ++i) { |
499 if (i->second.get() == job) { | 501 if (i->second.get() == job) { |
500 jobs_.erase(i); | 502 jobs_.erase(i); |
501 break; | 503 break; |
502 } | 504 } |
503 } | 505 } |
504 } | 506 } |
505 | 507 |
506 } // namespace extensions | 508 } // namespace extensions |
OLD | NEW |