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

Side by Side Diff: chrome/browser/icon_loader.cc

Issue 2953633002: Move the IconLoader to use the task scheduler. (Closed)
Patch Set: Created 3 years, 6 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 | « chrome/browser/icon_loader.h ('k') | chrome/browser/icon_loader_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/icon_loader.h" 5 #include "chrome/browser/icon_loader.h"
6 6
7 #include <utility>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/task_scheduler/post_task.h"
11 #include "base/task_scheduler/task_traits.h"
8 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
9 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
10 14
11 using content::BrowserThread; 15 using content::BrowserThread;
12 16
13 // static 17 // static
14 IconLoader* IconLoader::Create(const base::FilePath& file_path, 18 IconLoader* IconLoader::Create(const base::FilePath& file_path,
15 IconSize size, 19 IconSize size,
16 IconLoadedCallback callback) { 20 IconLoadedCallback callback) {
17 return new IconLoader(file_path, size, callback); 21 return new IconLoader(file_path, size, callback);
18 } 22 }
19 23
20 void IconLoader::Start() { 24 void IconLoader::Start() {
21 target_task_runner_ = base::ThreadTaskRunnerHandle::Get(); 25 target_task_runner_ = base::ThreadTaskRunnerHandle::Get();
22 26
23 BrowserThread::PostTaskAndReply( 27 base::PostTaskWithTraitsAndReply(
24 BrowserThread::FILE, FROM_HERE, 28 FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE},
25 base::BindOnce(&IconLoader::ReadGroup, base::Unretained(this)), 29 base::BindOnce(&IconLoader::ReadGroup, base::Unretained(this)),
26 base::BindOnce(&IconLoader::OnReadGroup, base::Unretained(this))); 30 base::BindOnce(&IconLoader::OnReadGroup, base::Unretained(this)));
27 } 31 }
28 32
29 IconLoader::IconLoader(const base::FilePath& file_path, 33 IconLoader::IconLoader(const base::FilePath& file_path,
30 IconSize size, 34 IconSize size,
31 IconLoadedCallback callback) 35 IconLoadedCallback callback)
32 : file_path_(file_path), icon_size_(size), callback_(callback) {} 36 : file_path_(file_path), icon_size_(size), callback_(callback) {}
33 37
34 IconLoader::~IconLoader() {} 38 IconLoader::~IconLoader() {}
35 39
36 void IconLoader::ReadGroup() { 40 void IconLoader::ReadGroup() {
37 group_ = GroupForFilepath(file_path_); 41 group_ = GroupForFilepath(file_path_);
38 } 42 }
39 43
40 void IconLoader::OnReadGroup() { 44 void IconLoader::OnReadGroup() {
41 BrowserThread::PostTask( 45 auto read_icon =
42 ReadIconThreadID(), FROM_HERE, 46 base::BindOnce(&IconLoader::ReadIcon, base::Unretained(this));
43 base::BindOnce(&IconLoader::ReadIcon, base::Unretained(this))); 47 if (ReadIconRequiresUIThread()) {
48 content::BrowserThread::GetTaskRunnerForThread(content::BrowserThread::UI)
49 ->PostTask(FROM_HERE, std::move(read_icon));
gab 2017/06/22 15:38:35 content::BrowserThread::PostTask(content::BrowserT
50 } else {
51 base::PostTaskWithTraits(
gab 2017/06/22 15:38:35 If you need COM you'll need to (on OS_WIN): base:
52 FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE},
sky 2017/06/22 00:43:25 optional: create a function to return the traits t
Avi (use Gerrit) 2017/06/22 01:21:17 Ben: Is that the style for the new PostTask?
gab 2017/06/22 15:38:35 TaskTraits is constexpr, you can store them in a c
53 std::move(read_icon));
54 }
44 } 55 }
OLDNEW
« no previous file with comments | « chrome/browser/icon_loader.h ('k') | chrome/browser/icon_loader_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698