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 <set> | 10 #include <set> |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 #include "components/metrics_services_manager/metrics_services_manager.h" | 127 #include "components/metrics_services_manager/metrics_services_manager.h" |
| 129 #include "components/nacl/browser/nacl_browser.h" | 128 #include "components/nacl/browser/nacl_browser.h" |
| 130 #include "components/prefs/json_pref_store.h" | 129 #include "components/prefs/json_pref_store.h" |
| 131 #include "components/prefs/pref_registry_simple.h" | 130 #include "components/prefs/pref_registry_simple.h" |
| 132 #include "components/prefs/pref_service.h" | 131 #include "components/prefs/pref_service.h" |
| 133 #include "components/prefs/pref_value_store.h" | 132 #include "components/prefs/pref_value_store.h" |
| 134 #include "components/prefs/scoped_user_pref_update.h" | 133 #include "components/prefs/scoped_user_pref_update.h" |
| 135 #include "components/rappor/rappor_service.h" | 134 #include "components/rappor/rappor_service.h" |
| 136 #include "components/signin/core/common/profile_management_switches.h" | 135 #include "components/signin/core/common/profile_management_switches.h" |
| 137 #include "components/startup_metric_utils/browser/startup_metric_utils.h" | 136 #include "components/startup_metric_utils/browser/startup_metric_utils.h" |
| 138 #include "components/task_scheduler_util/initialization_util.h" | |
| 139 #include "components/tracing/common/tracing_switches.h" | 137 #include "components/tracing/common/tracing_switches.h" |
| 140 #include "components/translate/core/browser/translate_download_manager.h" | 138 #include "components/translate/core/browser/translate_download_manager.h" |
| 141 #include "components/variations/field_trial_config/field_trial_util.h" | 139 #include "components/variations/field_trial_config/field_trial_util.h" |
| 142 #include "components/variations/pref_names.h" | 140 #include "components/variations/pref_names.h" |
| 143 #include "components/variations/service/variations_service.h" | 141 #include "components/variations/service/variations_service.h" |
| 144 #include "components/variations/variations_associated_data.h" | 142 #include "components/variations/variations_associated_data.h" |
| 145 #include "components/variations/variations_http_header_provider.h" | 143 #include "components/variations/variations_http_header_provider.h" |
| 146 #include "components/variations/variations_switches.h" | 144 #include "components/variations/variations_switches.h" |
| 147 #include "components/version_info/version_info.h" | 145 #include "components/version_info/version_info.h" |
| 148 #include "content/public/browser/browser_thread.h" | 146 #include "content/public/browser/browser_thread.h" |
| (...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1192 // Must be done after g_browser_process is constructed, before | 1190 // Must be done after g_browser_process is constructed, before |
| 1193 // SetupFieldTrials() and SetupMetrics(). | 1191 // SetupFieldTrials() and SetupMetrics(). |
| 1194 chromeos::CrosSettings::Initialize(); | 1192 chromeos::CrosSettings::Initialize(); |
| 1195 #endif // defined(OS_CHROMEOS) | 1193 #endif // defined(OS_CHROMEOS) |
| 1196 | 1194 |
| 1197 SetupOriginTrialsCommandLine(); | 1195 SetupOriginTrialsCommandLine(); |
| 1198 | 1196 |
| 1199 device::GeolocationProvider::SetGeolocationDelegate( | 1197 device::GeolocationProvider::SetGeolocationDelegate( |
| 1200 new ChromeGeolocationDelegate()); | 1198 new ChromeGeolocationDelegate()); |
| 1201 | 1199 |
| 1202 // IMPORTANT | 1200 // IMPORTANT |
|
gab
2016/11/30 22:36:58
Does this comment apply anymore? i.e. it's relevan
robliao
2016/12/06 01:31:30
Moved to top and reworded.
| |
| 1203 // Do not add anything below this line until you've verified your new code | 1201 // 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 | 1202 // does not interfere with the critical initialization order below. Calls |
| 1205 // the calls below end up implicitly creating threads and as such new calls | 1203 // after this line should not post tasks or create threads. This work should |
| 1206 // typically either belong before them or in a later startup phase. | 1204 // be deferred to PreMainMessageLoopRunImpl. |
| 1207 | 1205 |
| 1208 // Now that the command line has been mutated based on about:flags, we can | 1206 // 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 | 1207 // initialize field trials and setup metrics. The field trials are needed by |
|
gab
2016/11/30 22:36:58
No longer sets up metrics
robliao
2016/12/06 01:31:30
Reworded. The only implication here is that we can
| |
| 1210 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. | 1208 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. |
| 1211 SetupFieldTrials(); | 1209 SetupFieldTrials(); |
| 1212 | 1210 |
| 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. | 1211 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. |
| 1223 // This also instantiates the IOThread which requests the metrics service and | 1212 // This also instantiates the IOThread which requests the metrics service and |
| 1224 // must be after |SetupMetrics()|. | 1213 // must be after |SetupMetrics()|. |
| 1225 browser_process_->PreCreateThreads(); | 1214 browser_process_->PreCreateThreads(); |
| 1226 | 1215 |
| 1227 return content::RESULT_CODE_NORMAL_EXIT; | 1216 return content::RESULT_CODE_NORMAL_EXIT; |
| 1228 } | 1217 } |
| 1229 | 1218 |
| 1230 void ChromeBrowserMainParts::ServiceManagerConnectionStarted( | 1219 void ChromeBrowserMainParts::ServiceManagerConnectionStarted( |
| 1231 content::ServiceManagerConnection* connection) { | 1220 content::ServiceManagerConnection* connection) { |
| (...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2063 ? browser_shutdown::RESTART_IN_BACKGROUND | 2052 ? browser_shutdown::RESTART_IN_BACKGROUND |
| 2064 : browser_shutdown::NO_FLAGS; | 2053 : browser_shutdown::NO_FLAGS; |
| 2065 } | 2054 } |
| 2066 #endif // BUILDFLAG(ENABLE_BACKGROUND) | 2055 #endif // BUILDFLAG(ENABLE_BACKGROUND) |
| 2067 | 2056 |
| 2068 browser_process_->PostDestroyThreads(); | 2057 browser_process_->PostDestroyThreads(); |
| 2069 // browser_shutdown takes care of deleting browser_process, so we need to | 2058 // browser_shutdown takes care of deleting browser_process, so we need to |
| 2070 // release it. | 2059 // release it. |
| 2071 ignore_result(browser_process_.release()); | 2060 ignore_result(browser_process_.release()); |
| 2072 | 2061 |
| 2073 // The TaskScheduler was initialized before invoking | |
| 2074 // |browser_process_->PreCreateThreads()|. To maintain scoping symmetry, | |
| 2075 // perform the shutdown after |browser_process_->PostDestroyThreads()|. | |
| 2076 base::TaskScheduler* task_scheduler = base::TaskScheduler::GetInstance(); | |
| 2077 if (task_scheduler) | |
| 2078 task_scheduler->Shutdown(); | |
| 2079 | |
| 2080 browser_shutdown::ShutdownPostThreadsStop(restart_flags); | 2062 browser_shutdown::ShutdownPostThreadsStop(restart_flags); |
| 2081 master_prefs_.reset(); | 2063 master_prefs_.reset(); |
| 2082 process_singleton_.reset(); | 2064 process_singleton_.reset(); |
| 2083 device_event_log::Shutdown(); | 2065 device_event_log::Shutdown(); |
| 2084 | 2066 |
| 2085 // We need to do this check as late as possible, but due to modularity, this | 2067 // We need to do this check as late as possible, but due to modularity, this |
| 2086 // may be the last point in Chrome. This would be more effective if done at | 2068 // may be the last point in Chrome. This would be more effective if done at |
| 2087 // a higher level on the stack, so that it is impossible for an early return | 2069 // a higher level on the stack, so that it is impossible for an early return |
| 2088 // to bypass this code. Perhaps we need a *final* hook that is called on all | 2070 // to bypass this code. Perhaps we need a *final* hook that is called on all |
| 2089 // paths from content/browser/browser_main. | 2071 // paths from content/browser/browser_main. |
| 2090 CHECK(metrics::MetricsService::UmaMetricsProperlyShutdown()); | 2072 CHECK(metrics::MetricsService::UmaMetricsProperlyShutdown()); |
| 2091 | 2073 |
| 2092 #if defined(OS_CHROMEOS) | 2074 #if defined(OS_CHROMEOS) |
| 2093 chromeos::CrosSettings::Shutdown(); | 2075 chromeos::CrosSettings::Shutdown(); |
| 2094 #endif // defined(OS_CHROMEOS) | 2076 #endif // defined(OS_CHROMEOS) |
| 2095 #endif // defined(OS_ANDROID) | 2077 #endif // defined(OS_ANDROID) |
| 2096 } | 2078 } |
| 2097 | 2079 |
| 2098 // Public members: | 2080 // Public members: |
| 2099 | 2081 |
| 2100 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { | 2082 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { |
| 2101 chrome_extra_parts_.push_back(parts); | 2083 chrome_extra_parts_.push_back(parts); |
| 2102 } | 2084 } |
| OLD | NEW |