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 <algorithm> | 10 #include <algorithm> |
(...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 // Now the command line has been mutated based on about:flags, we can | 1327 // Now the command line has been mutated based on about:flags, we can |
1328 // initialize field trials and setup metrics. The field trials are needed by | 1328 // initialize field trials and setup metrics. The field trials are needed by |
1329 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. | 1329 // IOThread's initialization which happens in BrowserProcess:PreCreateThreads. |
1330 SetupFieldTrials(); | 1330 SetupFieldTrials(); |
1331 | |
1332 // Task Scheduler initialization needs to be here for the following reasons: | |
1333 // * After |SetupFieldTrials()|: Initialization uses variations. | |
1334 // * Before |SetupMetrics()|: |SetupMetrics()| uses the blocking pool. The | |
1335 // Task Scheduler must do any necessary redirection before then. | |
1336 // * Near the end of |PreCreateThreads()|: The TaskScheduler needs to be | |
1337 // created before any other threads are (by contract) but it creates | |
1338 // threads itself so instantiating it earlier is also incorrect. | |
1339 // To maintain scoping symmetry, if this line is moved, the corresponding | |
1340 // shutdown call may also need to be moved. | |
1341 MaybeInitializeTaskScheduler(); | |
1342 | |
1331 SetupMetrics(); | 1343 SetupMetrics(); |
1332 | 1344 |
1333 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. | 1345 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. |
gab
2016/09/19 17:51:32
Add:
// This instantiates the IOThread and must b
robliao
2016/09/19 19:17:30
Done. What do you mean mean about the "explain why
| |
1334 browser_process_->PreCreateThreads(); | 1346 browser_process_->PreCreateThreads(); |
1335 | 1347 |
1336 device::GeolocationProvider::SetGeolocationDelegate( | 1348 device::GeolocationProvider::SetGeolocationDelegate( |
gab
2016/09/19 17:51:32
Can we move this before SetupFieldTrials() and the
robliao
2016/09/19 19:17:30
Looks safe to move (default constructor, global se
| |
1337 new ChromeGeolocationDelegate()); | 1349 new ChromeGeolocationDelegate()); |
1338 | 1350 |
1339 // This needs to be the last thing in PreCreateThreads() because the | |
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 // shutdown call may also need to be moved. | |
1349 MaybeInitializeTaskScheduler(); | |
1350 | |
1351 return content::RESULT_CODE_NORMAL_EXIT; | 1351 return content::RESULT_CODE_NORMAL_EXIT; |
1352 } | 1352 } |
1353 | 1353 |
1354 void ChromeBrowserMainParts::MojoShellConnectionStarted( | 1354 void ChromeBrowserMainParts::MojoShellConnectionStarted( |
1355 content::MojoShellConnection* connection) { | 1355 content::MojoShellConnection* connection) { |
1356 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) | 1356 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
1357 chrome_extra_parts_[i]->MojoShellConnectionStarted(connection); | 1357 chrome_extra_parts_[i]->MojoShellConnectionStarted(connection); |
1358 } | 1358 } |
1359 | 1359 |
1360 void ChromeBrowserMainParts::PreMainMessageLoopRun() { | 1360 void ChromeBrowserMainParts::PreMainMessageLoopRun() { |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2162 #endif // defined(SYZYASAN) | 2162 #endif // defined(SYZYASAN) |
2163 #endif // defined(OS_ANDROID) | 2163 #endif // defined(OS_ANDROID) |
2164 } | 2164 } |
2165 | 2165 |
2166 void ChromeBrowserMainParts::PostDestroyThreads() { | 2166 void ChromeBrowserMainParts::PostDestroyThreads() { |
2167 #if defined(OS_ANDROID) | 2167 #if defined(OS_ANDROID) |
2168 // On Android, there is no quit/exit. So the browser's main message loop will | 2168 // On Android, there is no quit/exit. So the browser's main message loop will |
2169 // not finish. | 2169 // not finish. |
2170 NOTREACHED(); | 2170 NOTREACHED(); |
2171 #else | 2171 #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_ | 2172 int restart_flags = restart_last_session_ |
2180 ? browser_shutdown::RESTART_LAST_SESSION | 2173 ? browser_shutdown::RESTART_LAST_SESSION |
2181 : browser_shutdown::NO_FLAGS; | 2174 : browser_shutdown::NO_FLAGS; |
2182 | 2175 |
2183 #if BUILDFLAG(ENABLE_BACKGROUND) | 2176 #if BUILDFLAG(ENABLE_BACKGROUND) |
2184 if (restart_flags) { | 2177 if (restart_flags) { |
2185 restart_flags |= BackgroundModeManager::should_restart_in_background() | 2178 restart_flags |= BackgroundModeManager::should_restart_in_background() |
2186 ? browser_shutdown::RESTART_IN_BACKGROUND | 2179 ? browser_shutdown::RESTART_IN_BACKGROUND |
2187 : browser_shutdown::NO_FLAGS; | 2180 : browser_shutdown::NO_FLAGS; |
2188 } | 2181 } |
2189 #endif // BUILDFLAG(ENABLE_BACKGROUND) | 2182 #endif // BUILDFLAG(ENABLE_BACKGROUND) |
2190 | 2183 |
2191 browser_process_->PostDestroyThreads(); | 2184 browser_process_->PostDestroyThreads(); |
2192 // browser_shutdown takes care of deleting browser_process, so we need to | 2185 // browser_shutdown takes care of deleting browser_process, so we need to |
2193 // release it. | 2186 // release it. |
2194 ignore_result(browser_process_.release()); | 2187 ignore_result(browser_process_.release()); |
2188 | |
2189 // The TaskScheduler was initialized before the PreCreateThreads() on | |
2190 // |browser_process_|. To maintain scoping symmetry, perform the shutdown | |
gab
2016/09/19 17:51:32
s/before the PreCreateThreads on |browser_process_
robliao
2016/09/19 19:17:30
Done.
| |
2191 // after browser process PostDestroyThreads. | |
gab
2016/09/19 17:51:32
Similarly: "after invoking |browser_process_->Post
robliao
2016/09/19 19:17:30
Done.
| |
2192 base::TaskScheduler* task_scheduler = base::TaskScheduler::GetInstance(); | |
2193 if (task_scheduler) | |
2194 task_scheduler->Shutdown(); | |
2195 | |
2195 browser_shutdown::ShutdownPostThreadsStop(restart_flags); | 2196 browser_shutdown::ShutdownPostThreadsStop(restart_flags); |
2196 master_prefs_.reset(); | 2197 master_prefs_.reset(); |
2197 process_singleton_.reset(); | 2198 process_singleton_.reset(); |
2198 device_event_log::Shutdown(); | 2199 device_event_log::Shutdown(); |
2199 | 2200 |
2200 // We need to do this check as late as possible, but due to modularity, this | 2201 // 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 | 2202 // 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 | 2203 // 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 | 2204 // to bypass this code. Perhaps we need a *final* hook that is called on all |
2204 // paths from content/browser/browser_main. | 2205 // paths from content/browser/browser_main. |
2205 CHECK(metrics::MetricsService::UmaMetricsProperlyShutdown()); | 2206 CHECK(metrics::MetricsService::UmaMetricsProperlyShutdown()); |
2206 | 2207 |
2207 #if defined(OS_CHROMEOS) | 2208 #if defined(OS_CHROMEOS) |
2208 chromeos::CrosSettings::Shutdown(); | 2209 chromeos::CrosSettings::Shutdown(); |
2209 #endif // defined(OS_CHROMEOS) | 2210 #endif // defined(OS_CHROMEOS) |
2210 #endif // defined(OS_ANDROID) | 2211 #endif // defined(OS_ANDROID) |
2211 } | 2212 } |
2212 | 2213 |
2213 // Public members: | 2214 // Public members: |
2214 | 2215 |
2215 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { | 2216 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { |
2216 chrome_extra_parts_.push_back(parts); | 2217 chrome_extra_parts_.push_back(parts); |
2217 } | 2218 } |
OLD | NEW |