Chromium Code Reviews| 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. If |
| 318 // the function enables redirection of SequencedWorkerPool to TaskScheduler, | |
| 319 // |sequenced_worker_pool_redirected| is set to true. | |
| 320 void MaybeInitializeTaskScheduler(bool* sequenced_worker_pool_redirected) { | |
|
gab
2016/11/01 21:48:02
Prefer return value to out-param.
fdoray
2016/11/02 12:56:09
Done.
| |
| 321 DCHECK(sequenced_worker_pool_redirected); | |
| 322 DCHECK(!*sequenced_worker_pool_redirected); | |
| 323 | |
| 318 static constexpr char kFieldTrialName[] = "BrowserScheduler"; | 324 static constexpr char kFieldTrialName[] = "BrowserScheduler"; |
| 319 std::map<std::string, std::string> variation_params; | 325 std::map<std::string, std::string> variation_params; |
| 320 if (!variations::GetVariationParams(kFieldTrialName, &variation_params)) { | 326 if (!variations::GetVariationParams(kFieldTrialName, &variation_params)) { |
| 321 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( | 327 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 322 switches::kEnableBrowserTaskScheduler)) | 328 switches::kEnableBrowserTaskScheduler)) |
| 323 << "The Browser Task Scheduler remains disabled with " | 329 << "The Browser Task Scheduler remains disabled with " |
| 324 << switches::kEnableBrowserTaskScheduler | 330 << switches::kEnableBrowserTaskScheduler |
| 325 << " because there is no available variation param for this build or " | 331 << " because there is no available variation param for this build or " |
| 326 " the task scheduler is disabled in chrome://flags."; | 332 " the task scheduler is disabled in chrome://flags."; |
| 327 return; | 333 return; |
| 328 } | 334 } |
| 329 | 335 |
| 330 if (!task_scheduler_util::InitializeDefaultTaskScheduler(variation_params)) | 336 if (!task_scheduler_util::InitializeDefaultTaskScheduler(variation_params)) |
| 331 return; | 337 return; |
| 332 | 338 |
| 333 // TODO(gab): Remove this when http://crbug.com/622400 concludes. | 339 // TODO(gab): Remove this when http://crbug.com/622400 concludes. |
| 334 const auto sequenced_worker_pool_param = | 340 const auto sequenced_worker_pool_param = |
| 335 variation_params.find("RedirectSequencedWorkerPools"); | 341 variation_params.find("RedirectSequencedWorkerPools"); |
| 336 if (sequenced_worker_pool_param != variation_params.end() && | 342 if (sequenced_worker_pool_param != variation_params.end() && |
| 337 sequenced_worker_pool_param->second == "true") { | 343 sequenced_worker_pool_param->second == "true") { |
| 338 base::SequencedWorkerPool::RedirectToTaskSchedulerForProcess(); | 344 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); |
| 345 *sequenced_worker_pool_redirected = true; | |
| 339 } | 346 } |
| 340 } | 347 } |
| 341 | 348 |
| 342 // Returns the new local state object, guaranteed non-NULL. | 349 // Returns the new local state object, guaranteed non-NULL. |
| 343 // |local_state_task_runner| must be a shutdown-blocking task runner. | 350 // |local_state_task_runner| must be a shutdown-blocking task runner. |
| 344 PrefService* InitializeLocalState( | 351 PrefService* InitializeLocalState( |
| 345 base::SequencedTaskRunner* local_state_task_runner, | 352 base::SequencedTaskRunner* local_state_task_runner, |
| 346 const base::CommandLine& parsed_command_line) { | 353 const base::CommandLine& parsed_command_line) { |
| 347 TRACE_EVENT0("startup", "ChromeBrowserMainParts::InitializeLocalState") | 354 TRACE_EVENT0("startup", "ChromeBrowserMainParts::InitializeLocalState") |
| 348 | 355 |
| (...skipping 873 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 | 1229 // 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 | 1230 // 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 | 1231 // 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. | 1232 // typically either belong before them or in a later startup phase. |
| 1226 | 1233 |
| 1227 // Now that the command line has been mutated based on about:flags, we can | 1234 // 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 | 1235 // initialize field trials and setup metrics. The field trials are needed by |
| 1229 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. | 1236 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. |
| 1230 SetupFieldTrials(); | 1237 SetupFieldTrials(); |
| 1231 | 1238 |
| 1232 // Task Scheduler initialization needs to be here for the following reasons: | 1239 // Initializing TaskScheduler and enabling SequencedWorkerPool needs to be |
| 1240 // here for the following reasons: | |
| 1233 // * After |SetupFieldTrials()|: Initialization uses variations. | 1241 // * After |SetupFieldTrials()|: Initialization uses variations. |
| 1234 // * Before |SetupMetrics()|: |SetupMetrics()| uses the blocking pool. The | 1242 // * Before |SetupMetrics()|: |SetupMetrics()| uses the blocking pool. The |
| 1235 // Task Scheduler must do any necessary redirection before then. | 1243 // Task Scheduler must do any necessary redirection before then. |
| 1236 // * Near the end of |PreCreateThreads()|: The TaskScheduler needs to be | 1244 // * Near the end of |PreCreateThreads()|: The TaskScheduler needs to be |
| 1237 // created before any other threads are (by contract) but it creates | 1245 // created before any other threads are (by contract) but it creates |
| 1238 // threads itself so instantiating it earlier is also incorrect. | 1246 // threads itself so instantiating it earlier is also incorrect. |
| 1239 // To maintain scoping symmetry, if this line is moved, the corresponding | 1247 // To maintain scoping symmetry, if this line is moved, the corresponding |
| 1240 // shutdown call may also need to be moved. | 1248 // shutdown call may also need to be moved. |
| 1241 MaybeInitializeTaskScheduler(); | 1249 bool sequenced_worker_pool_redirected = false; |
| 1250 MaybeInitializeTaskScheduler(&sequenced_worker_pool_redirected); | |
| 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 |