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

Side by Side Diff: chrome/browser/chrome_browser_main.cc

Issue 2539263003: Move Task Scheduler Initialization From chrome/browser to Content (Closed)
Patch Set: Rebase to bf8e2f1 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
« no previous file with comments | « chrome/browser/BUILD.gn ('k') | chrome/browser/chrome_content_browser_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <set> 10 #include <set>
(...skipping 15 matching lines...) Expand all
26 #include "base/metrics/field_trial.h" 26 #include "base/metrics/field_trial.h"
27 #include "base/metrics/histogram_macros.h" 27 #include "base/metrics/histogram_macros.h"
28 #include "base/path_service.h" 28 #include "base/path_service.h"
29 #include "base/profiler/scoped_tracker.h" 29 #include "base/profiler/scoped_tracker.h"
30 #include "base/run_loop.h" 30 #include "base/run_loop.h"
31 #include "base/strings/string16.h" 31 #include "base/strings/string16.h"
32 #include "base/strings/string_number_conversions.h" 32 #include "base/strings/string_number_conversions.h"
33 #include "base/strings/sys_string_conversions.h" 33 #include "base/strings/sys_string_conversions.h"
34 #include "base/strings/utf_string_conversions.h" 34 #include "base/strings/utf_string_conversions.h"
35 #include "base/sys_info.h" 35 #include "base/sys_info.h"
36 #include "base/task_scheduler/task_scheduler.h"
37 #include "base/threading/platform_thread.h" 36 #include "base/threading/platform_thread.h"
38 #include "base/time/default_tick_clock.h" 37 #include "base/time/default_tick_clock.h"
39 #include "base/time/time.h" 38 #include "base/time/time.h"
40 #include "base/trace_event/trace_event.h" 39 #include "base/trace_event/trace_event.h"
41 #include "base/values.h" 40 #include "base/values.h"
42 #include "build/build_config.h" 41 #include "build/build_config.h"
43 #include "cc/base/switches.h" 42 #include "cc/base/switches.h"
44 #include "chrome/browser/about_flags.h" 43 #include "chrome/browser/about_flags.h"
45 #include "chrome/browser/after_startup_task_utils.h" 44 #include "chrome/browser/after_startup_task_utils.h"
46 #include "chrome/browser/browser_process.h" 45 #include "chrome/browser/browser_process.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 #include "components/metrics_services_manager/metrics_services_manager.h" 126 #include "components/metrics_services_manager/metrics_services_manager.h"
128 #include "components/nacl/browser/nacl_browser.h" 127 #include "components/nacl/browser/nacl_browser.h"
129 #include "components/prefs/json_pref_store.h" 128 #include "components/prefs/json_pref_store.h"
130 #include "components/prefs/pref_registry_simple.h" 129 #include "components/prefs/pref_registry_simple.h"
131 #include "components/prefs/pref_service.h" 130 #include "components/prefs/pref_service.h"
132 #include "components/prefs/pref_value_store.h" 131 #include "components/prefs/pref_value_store.h"
133 #include "components/prefs/scoped_user_pref_update.h" 132 #include "components/prefs/scoped_user_pref_update.h"
134 #include "components/rappor/rappor_service_impl.h" 133 #include "components/rappor/rappor_service_impl.h"
135 #include "components/signin/core/common/profile_management_switches.h" 134 #include "components/signin/core/common/profile_management_switches.h"
136 #include "components/startup_metric_utils/browser/startup_metric_utils.h" 135 #include "components/startup_metric_utils/browser/startup_metric_utils.h"
137 #include "components/task_scheduler_util/initialization_util.h"
138 #include "components/tracing/common/tracing_switches.h" 136 #include "components/tracing/common/tracing_switches.h"
139 #include "components/translate/core/browser/translate_download_manager.h" 137 #include "components/translate/core/browser/translate_download_manager.h"
140 #include "components/variations/field_trial_config/field_trial_util.h" 138 #include "components/variations/field_trial_config/field_trial_util.h"
141 #include "components/variations/pref_names.h" 139 #include "components/variations/pref_names.h"
142 #include "components/variations/service/variations_service.h" 140 #include "components/variations/service/variations_service.h"
143 #include "components/variations/variations_associated_data.h" 141 #include "components/variations/variations_associated_data.h"
144 #include "components/variations/variations_http_header_provider.h" 142 #include "components/variations/variations_http_header_provider.h"
145 #include "components/variations/variations_switches.h" 143 #include "components/variations/variations_switches.h"
146 #include "components/version_info/version_info.h" 144 #include "components/version_info/version_info.h"
147 #include "content/public/browser/browser_thread.h" 145 #include "content/public/browser/browser_thread.h"
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 // {DEVICE}_LOG prior to here will only be logged with VLOG. Some 920 // {DEVICE}_LOG prior to here will only be logged with VLOG. Some
923 // platforms (e.g. chromeos) may have already initialized this. 921 // platforms (e.g. chromeos) may have already initialized this.
924 if (!device_event_log::IsInitialized()) 922 if (!device_event_log::IsInitialized())
925 device_event_log::Initialize(0 /* default max entries */); 923 device_event_log::Initialize(0 /* default max entries */);
926 924
927 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) 925 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
928 chrome_extra_parts_[i]->PostMainMessageLoopStart(); 926 chrome_extra_parts_[i]->PostMainMessageLoopStart();
929 } 927 }
930 928
931 int ChromeBrowserMainParts::PreCreateThreads() { 929 int ChromeBrowserMainParts::PreCreateThreads() {
930 // IMPORTANT
931 // Calls in this function should not post tasks or create threads as
932 // components used to handle those tasks are not yet available. This work
933 // should be deferred to PreMainMessageLoopRunImpl.
934
932 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreCreateThreads"); 935 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreCreateThreads");
933 result_code_ = PreCreateThreadsImpl(); 936 result_code_ = PreCreateThreadsImpl();
934 937
935 if (result_code_ == content::RESULT_CODE_NORMAL_EXIT) { 938 if (result_code_ == content::RESULT_CODE_NORMAL_EXIT) {
936 #if !defined(OS_ANDROID) 939 #if !defined(OS_ANDROID)
937 // These members must be initialized before exiting this function normally. 940 // These members must be initialized before exiting this function normally.
938 DCHECK(master_prefs_.get()); 941 DCHECK(master_prefs_.get());
939 DCHECK(browser_creator_.get()); 942 DCHECK(browser_creator_.get());
940 #endif // !defined(OS_ANDROID) 943 #endif // !defined(OS_ANDROID)
941 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) 944 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 // Must be done after g_browser_process is constructed, before 1195 // Must be done after g_browser_process is constructed, before
1193 // SetupFieldTrials() and SetupMetrics(). 1196 // SetupFieldTrials() and SetupMetrics().
1194 chromeos::CrosSettings::Initialize(); 1197 chromeos::CrosSettings::Initialize();
1195 #endif // defined(OS_CHROMEOS) 1198 #endif // defined(OS_CHROMEOS)
1196 1199
1197 SetupOriginTrialsCommandLine(); 1200 SetupOriginTrialsCommandLine();
1198 1201
1199 device::GeolocationProvider::SetGeolocationDelegate( 1202 device::GeolocationProvider::SetGeolocationDelegate(
1200 new ChromeGeolocationDelegate()); 1203 new ChromeGeolocationDelegate());
1201 1204
1202 // IMPORTANT
1203 // Do not add anything below this line until you've verified your new code
1204 // does not interfere with the critical initialization order below. Some of
1205 // the calls below end up implicitly creating threads and as such new calls
1206 // typically either belong before them or in a later startup phase.
1207
1208 // Now that the command line has been mutated based on about:flags, we can 1205 // Now that the command line has been mutated based on about:flags, we can
1209 // initialize field trials and setup metrics. The field trials are needed by 1206 // initialize field trials. The field trials are needed by IOThread's
1210 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. 1207 // initialization which happens in BrowserProcess:PreCreateThreads. Metrics
1208 // initialization is handled in PreMainMessageLoopRunImpl since it posts
1209 // tasks.
1211 SetupFieldTrials(); 1210 SetupFieldTrials();
1212 1211
1213 // Task Scheduler initialization needs to be here for the following reasons:
1214 // * After |SetupFieldTrials()|: Initialization uses variations.
1215 // * Near the end of |PreCreateThreads()|: The TaskScheduler needs to be
1216 // created before any other threads are (by contract) but it creates
1217 // threads itself so instantiating it earlier is also incorrect.
1218 // To maintain scoping symmetry, if this line is moved, the corresponding
1219 // shutdown call may also need to be moved.
1220 task_scheduler_util::InitializeDefaultBrowserTaskScheduler();
1221
1222 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. 1212 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this.
1223 // This also instantiates the IOThread which requests the metrics service and 1213 // This also instantiates the IOThread which requests the metrics service and
1224 // must be after |SetupMetrics()|. 1214 // must be after |SetupMetrics()|.
1225 browser_process_->PreCreateThreads(); 1215 browser_process_->PreCreateThreads();
1226 1216
1227 return content::RESULT_CODE_NORMAL_EXIT; 1217 return content::RESULT_CODE_NORMAL_EXIT;
1228 } 1218 }
1229 1219
1230 void ChromeBrowserMainParts::ServiceManagerConnectionStarted( 1220 void ChromeBrowserMainParts::ServiceManagerConnectionStarted(
1231 content::ServiceManagerConnection* connection) { 1221 content::ServiceManagerConnection* connection) {
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
2065 ? browser_shutdown::RESTART_IN_BACKGROUND 2055 ? browser_shutdown::RESTART_IN_BACKGROUND
2066 : browser_shutdown::NO_FLAGS; 2056 : browser_shutdown::NO_FLAGS;
2067 } 2057 }
2068 #endif // BUILDFLAG(ENABLE_BACKGROUND) 2058 #endif // BUILDFLAG(ENABLE_BACKGROUND)
2069 2059
2070 browser_process_->PostDestroyThreads(); 2060 browser_process_->PostDestroyThreads();
2071 // browser_shutdown takes care of deleting browser_process, so we need to 2061 // browser_shutdown takes care of deleting browser_process, so we need to
2072 // release it. 2062 // release it.
2073 ignore_result(browser_process_.release()); 2063 ignore_result(browser_process_.release());
2074 2064
2075 // The TaskScheduler was initialized before invoking
2076 // |browser_process_->PreCreateThreads()|. To maintain scoping symmetry,
2077 // perform the shutdown after |browser_process_->PostDestroyThreads()|.
2078 base::TaskScheduler* task_scheduler = base::TaskScheduler::GetInstance();
2079 if (task_scheduler)
2080 task_scheduler->Shutdown();
2081
2082 browser_shutdown::ShutdownPostThreadsStop(restart_flags); 2065 browser_shutdown::ShutdownPostThreadsStop(restart_flags);
2083 master_prefs_.reset(); 2066 master_prefs_.reset();
2084 process_singleton_.reset(); 2067 process_singleton_.reset();
2085 device_event_log::Shutdown(); 2068 device_event_log::Shutdown();
2086 2069
2087 // We need to do this check as late as possible, but due to modularity, this 2070 // We need to do this check as late as possible, but due to modularity, this
2088 // may be the last point in Chrome. This would be more effective if done at 2071 // may be the last point in Chrome. This would be more effective if done at
2089 // a higher level on the stack, so that it is impossible for an early return 2072 // a higher level on the stack, so that it is impossible for an early return
2090 // to bypass this code. Perhaps we need a *final* hook that is called on all 2073 // to bypass this code. Perhaps we need a *final* hook that is called on all
2091 // paths from content/browser/browser_main. 2074 // paths from content/browser/browser_main.
2092 CHECK(metrics::MetricsService::UmaMetricsProperlyShutdown()); 2075 CHECK(metrics::MetricsService::UmaMetricsProperlyShutdown());
2093 2076
2094 #if defined(OS_CHROMEOS) 2077 #if defined(OS_CHROMEOS)
2095 chromeos::CrosSettings::Shutdown(); 2078 chromeos::CrosSettings::Shutdown();
2096 #endif // defined(OS_CHROMEOS) 2079 #endif // defined(OS_CHROMEOS)
2097 #endif // defined(OS_ANDROID) 2080 #endif // defined(OS_ANDROID)
2098 } 2081 }
2099 2082
2100 // Public members: 2083 // Public members:
2101 2084
2102 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { 2085 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) {
2103 chrome_extra_parts_.push_back(parts); 2086 chrome_extra_parts_.push_back(parts);
2104 } 2087 }
OLDNEW
« no previous file with comments | « chrome/browser/BUILD.gn ('k') | chrome/browser/chrome_content_browser_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698