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

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

Issue 2672623006: Use TaskScheduler instead of blocking pool in content_hash_fetcher.cc. (Closed)
Patch Set: upload Created 3 years, 10 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 | « no previous file | 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_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/timer/elapsed_timer.h" 22 #include "base/timer/elapsed_timer.h"
23 #include "base/version.h" 23 #include "base/version.h"
24 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
25 #include "crypto/sha2.h" 25 #include "crypto/sha2.h"
26 #include "extensions/browser/computed_hashes.h" 26 #include "extensions/browser/computed_hashes.h"
27 #include "extensions/browser/content_hash_tree.h" 27 #include "extensions/browser/content_hash_tree.h"
28 #include "extensions/browser/content_verifier_delegate.h" 28 #include "extensions/browser/content_verifier_delegate.h"
29 #include "extensions/browser/verified_contents.h" 29 #include "extensions/browser/verified_contents.h"
30 #include "extensions/common/constants.h" 30 #include "extensions/common/constants.h"
31 #include "extensions/common/extension.h" 31 #include "extensions/common/extension.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 block_size_(4096), 188 block_size_(4096),
189 cancelled_(false) { 189 cancelled_(false) {
190 bool got_id = 190 bool got_id =
191 content::BrowserThread::GetCurrentThreadIdentifier(&creation_thread_); 191 content::BrowserThread::GetCurrentThreadIdentifier(&creation_thread_);
192 DCHECK(got_id); 192 DCHECK(got_id);
193 } 193 }
194 194
195 void ContentHashFetcherJob::Start() { 195 void ContentHashFetcherJob::Start() {
196 base::FilePath verified_contents_path = 196 base::FilePath verified_contents_path =
197 file_util::GetVerifiedContentsPath(extension_path_); 197 file_util::GetVerifiedContentsPath(extension_path_);
198 base::PostTaskAndReplyWithResult( 198 base::PostTaskWithTraitsAndReplyWithResult(
199 content::BrowserThread::GetBlockingPool(), 199 FROM_HERE, base::TaskTraits().MayBlock().WithPriority(
200 FROM_HERE, 200 base::TaskPriority::BACKGROUND),
Devlin 2017/02/15 16:17:17 WithPriority() USER_VISIBLE This is in response t
201 base::Bind(&ContentHashFetcherJob::LoadVerifiedContents, 201 base::Bind(&ContentHashFetcherJob::LoadVerifiedContents, this,
202 this,
203 verified_contents_path), 202 verified_contents_path),
204 base::Bind(&ContentHashFetcherJob::DoneCheckingForVerifiedContents, 203 base::Bind(&ContentHashFetcherJob::DoneCheckingForVerifiedContents,
205 this)); 204 this));
206 } 205 }
207 206
208 void ContentHashFetcherJob::Cancel() { 207 void ContentHashFetcherJob::Cancel() {
209 base::AutoLock autolock(cancelled_lock_); 208 base::AutoLock autolock(cancelled_lock_);
210 cancelled_ = true; 209 cancelled_ = true;
211 } 210 }
212 211
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 // 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
282 // move to parsing this in a sandboxed helper (crbug.com/372878). 281 // move to parsing this in a sandboxed helper (crbug.com/372878).
283 std::unique_ptr<base::Value> parsed(base::JSONReader::Read(*response)); 282 std::unique_ptr<base::Value> parsed(base::JSONReader::Read(*response));
284 if (parsed) { 283 if (parsed) {
285 VLOG(1) << "JSON parsed ok for " << extension_id_; 284 VLOG(1) << "JSON parsed ok for " << extension_id_;
286 285
287 parsed.reset(); // no longer needed 286 parsed.reset(); // no longer needed
288 base::FilePath destination = 287 base::FilePath destination =
289 file_util::GetVerifiedContentsPath(extension_path_); 288 file_util::GetVerifiedContentsPath(extension_path_);
290 size_t size = response->size(); 289 size_t size = response->size();
291 base::PostTaskAndReplyWithResult( 290 base::PostTaskWithTraitsAndReplyWithResult(
292 content::BrowserThread::GetBlockingPool(), 291 FROM_HERE, base::TaskTraits().MayBlock().WithPriority(
293 FROM_HERE, 292 base::TaskPriority::BACKGROUND),
294 base::Bind(&WriteFileHelper, destination, base::Passed(&response)), 293 base::Bind(&WriteFileHelper, destination, base::Passed(&response)),
295 base::Bind( 294 base::Bind(&ContentHashFetcherJob::OnVerifiedContentsWritten, this,
296 &ContentHashFetcherJob::OnVerifiedContentsWritten, this, size)); 295 size));
297 } else { 296 } else {
298 DoneFetchingVerifiedContents(false); 297 DoneFetchingVerifiedContents(false);
299 } 298 }
300 } 299 }
301 300
302 void ContentHashFetcherJob::OnVerifiedContentsWritten(size_t expected_size, 301 void ContentHashFetcherJob::OnVerifiedContentsWritten(size_t expected_size,
303 int write_result) { 302 int write_result) {
304 bool success = 303 bool success =
305 (write_result >= 0 && static_cast<size_t>(write_result) == expected_size); 304 (write_result >= 0 && static_cast<size_t>(write_result) == expected_size);
306 DoneFetchingVerifiedContents(success); 305 DoneFetchingVerifiedContents(success);
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 497
499 for (JobMap::iterator i = jobs_.begin(); i != jobs_.end(); ++i) { 498 for (JobMap::iterator i = jobs_.begin(); i != jobs_.end(); ++i) {
500 if (i->second.get() == job) { 499 if (i->second.get() == job) {
501 jobs_.erase(i); 500 jobs_.erase(i);
502 break; 501 break;
503 } 502 }
504 } 503 }
505 } 504 }
506 505
507 } // namespace extensions 506 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698