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

Side by Side Diff: components/task_scheduler_util/initialization_util.cc

Issue 2539263003: Move Task Scheduler Initialization From chrome/browser to Content (Closed)
Patch Set: 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_util.h" 5 #include "components/task_scheduler_util/initialization_util.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 variation_values.standby_thread_policy, 163 variation_values.standby_thread_policy,
164 variation_values.threads, 164 variation_values.threads,
165 variation_values.detach_period); 165 variation_values.detach_period);
166 } 166 }
167 DCHECK_EQ(WORKER_POOL_COUNT, params_vector.size()); 167 DCHECK_EQ(WORKER_POOL_COUNT, params_vector.size());
168 return params_vector; 168 return params_vector;
169 } 169 }
170 170
171 } // namespace 171 } // namespace
172 172
173 void InitializeDefaultBrowserTaskScheduler() { 173 void InitializeDefaultBrowserTaskScheduler() {
gab 2016/11/30 22:36:58 This is still used by iOS I guess?
robliao 2016/11/30 22:46:57 Yep! This goes away when iOS moves, which will be
174 std::vector<base::SchedulerWorkerPoolParams> params_vector;
175 base::TaskScheduler::WorkerPoolIndexForTraitsCallback
176 index_to_traits_callback;
177 GetBrowserTaskSchedulerInitParameters(
178 &params_vector, &index_to_traits_callback);
179 base::TaskScheduler::CreateAndSetDefaultTaskScheduler(
180 params_vector, base::Bind(WorkerPoolIndexForTraits));
181
182 MaybePerformRedirectionToTaskScheduler();
183 }
184
185 void GetBrowserTaskSchedulerInitParameters(
186 std::vector<base::SchedulerWorkerPoolParams>* params_vector,
187 base::TaskScheduler::WorkerPoolIndexForTraitsCallback*
188 index_to_traits_callback) {
174 static constexpr char kFieldTrialName[] = "BrowserScheduler"; 189 static constexpr char kFieldTrialName[] = "BrowserScheduler";
175 std::map<std::string, std::string> variation_params; 190 std::map<std::string, std::string> variation_params;
176 if (!variations::GetVariationParams(kFieldTrialName, &variation_params)) 191 if (!variations::GetVariationParams(kFieldTrialName, &variation_params))
177 variation_params = GetDefaultBrowserVariationParams(); 192 variation_params = GetDefaultBrowserVariationParams();
178 193
179 auto params_vector = 194 *params_vector =
180 VariationsParamsToBrowserSchedulerWorkerPoolParams(variation_params); 195 VariationsParamsToBrowserSchedulerWorkerPoolParams(variation_params);
181 if (params_vector.empty()) { 196 if (params_vector->empty()) {
182 variation_params = GetDefaultBrowserVariationParams(); 197 variation_params = GetDefaultBrowserVariationParams();
183 params_vector = 198 *params_vector =
184 VariationsParamsToBrowserSchedulerWorkerPoolParams(variation_params); 199 VariationsParamsToBrowserSchedulerWorkerPoolParams(variation_params);
185 DCHECK(!params_vector.empty()); 200 DCHECK(!params_vector->empty());
186 } 201 }
187 base::TaskScheduler::CreateAndSetDefaultTaskScheduler(
188 params_vector, base::Bind(WorkerPoolIndexForTraits));
189 202
203 *index_to_traits_callback = base::Bind(WorkerPoolIndexForTraits);
204 }
205
206 void MaybePerformRedirectionToTaskScheduler() {
190 // TODO(gab): Remove this when http://crbug.com/622400 concludes. 207 // TODO(gab): Remove this when http://crbug.com/622400 concludes.
208 static constexpr char kFieldTrialName[] = "BrowserScheduler";
209 std::map<std::string, std::string> variation_params;
210 if (!variations::GetVariationParams(kFieldTrialName, &variation_params))
gab 2016/11/30 22:36:58 I think we should have defaults for individual fie
robliao 2016/11/30 22:46:57 I believe this is the nature of how things are str
gab 2016/11/30 23:10:38 If we fail to get variations then ChromeContentBro
robliao 2016/11/30 23:45:21 The main reason for this is that the failure path:
211 variation_params = GetDefaultBrowserVariationParams();
212
191 const auto sequenced_worker_pool_param = 213 const auto sequenced_worker_pool_param =
192 variation_params.find("RedirectSequencedWorkerPools"); 214 variation_params.find("RedirectSequencedWorkerPools");
193 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 215 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
194 switches::kDisableBrowserTaskScheduler) && 216 switches::kDisableBrowserTaskScheduler) &&
195 sequenced_worker_pool_param != variation_params.end() && 217 sequenced_worker_pool_param != variation_params.end() &&
196 sequenced_worker_pool_param->second == "true") { 218 sequenced_worker_pool_param->second == "true") {
197 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); 219 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess();
198 } else { 220 } else {
199 base::SequencedWorkerPool::EnableForProcess(); 221 base::SequencedWorkerPool::EnableForProcess();
200 } 222 }
201 } 223 }
202 224
203 } // namespace task_scheduler_util 225 } // namespace task_scheduler_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698