| 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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 void AddFirstRunNewTabs(StartupBrowserCreator* browser_creator, | 308 void AddFirstRunNewTabs(StartupBrowserCreator* browser_creator, |
| 309 const std::vector<GURL>& new_tabs) { | 309 const std::vector<GURL>& new_tabs) { |
| 310 for (std::vector<GURL>::const_iterator it = new_tabs.begin(); | 310 for (std::vector<GURL>::const_iterator it = new_tabs.begin(); |
| 311 it != new_tabs.end(); ++it) { | 311 it != new_tabs.end(); ++it) { |
| 312 if (it->is_valid()) | 312 if (it->is_valid()) |
| 313 browser_creator->AddFirstRunTab(*it); | 313 browser_creator->AddFirstRunTab(*it); |
| 314 } | 314 } |
| 315 } | 315 } |
| 316 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 316 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
| 317 | 317 |
| 318 // Initializes TaskScheduler if enabled via field trial or command line flag. | 318 void MaybeInitializeTaskScheduler() { |
| 319 // The function returns true if it enables redirection of SequencedWorkerPool to | |
| 320 // TaskScheduler. | |
| 321 bool MaybeInitializeTaskScheduler() { | |
| 322 bool sequenced_worker_pool_redirected = false; | |
| 323 | |
| 324 static constexpr char kFieldTrialName[] = "BrowserScheduler"; | 319 static constexpr char kFieldTrialName[] = "BrowserScheduler"; |
| 325 std::map<std::string, std::string> variation_params; | 320 std::map<std::string, std::string> variation_params; |
| 326 if (!variations::GetVariationParams(kFieldTrialName, &variation_params)) { | 321 if (!variations::GetVariationParams(kFieldTrialName, &variation_params)) { |
| 327 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( | 322 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 328 switches::kEnableBrowserTaskScheduler)) | 323 switches::kEnableBrowserTaskScheduler)) |
| 329 << "The Browser Task Scheduler remains disabled with " | 324 << "The Browser Task Scheduler remains disabled with " |
| 330 << switches::kEnableBrowserTaskScheduler | 325 << switches::kEnableBrowserTaskScheduler |
| 331 << " because there is no available variation param for this build or " | 326 << " because there is no available variation param for this build or " |
| 332 " the task scheduler is disabled in chrome://flags."; | 327 " the task scheduler is disabled in chrome://flags."; |
| 333 return sequenced_worker_pool_redirected; | 328 return; |
| 334 } | 329 } |
| 335 | 330 |
| 336 if (!task_scheduler_util::InitializeDefaultTaskScheduler(variation_params)) | 331 if (!task_scheduler_util::InitializeDefaultTaskScheduler(variation_params)) |
| 337 return sequenced_worker_pool_redirected; | 332 return; |
| 338 | 333 |
| 339 // TODO(gab): Remove this when http://crbug.com/622400 concludes. | 334 // TODO(gab): Remove this when http://crbug.com/622400 concludes. |
| 340 const auto sequenced_worker_pool_param = | 335 const auto sequenced_worker_pool_param = |
| 341 variation_params.find("RedirectSequencedWorkerPools"); | 336 variation_params.find("RedirectSequencedWorkerPools"); |
| 342 if (sequenced_worker_pool_param != variation_params.end() && | 337 if (sequenced_worker_pool_param != variation_params.end() && |
| 343 sequenced_worker_pool_param->second == "true") { | 338 sequenced_worker_pool_param->second == "true") { |
| 344 sequenced_worker_pool_redirected = true; | 339 base::SequencedWorkerPool::RedirectToTaskSchedulerForProcess(); |
| 345 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); | |
| 346 } | 340 } |
| 347 | |
| 348 return sequenced_worker_pool_redirected; | |
| 349 } | 341 } |
| 350 | 342 |
| 351 // Returns the new local state object, guaranteed non-NULL. | 343 // Returns the new local state object, guaranteed non-NULL. |
| 352 // |local_state_task_runner| must be a shutdown-blocking task runner. | 344 // |local_state_task_runner| must be a shutdown-blocking task runner. |
| 353 PrefService* InitializeLocalState( | 345 PrefService* InitializeLocalState( |
| 354 base::SequencedTaskRunner* local_state_task_runner, | 346 base::SequencedTaskRunner* local_state_task_runner, |
| 355 const base::CommandLine& parsed_command_line) { | 347 const base::CommandLine& parsed_command_line) { |
| 356 TRACE_EVENT0("startup", "ChromeBrowserMainParts::InitializeLocalState") | 348 TRACE_EVENT0("startup", "ChromeBrowserMainParts::InitializeLocalState") |
| 357 | 349 |
| 358 // Load local state. This includes the application locale so we know which | 350 // Load local state. This includes the application locale so we know which |
| (...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1238 // 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 |
| 1239 // does not interfere with the critical initialization order below. Some of | 1231 // does not interfere with the critical initialization order below. Some of |
| 1240 // 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 |
| 1241 // typically either belong before them or in a later startup phase. | 1233 // typically either belong before them or in a later startup phase. |
| 1242 | 1234 |
| 1243 // 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 |
| 1244 // 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 |
| 1245 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. | 1237 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. |
| 1246 SetupFieldTrials(); | 1238 SetupFieldTrials(); |
| 1247 | 1239 |
| 1248 // Initializing TaskScheduler and enabling SequencedWorkerPool needs to be | 1240 // Task Scheduler initialization needs to be here for the following reasons: |
| 1249 // here for the following reasons: | |
| 1250 // * After |SetupFieldTrials()|: Initialization uses variations. | 1241 // * After |SetupFieldTrials()|: Initialization uses variations. |
| 1251 // * Before |SetupMetrics()|: |SetupMetrics()| uses the blocking pool. The | 1242 // * Before |SetupMetrics()|: |SetupMetrics()| uses the blocking pool. The |
| 1252 // Task Scheduler must do any necessary redirection before then. | 1243 // Task Scheduler must do any necessary redirection before then. |
| 1253 // * Near the end of |PreCreateThreads()|: The TaskScheduler needs to be | 1244 // * Near the end of |PreCreateThreads()|: The TaskScheduler needs to be |
| 1254 // created before any other threads are (by contract) but it creates | 1245 // created before any other threads are (by contract) but it creates |
| 1255 // threads itself so instantiating it earlier is also incorrect. | 1246 // threads itself so instantiating it earlier is also incorrect. |
| 1256 // To maintain scoping symmetry, if this line is moved, the corresponding | 1247 // To maintain scoping symmetry, if this line is moved, the corresponding |
| 1257 // shutdown call may also need to be moved. | 1248 // shutdown call may also need to be moved. |
| 1258 const bool sequenced_worker_pool_redirected = MaybeInitializeTaskScheduler(); | 1249 MaybeInitializeTaskScheduler(); |
| 1259 | |
| 1260 // If MaybeInitializeTaskScheduler() hasn't enabled SequencedWorkerPool with | |
| 1261 // redirection to TaskScheduler, enable it without redirection. | |
| 1262 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler | |
| 1263 // redirection experiment concludes https://crbug.com/622400. | |
| 1264 if (!sequenced_worker_pool_redirected) | |
| 1265 base::SequencedWorkerPool::EnableForProcess(); | |
| 1266 | 1250 |
| 1267 SetupMetrics(); | 1251 SetupMetrics(); |
| 1268 | 1252 |
| 1269 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. | 1253 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. |
| 1270 // This also instantiates the IOThread which requests the metrics service and | 1254 // This also instantiates the IOThread which requests the metrics service and |
| 1271 // must be after |SetupMetrics()|. | 1255 // must be after |SetupMetrics()|. |
| 1272 browser_process_->PreCreateThreads(); | 1256 browser_process_->PreCreateThreads(); |
| 1273 | 1257 |
| 1274 return content::RESULT_CODE_NORMAL_EXIT; | 1258 return content::RESULT_CODE_NORMAL_EXIT; |
| 1275 } | 1259 } |
| (...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2136 chromeos::CrosSettings::Shutdown(); | 2120 chromeos::CrosSettings::Shutdown(); |
| 2137 #endif // defined(OS_CHROMEOS) | 2121 #endif // defined(OS_CHROMEOS) |
| 2138 #endif // defined(OS_ANDROID) | 2122 #endif // defined(OS_ANDROID) |
| 2139 } | 2123 } |
| 2140 | 2124 |
| 2141 // Public members: | 2125 // Public members: |
| 2142 | 2126 |
| 2143 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { | 2127 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { |
| 2144 chrome_extra_parts_.push_back(parts); | 2128 chrome_extra_parts_.push_back(parts); |
| 2145 } | 2129 } |
| OLD | NEW |