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