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

Side by Side Diff: components/task_scheduler_util/initialization/browser_util.cc

Issue 2539263003: Move Task Scheduler Initialization From chrome/browser to Content (Closed)
Patch Set: Rebase to bf8e2f1 Created 4 years 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/task_scheduler_util/initialization/browser_util.h" 5 #include "components/task_scheduler_util/initialization/browser_util.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/task_scheduler/initialization_util.h" 10 #include "base/task_scheduler/initialization_util.h"
11 #include "base/task_scheduler/switches.h" 11 #include "base/task_scheduler/switches.h"
12 #include "base/task_scheduler/task_traits.h" 12 #include "base/task_scheduler/task_traits.h"
13 #include "base/threading/sequenced_worker_pool.h" 13 #include "base/threading/sequenced_worker_pool.h"
14 #include "build/build_config.h"
15 14
16 namespace task_scheduler_util { 15 namespace task_scheduler_util {
17 namespace initialization { 16 namespace initialization {
18 17
19 namespace { 18 namespace {
20 19
21 using StandbyThreadPolicy = 20 using StandbyThreadPolicy =
22 base::SchedulerWorkerPoolParams::StandbyThreadPolicy; 21 base::SchedulerWorkerPoolParams::StandbyThreadPolicy;
23 using ThreadPriority = base::ThreadPriority; 22 using ThreadPriority = base::ThreadPriority;
24 23
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // FOREGROUND_FILE_IO on any priorities other than background. 77 // FOREGROUND_FILE_IO on any priorities other than background.
79 size_t BrowserWorkerPoolIndexForTraits(const base::TaskTraits& traits) { 78 size_t BrowserWorkerPoolIndexForTraits(const base::TaskTraits& traits) {
80 const bool is_background = 79 const bool is_background =
81 traits.priority() == base::TaskPriority::BACKGROUND; 80 traits.priority() == base::TaskPriority::BACKGROUND;
82 if (traits.with_file_io()) 81 if (traits.with_file_io())
83 return is_background ? BACKGROUND_FILE_IO : FOREGROUND_FILE_IO; 82 return is_background ? BACKGROUND_FILE_IO : FOREGROUND_FILE_IO;
84 83
85 return is_background ? BACKGROUND : FOREGROUND; 84 return is_background ? BACKGROUND : FOREGROUND;
86 } 85 }
87 86
87 #if defined(OS_IOS)
88 std::vector<base::SchedulerWorkerPoolParams> 88 std::vector<base::SchedulerWorkerPoolParams>
89 GetDefaultBrowserSchedulerWorkerPoolParams() { 89 GetDefaultBrowserSchedulerWorkerPoolParams() {
90 constexpr size_t kNumWorkerPoolsDefined = 90 constexpr size_t kNumWorkerPoolsDefined =
91 sizeof(BrowserWorkerPoolsConfiguration) / 91 sizeof(BrowserWorkerPoolsConfiguration) /
92 sizeof(SingleWorkerPoolConfiguration); 92 sizeof(SingleWorkerPoolConfiguration);
93 static_assert(kNumWorkerPoolsDefined == 4, 93 static_assert(kNumWorkerPoolsDefined == 4,
94 "Expected 4 worker pools in BrowserWorkerPoolsConfiguration"); 94 "Expected 4 worker pools in BrowserWorkerPoolsConfiguration");
95 BrowserWorkerPoolsConfiguration config; 95 BrowserWorkerPoolsConfiguration config;
96 #if defined(OS_ANDROID) || defined(OS_IOS) 96 constexpr size_t kSizeAssignedFields =
97 sizeof(config.background.threads) +
98 sizeof(config.background.detach_period) +
99 sizeof(config.background.standby_thread_policy);
100 static_assert(kSizeAssignedFields == sizeof(config.background),
101 "Not all fields were assigned");
97 config.background.standby_thread_policy = StandbyThreadPolicy::ONE; 102 config.background.standby_thread_policy = StandbyThreadPolicy::ONE;
98 config.background.threads = 103 config.background.threads =
99 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0); 104 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0);
100 config.background.detach_period = base::TimeDelta::FromSeconds(30); 105 config.background.detach_period = base::TimeDelta::FromSeconds(30);
101 106
102 config.background_file_io.standby_thread_policy = StandbyThreadPolicy::ONE; 107 config.background_file_io.standby_thread_policy = StandbyThreadPolicy::ONE;
103 config.background_file_io.threads = 108 config.background_file_io.threads =
104 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0); 109 base::RecommendedMaxNumberOfThreadsInPool(2, 8, 0.1, 0);
105 config.background_file_io.detach_period = base::TimeDelta::FromSeconds(30); 110 config.background_file_io.detach_period = base::TimeDelta::FromSeconds(30);
106 111
107 config.foreground.standby_thread_policy = StandbyThreadPolicy::ONE; 112 config.foreground.standby_thread_policy = StandbyThreadPolicy::ONE;
108 config.foreground.threads = 113 config.foreground.threads =
109 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0); 114 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0);
110 config.foreground.detach_period = base::TimeDelta::FromSeconds(30); 115 config.foreground.detach_period = base::TimeDelta::FromSeconds(30);
111 116
112 config.foreground_file_io.standby_thread_policy = StandbyThreadPolicy::ONE; 117 config.foreground_file_io.standby_thread_policy = StandbyThreadPolicy::ONE;
113 config.foreground_file_io.threads = 118 config.foreground_file_io.threads =
114 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0); 119 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.3, 0);
115 config.foreground_file_io.detach_period = base::TimeDelta::FromSeconds(30); 120 config.foreground_file_io.detach_period = base::TimeDelta::FromSeconds(30);
116 #else
117 config.background.standby_thread_policy = StandbyThreadPolicy::ONE;
118 config.background.threads =
119 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0);
120 config.background.detach_period = base::TimeDelta::FromSeconds(30);
121
122 config.background_file_io.standby_thread_policy = StandbyThreadPolicy::ONE;
123 config.background_file_io.threads =
124 base::RecommendedMaxNumberOfThreadsInPool(3, 8, 0.1, 0);
125 config.background_file_io.detach_period = base::TimeDelta::FromSeconds(30);
126
127 config.foreground.standby_thread_policy = StandbyThreadPolicy::ONE;
128 config.foreground.threads =
129 base::RecommendedMaxNumberOfThreadsInPool(8, 32, 0.3, 0);
130 config.foreground.detach_period = base::TimeDelta::FromSeconds(30);
131
132 config.foreground_file_io.standby_thread_policy = StandbyThreadPolicy::ONE;
133 config.foreground_file_io.threads =
134 base::RecommendedMaxNumberOfThreadsInPool(8, 32, 0.3, 0);
135 config.foreground_file_io.detach_period = base::TimeDelta::FromSeconds(30);
136 #endif
137 return BrowserWorkerPoolConfigurationToSchedulerWorkerPoolParams(config); 121 return BrowserWorkerPoolConfigurationToSchedulerWorkerPoolParams(config);
138 } 122 }
123 #endif // defined(OS_IOS)
139 124
140 } // namespace initialization 125 } // namespace initialization
141 } // namespace task_scheduler_util 126 } // namespace task_scheduler_util
OLDNEW
« no previous file with comments | « components/task_scheduler_util/initialization/browser_util.h ('k') | components/task_scheduler_util/initialization_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698