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

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

Issue 2342373002: Initialize the Browser Task Scheduler Between Field Trials and Metrics (Closed)
Patch Set: CR Feedback Created 4 years, 3 months 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 | « no previous file | no next file » | 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 <algorithm> 10 #include <algorithm>
(...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 #endif // defined(OS_MACOSX) 1317 #endif // defined(OS_MACOSX)
1318 1318
1319 #if defined(OS_CHROMEOS) 1319 #if defined(OS_CHROMEOS)
1320 // Must be done after g_browser_process is constructed, before 1320 // Must be done after g_browser_process is constructed, before
1321 // SetupFieldTrials() and SetupMetrics(). 1321 // SetupFieldTrials() and SetupMetrics().
1322 chromeos::CrosSettings::Initialize(); 1322 chromeos::CrosSettings::Initialize();
1323 #endif // defined(OS_CHROMEOS) 1323 #endif // defined(OS_CHROMEOS)
1324 1324
1325 SetupOriginTrialsCommandLine(); 1325 SetupOriginTrialsCommandLine();
1326 1326
1327 device::GeolocationProvider::SetGeolocationDelegate(
1328 new ChromeGeolocationDelegate());
1329
1330 // IMPORTANT
1331 // Do not add anything below this line until you've verified your new code
1332 // does not interfere with the critical initialization order below. Some of
1333 // the calls below end up implicitly creating threads and as such new calls
1334 // typically either belong before them or in a later startup phase.
1335
1327 // Now the command line has been mutated based on about:flags, we can 1336 // Now the command line has been mutated based on about:flags, we can
gab 2016/09/19 20:05:20 While you're here: s/Now the/Now that the/
robliao 2016/09/19 20:08:34 I'll do this in a next change to make reverts easi
robliao 2016/09/19 20:11:20 https://codereview.chromium.org/2350943002/ tracks
1328 // initialize field trials and setup metrics. The field trials are needed by 1337 // initialize field trials and setup metrics. The field trials are needed by
1329 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. 1338 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads.
1330 SetupFieldTrials(); 1339 SetupFieldTrials();
1331 SetupMetrics();
1332 1340
1333 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. 1341 // Task Scheduler initialization needs to be here for the following reasons:
1334 browser_process_->PreCreateThreads(); 1342 // * After |SetupFieldTrials()|: Initialization uses variations.
1335 1343 // * Before |SetupMetrics()|: |SetupMetrics()| uses the blocking pool. The
1336 device::GeolocationProvider::SetGeolocationDelegate( 1344 // Task Scheduler must do any necessary redirection before then.
1337 new ChromeGeolocationDelegate()); 1345 // * Near the end of |PreCreateThreads()|: The TaskScheduler needs to be
1338 1346 // created before any other threads are (by contract) but it creates
1339 // This needs to be the last thing in PreCreateThreads() because the 1347 // threads itself so instantiating it earlier is also incorrect.
1340 // TaskScheduler needs to be created before any other threads are (by
1341 // contract) but it creates threads itself so instantiating it earlier is also
1342 // incorrect. It also has to be after SetupFieldTrials() to allow it to use
1343 // field trials. Note: it could also be the first thing in CreateThreads() but
1344 // being in chrome/ is convenient for now as the initialization uses
1345 // variations parameters extensively.
1346 //
1347 // To maintain scoping symmetry, if this line is moved, the corresponding 1348 // To maintain scoping symmetry, if this line is moved, the corresponding
1348 // shutdown call may also need to be moved. 1349 // shutdown call may also need to be moved.
1349 MaybeInitializeTaskScheduler(); 1350 MaybeInitializeTaskScheduler();
1350 1351
1352 SetupMetrics();
1353
1354 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this.
1355 // This also instantiates the IOThread which requests the metrics service and
1356 // must be after |SetupMetrics()|.
1357 browser_process_->PreCreateThreads();
1358
1351 return content::RESULT_CODE_NORMAL_EXIT; 1359 return content::RESULT_CODE_NORMAL_EXIT;
1352 } 1360 }
1353 1361
1354 void ChromeBrowserMainParts::MojoShellConnectionStarted( 1362 void ChromeBrowserMainParts::MojoShellConnectionStarted(
1355 content::MojoShellConnection* connection) { 1363 content::MojoShellConnection* connection) {
1356 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) 1364 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1357 chrome_extra_parts_[i]->MojoShellConnectionStarted(connection); 1365 chrome_extra_parts_[i]->MojoShellConnectionStarted(connection);
1358 } 1366 }
1359 1367
1360 void ChromeBrowserMainParts::PreMainMessageLoopRun() { 1368 void ChromeBrowserMainParts::PreMainMessageLoopRun() {
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after
2162 #endif // defined(SYZYASAN) 2170 #endif // defined(SYZYASAN)
2163 #endif // defined(OS_ANDROID) 2171 #endif // defined(OS_ANDROID)
2164 } 2172 }
2165 2173
2166 void ChromeBrowserMainParts::PostDestroyThreads() { 2174 void ChromeBrowserMainParts::PostDestroyThreads() {
2167 #if defined(OS_ANDROID) 2175 #if defined(OS_ANDROID)
2168 // On Android, there is no quit/exit. So the browser's main message loop will 2176 // On Android, there is no quit/exit. So the browser's main message loop will
2169 // not finish. 2177 // not finish.
2170 NOTREACHED(); 2178 NOTREACHED();
2171 #else 2179 #else
2172 // The TaskScheduler was initialized at the very end of PreCreateThreads. To
2173 // maintain scoping symmetry, perform the shutdown here at the beginning of
2174 // PostDestroyThreads.
2175 base::TaskScheduler* task_scheduler = base::TaskScheduler::GetInstance();
2176 if (task_scheduler)
2177 task_scheduler->Shutdown();
2178
2179 int restart_flags = restart_last_session_ 2180 int restart_flags = restart_last_session_
2180 ? browser_shutdown::RESTART_LAST_SESSION 2181 ? browser_shutdown::RESTART_LAST_SESSION
2181 : browser_shutdown::NO_FLAGS; 2182 : browser_shutdown::NO_FLAGS;
2182 2183
2183 #if BUILDFLAG(ENABLE_BACKGROUND) 2184 #if BUILDFLAG(ENABLE_BACKGROUND)
2184 if (restart_flags) { 2185 if (restart_flags) {
2185 restart_flags |= BackgroundModeManager::should_restart_in_background() 2186 restart_flags |= BackgroundModeManager::should_restart_in_background()
2186 ? browser_shutdown::RESTART_IN_BACKGROUND 2187 ? browser_shutdown::RESTART_IN_BACKGROUND
2187 : browser_shutdown::NO_FLAGS; 2188 : browser_shutdown::NO_FLAGS;
2188 } 2189 }
2189 #endif // BUILDFLAG(ENABLE_BACKGROUND) 2190 #endif // BUILDFLAG(ENABLE_BACKGROUND)
2190 2191
2191 browser_process_->PostDestroyThreads(); 2192 browser_process_->PostDestroyThreads();
2192 // browser_shutdown takes care of deleting browser_process, so we need to 2193 // browser_shutdown takes care of deleting browser_process, so we need to
2193 // release it. 2194 // release it.
2194 ignore_result(browser_process_.release()); 2195 ignore_result(browser_process_.release());
2196
2197 // The TaskScheduler was initialized before invoking
2198 // |browser_process_->PreCreateThreads()|. To maintain scoping symmetry,
2199 // perform the shutdown after |browser_process_->PostDestroyThreads()|.
2200 base::TaskScheduler* task_scheduler = base::TaskScheduler::GetInstance();
2201 if (task_scheduler)
2202 task_scheduler->Shutdown();
2203
2195 browser_shutdown::ShutdownPostThreadsStop(restart_flags); 2204 browser_shutdown::ShutdownPostThreadsStop(restart_flags);
2196 master_prefs_.reset(); 2205 master_prefs_.reset();
2197 process_singleton_.reset(); 2206 process_singleton_.reset();
2198 device_event_log::Shutdown(); 2207 device_event_log::Shutdown();
2199 2208
2200 // We need to do this check as late as possible, but due to modularity, this 2209 // We need to do this check as late as possible, but due to modularity, this
2201 // may be the last point in Chrome. This would be more effective if done at 2210 // may be the last point in Chrome. This would be more effective if done at
2202 // a higher level on the stack, so that it is impossible for an early return 2211 // a higher level on the stack, so that it is impossible for an early return
2203 // to bypass this code. Perhaps we need a *final* hook that is called on all 2212 // to bypass this code. Perhaps we need a *final* hook that is called on all
2204 // paths from content/browser/browser_main. 2213 // paths from content/browser/browser_main.
2205 CHECK(metrics::MetricsService::UmaMetricsProperlyShutdown()); 2214 CHECK(metrics::MetricsService::UmaMetricsProperlyShutdown());
2206 2215
2207 #if defined(OS_CHROMEOS) 2216 #if defined(OS_CHROMEOS)
2208 chromeos::CrosSettings::Shutdown(); 2217 chromeos::CrosSettings::Shutdown();
2209 #endif // defined(OS_CHROMEOS) 2218 #endif // defined(OS_CHROMEOS)
2210 #endif // defined(OS_ANDROID) 2219 #endif // defined(OS_ANDROID)
2211 } 2220 }
2212 2221
2213 // Public members: 2222 // Public members:
2214 2223
2215 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { 2224 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) {
2216 chrome_extra_parts_.push_back(parts); 2225 chrome_extra_parts_.push_back(parts);
2217 } 2226 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698