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> | |
11 #include <set> | 10 #include <set> |
12 #include <string> | 11 #include <string> |
13 #include <utility> | 12 #include <utility> |
14 #include <vector> | 13 #include <vector> |
15 | 14 |
16 #include "base/at_exit.h" | 15 #include "base/at_exit.h" |
17 #include "base/base_switches.h" | 16 #include "base/base_switches.h" |
18 #include "base/bind.h" | 17 #include "base/bind.h" |
19 #include "base/command_line.h" | 18 #include "base/command_line.h" |
20 #include "base/debug/crash_logging.h" | 19 #include "base/debug/crash_logging.h" |
21 #include "base/debug/debugger.h" | 20 #include "base/debug/debugger.h" |
22 #include "base/feature_list.h" | 21 #include "base/feature_list.h" |
23 #include "base/files/file_path.h" | 22 #include "base/files/file_path.h" |
24 #include "base/files/file_util.h" | 23 #include "base/files/file_util.h" |
25 #include "base/logging.h" | 24 #include "base/logging.h" |
26 #include "base/memory/ptr_util.h" | 25 #include "base/memory/ptr_util.h" |
27 #include "base/metrics/field_trial.h" | 26 #include "base/metrics/field_trial.h" |
28 #include "base/metrics/histogram_macros.h" | 27 #include "base/metrics/histogram_macros.h" |
29 #include "base/path_service.h" | 28 #include "base/path_service.h" |
30 #include "base/profiler/scoped_tracker.h" | 29 #include "base/profiler/scoped_tracker.h" |
31 #include "base/run_loop.h" | 30 #include "base/run_loop.h" |
32 #include "base/strings/string16.h" | 31 #include "base/strings/string16.h" |
33 #include "base/strings/string_number_conversions.h" | 32 #include "base/strings/string_number_conversions.h" |
34 #include "base/strings/sys_string_conversions.h" | 33 #include "base/strings/sys_string_conversions.h" |
35 #include "base/strings/utf_string_conversions.h" | 34 #include "base/strings/utf_string_conversions.h" |
36 #include "base/sys_info.h" | 35 #include "base/sys_info.h" |
37 #include "base/task_scheduler/switches.h" | |
38 #include "base/task_scheduler/task_scheduler.h" | 36 #include "base/task_scheduler/task_scheduler.h" |
39 #include "base/threading/platform_thread.h" | 37 #include "base/threading/platform_thread.h" |
40 #include "base/threading/sequenced_worker_pool.h" | 38 #include "base/threading/sequenced_worker_pool.h" |
fdoray
2016/11/16 19:23:59
Remove #include "base/threading/sequenced_worker_
robliao
2016/11/16 19:42:55
Done.
| |
41 #include "base/time/default_tick_clock.h" | 39 #include "base/time/default_tick_clock.h" |
42 #include "base/time/time.h" | 40 #include "base/time/time.h" |
43 #include "base/trace_event/trace_event.h" | 41 #include "base/trace_event/trace_event.h" |
44 #include "base/values.h" | 42 #include "base/values.h" |
45 #include "build/build_config.h" | 43 #include "build/build_config.h" |
46 #include "cc/base/switches.h" | 44 #include "cc/base/switches.h" |
47 #include "chrome/browser/about_flags.h" | 45 #include "chrome/browser/about_flags.h" |
48 #include "chrome/browser/after_startup_task_utils.h" | 46 #include "chrome/browser/after_startup_task_utils.h" |
49 #include "chrome/browser/browser_process.h" | 47 #include "chrome/browser/browser_process.h" |
50 #include "chrome/browser/browser_process_impl.h" | 48 #include "chrome/browser/browser_process_impl.h" |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 void AddFirstRunNewTabs(StartupBrowserCreator* browser_creator, | 306 void AddFirstRunNewTabs(StartupBrowserCreator* browser_creator, |
309 const std::vector<GURL>& new_tabs) { | 307 const std::vector<GURL>& new_tabs) { |
310 for (std::vector<GURL>::const_iterator it = new_tabs.begin(); | 308 for (std::vector<GURL>::const_iterator it = new_tabs.begin(); |
311 it != new_tabs.end(); ++it) { | 309 it != new_tabs.end(); ++it) { |
312 if (it->is_valid()) | 310 if (it->is_valid()) |
313 browser_creator->AddFirstRunTab(*it); | 311 browser_creator->AddFirstRunTab(*it); |
314 } | 312 } |
315 } | 313 } |
316 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 314 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
317 | 315 |
318 void MaybeInitializeTaskScheduler() { | |
319 static constexpr char kFieldTrialName[] = "BrowserScheduler"; | |
320 std::map<std::string, std::string> variation_params; | |
321 if (!variations::GetVariationParams(kFieldTrialName, &variation_params)) { | |
322 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
323 switches::kEnableBrowserTaskScheduler)) | |
324 << "The Browser Task Scheduler remains disabled with " | |
325 << switches::kEnableBrowserTaskScheduler | |
326 << " because there is no available variation param for this build or " | |
327 " the task scheduler is disabled in chrome://flags."; | |
328 return; | |
329 } | |
330 | |
331 if (!task_scheduler_util::InitializeDefaultTaskScheduler(variation_params)) | |
332 return; | |
333 | |
334 // TODO(gab): Remove this when http://crbug.com/622400 concludes. | |
335 const auto sequenced_worker_pool_param = | |
336 variation_params.find("RedirectSequencedWorkerPools"); | |
337 if (sequenced_worker_pool_param != variation_params.end() && | |
338 sequenced_worker_pool_param->second == "true") { | |
339 base::SequencedWorkerPool::RedirectToTaskSchedulerForProcess(); | |
340 } | |
341 } | |
342 | |
343 // Returns the new local state object, guaranteed non-NULL. | 316 // Returns the new local state object, guaranteed non-NULL. |
344 // |local_state_task_runner| must be a shutdown-blocking task runner. | 317 // |local_state_task_runner| must be a shutdown-blocking task runner. |
345 PrefService* InitializeLocalState( | 318 PrefService* InitializeLocalState( |
346 base::SequencedTaskRunner* local_state_task_runner, | 319 base::SequencedTaskRunner* local_state_task_runner, |
347 const base::CommandLine& parsed_command_line) { | 320 const base::CommandLine& parsed_command_line) { |
348 TRACE_EVENT0("startup", "ChromeBrowserMainParts::InitializeLocalState") | 321 TRACE_EVENT0("startup", "ChromeBrowserMainParts::InitializeLocalState") |
349 | 322 |
350 // Load local state. This includes the application locale so we know which | 323 // Load local state. This includes the application locale so we know which |
351 // locale dll to load. This also causes local state prefs to be registered. | 324 // locale dll to load. This also causes local state prefs to be registered. |
352 PrefService* local_state = g_browser_process->local_state(); | 325 PrefService* local_state = g_browser_process->local_state(); |
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1239 | 1212 |
1240 // Task Scheduler initialization needs to be here for the following reasons: | 1213 // Task Scheduler initialization needs to be here for the following reasons: |
1241 // * After |SetupFieldTrials()|: Initialization uses variations. | 1214 // * After |SetupFieldTrials()|: Initialization uses variations. |
1242 // * Before |SetupMetrics()|: |SetupMetrics()| uses the blocking pool. The | 1215 // * Before |SetupMetrics()|: |SetupMetrics()| uses the blocking pool. The |
1243 // Task Scheduler must do any necessary redirection before then. | 1216 // Task Scheduler must do any necessary redirection before then. |
1244 // * Near the end of |PreCreateThreads()|: The TaskScheduler needs to be | 1217 // * Near the end of |PreCreateThreads()|: The TaskScheduler needs to be |
1245 // created before any other threads are (by contract) but it creates | 1218 // created before any other threads are (by contract) but it creates |
1246 // threads itself so instantiating it earlier is also incorrect. | 1219 // threads itself so instantiating it earlier is also incorrect. |
1247 // To maintain scoping symmetry, if this line is moved, the corresponding | 1220 // To maintain scoping symmetry, if this line is moved, the corresponding |
1248 // shutdown call may also need to be moved. | 1221 // shutdown call may also need to be moved. |
1249 MaybeInitializeTaskScheduler(); | 1222 task_scheduler_util::InitializeDefaultBrowserTaskScheduler(); |
fdoray
2016/11/16 19:23:59
Remove "Default"?
robliao
2016/11/16 19:42:55
Technically it is the default one (we provide it),
| |
1250 | 1223 |
1251 SetupMetrics(); | 1224 SetupMetrics(); |
1252 | 1225 |
1253 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. | 1226 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. |
1254 // This also instantiates the IOThread which requests the metrics service and | 1227 // This also instantiates the IOThread which requests the metrics service and |
1255 // must be after |SetupMetrics()|. | 1228 // must be after |SetupMetrics()|. |
1256 browser_process_->PreCreateThreads(); | 1229 browser_process_->PreCreateThreads(); |
1257 | 1230 |
1258 return content::RESULT_CODE_NORMAL_EXIT; | 1231 return content::RESULT_CODE_NORMAL_EXIT; |
1259 } | 1232 } |
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2120 chromeos::CrosSettings::Shutdown(); | 2093 chromeos::CrosSettings::Shutdown(); |
2121 #endif // defined(OS_CHROMEOS) | 2094 #endif // defined(OS_CHROMEOS) |
2122 #endif // defined(OS_ANDROID) | 2095 #endif // defined(OS_ANDROID) |
2123 } | 2096 } |
2124 | 2097 |
2125 // Public members: | 2098 // Public members: |
2126 | 2099 |
2127 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { | 2100 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { |
2128 chrome_extra_parts_.push_back(parts); | 2101 chrome_extra_parts_.push_back(parts); |
2129 } | 2102 } |
OLD | NEW |