OLD | NEW |
---|---|
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/chrome_browser_main.h" | 5 #include "chrome/browser/chrome_browser_main.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 void AddFirstRunNewTabs(StartupBrowserCreator* browser_creator, | 307 void AddFirstRunNewTabs(StartupBrowserCreator* browser_creator, |
308 const std::vector<GURL>& new_tabs) { | 308 const std::vector<GURL>& new_tabs) { |
309 for (std::vector<GURL>::const_iterator it = new_tabs.begin(); | 309 for (std::vector<GURL>::const_iterator it = new_tabs.begin(); |
310 it != new_tabs.end(); ++it) { | 310 it != new_tabs.end(); ++it) { |
311 if (it->is_valid()) | 311 if (it->is_valid()) |
312 browser_creator->AddFirstRunTab(*it); | 312 browser_creator->AddFirstRunTab(*it); |
313 } | 313 } |
314 } | 314 } |
315 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 315 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
316 | 316 |
317 void MaybeInitializeTaskScheduler() { | 317 // Initializes TaskScheduler if enabled via field trial or command line flag. |
318 // The function returns true if it enables redirection of SequencedWorkerPool to | |
319 // TaskScheduler. | |
320 bool MaybeInitializeTaskScheduler() { | |
321 bool sequenced_worker_pool_redirected = false; | |
322 | |
318 static constexpr char kFieldTrialName[] = "BrowserScheduler"; | 323 static constexpr char kFieldTrialName[] = "BrowserScheduler"; |
319 std::map<std::string, std::string> variation_params; | 324 std::map<std::string, std::string> variation_params; |
320 if (!variations::GetVariationParams(kFieldTrialName, &variation_params)) { | 325 if (!variations::GetVariationParams(kFieldTrialName, &variation_params)) { |
321 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( | 326 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( |
322 switches::kEnableBrowserTaskScheduler)) | 327 switches::kEnableBrowserTaskScheduler)) |
323 << "The Browser Task Scheduler remains disabled with " | 328 << "The Browser Task Scheduler remains disabled with " |
324 << switches::kEnableBrowserTaskScheduler | 329 << switches::kEnableBrowserTaskScheduler |
325 << " because there is no available variation param for this build or " | 330 << " because there is no available variation param for this build or " |
326 " the task scheduler is disabled in chrome://flags."; | 331 " the task scheduler is disabled in chrome://flags."; |
327 return; | 332 return sequenced_worker_pool_redirected; |
gab
2016/11/02 13:29:55
No var, just return false on each failure and retu
fdoray
2016/11/02 20:02:16
We may reach the end of the method without having
| |
328 } | 333 } |
329 | 334 |
330 if (!task_scheduler_util::InitializeDefaultTaskScheduler(variation_params)) | 335 if (!task_scheduler_util::InitializeDefaultTaskScheduler(variation_params)) |
331 return; | 336 return sequenced_worker_pool_redirected; |
332 | 337 |
333 // TODO(gab): Remove this when http://crbug.com/622400 concludes. | 338 // TODO(gab): Remove this when http://crbug.com/622400 concludes. |
334 const auto sequenced_worker_pool_param = | 339 const auto sequenced_worker_pool_param = |
335 variation_params.find("RedirectSequencedWorkerPools"); | 340 variation_params.find("RedirectSequencedWorkerPools"); |
336 if (sequenced_worker_pool_param != variation_params.end() && | 341 if (sequenced_worker_pool_param != variation_params.end() && |
337 sequenced_worker_pool_param->second == "true") { | 342 sequenced_worker_pool_param->second == "true") { |
338 base::SequencedWorkerPool::RedirectToTaskSchedulerForProcess(); | 343 sequenced_worker_pool_redirected = true; |
344 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); | |
339 } | 345 } |
346 | |
347 return sequenced_worker_pool_redirected; | |
340 } | 348 } |
341 | 349 |
342 // Returns the new local state object, guaranteed non-NULL. | 350 // Returns the new local state object, guaranteed non-NULL. |
343 // |local_state_task_runner| must be a shutdown-blocking task runner. | 351 // |local_state_task_runner| must be a shutdown-blocking task runner. |
344 PrefService* InitializeLocalState( | 352 PrefService* InitializeLocalState( |
345 base::SequencedTaskRunner* local_state_task_runner, | 353 base::SequencedTaskRunner* local_state_task_runner, |
346 const base::CommandLine& parsed_command_line) { | 354 const base::CommandLine& parsed_command_line) { |
347 TRACE_EVENT0("startup", "ChromeBrowserMainParts::InitializeLocalState") | 355 TRACE_EVENT0("startup", "ChromeBrowserMainParts::InitializeLocalState") |
348 | 356 |
349 // Load local state. This includes the application locale so we know which | 357 // Load local state. This includes the application locale so we know which |
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1222 // Do not add anything below this line until you've verified your new code | 1230 // Do not add anything below this line until you've verified your new code |
1223 // does not interfere with the critical initialization order below. Some of | 1231 // does not interfere with the critical initialization order below. Some of |
1224 // the calls below end up implicitly creating threads and as such new calls | 1232 // the calls below end up implicitly creating threads and as such new calls |
1225 // typically either belong before them or in a later startup phase. | 1233 // typically either belong before them or in a later startup phase. |
1226 | 1234 |
1227 // Now that the command line has been mutated based on about:flags, we can | 1235 // Now that the command line has been mutated based on about:flags, we can |
1228 // initialize field trials and setup metrics. The field trials are needed by | 1236 // initialize field trials and setup metrics. The field trials are needed by |
1229 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. | 1237 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. |
1230 SetupFieldTrials(); | 1238 SetupFieldTrials(); |
1231 | 1239 |
1232 // Task Scheduler initialization needs to be here for the following reasons: | 1240 // Initializing TaskScheduler and enabling SequencedWorkerPool needs to be |
1241 // here for the following reasons: | |
1233 // * After |SetupFieldTrials()|: Initialization uses variations. | 1242 // * After |SetupFieldTrials()|: Initialization uses variations. |
1234 // * Before |SetupMetrics()|: |SetupMetrics()| uses the blocking pool. The | 1243 // * Before |SetupMetrics()|: |SetupMetrics()| uses the blocking pool. The |
1235 // Task Scheduler must do any necessary redirection before then. | 1244 // Task Scheduler must do any necessary redirection before then. |
1236 // * Near the end of |PreCreateThreads()|: The TaskScheduler needs to be | 1245 // * Near the end of |PreCreateThreads()|: The TaskScheduler needs to be |
1237 // created before any other threads are (by contract) but it creates | 1246 // created before any other threads are (by contract) but it creates |
1238 // threads itself so instantiating it earlier is also incorrect. | 1247 // threads itself so instantiating it earlier is also incorrect. |
1239 // To maintain scoping symmetry, if this line is moved, the corresponding | 1248 // To maintain scoping symmetry, if this line is moved, the corresponding |
1240 // shutdown call may also need to be moved. | 1249 // shutdown call may also need to be moved. |
1241 MaybeInitializeTaskScheduler(); | 1250 const bool sequenced_worker_pool_redirected = MaybeInitializeTaskScheduler(); |
1251 | |
1252 // If MaybeInitializeTaskScheduler() hasn't enabled SequencedWorkerPool with | |
1253 // redirection to TaskScheduler, enable it without redirection. | |
1254 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler | |
1255 // redirection experiment concludes https://crbug.com/622400. | |
1256 if (!sequenced_worker_pool_redirected) | |
1257 base::SequencedWorkerPool::EnableForProcess(); | |
1242 | 1258 |
1243 SetupMetrics(); | 1259 SetupMetrics(); |
1244 | 1260 |
1245 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. | 1261 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. |
1246 // This also instantiates the IOThread which requests the metrics service and | 1262 // This also instantiates the IOThread which requests the metrics service and |
1247 // must be after |SetupMetrics()|. | 1263 // must be after |SetupMetrics()|. |
1248 browser_process_->PreCreateThreads(); | 1264 browser_process_->PreCreateThreads(); |
1249 | 1265 |
1250 return content::RESULT_CODE_NORMAL_EXIT; | 1266 return content::RESULT_CODE_NORMAL_EXIT; |
1251 } | 1267 } |
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2111 chromeos::CrosSettings::Shutdown(); | 2127 chromeos::CrosSettings::Shutdown(); |
2112 #endif // defined(OS_CHROMEOS) | 2128 #endif // defined(OS_CHROMEOS) |
2113 #endif // defined(OS_ANDROID) | 2129 #endif // defined(OS_ANDROID) |
2114 } | 2130 } |
2115 | 2131 |
2116 // Public members: | 2132 // Public members: |
2117 | 2133 |
2118 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { | 2134 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { |
2119 chrome_extra_parts_.push_back(parts); | 2135 chrome_extra_parts_.push_back(parts); |
2120 } | 2136 } |
OLD | NEW |