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 // Note: It could also be the first thing in CreateThreads() but being in | |
fdoray
2016/09/16 18:20:28
This Note is not so true if SetupMetrics() is in P
robliao
2016/09/16 21:35:40
Indeed. Removed.
| |
1340 // chrome/ is convenient for now as the initialization uses variations | |
1341 // parameters extensively. | |
1342 // | |
1343 // To maintain scoping symmetry, if this line is moved, the corresponding | |
1344 // shutdown call may also need to be moved. | |
1345 MaybeInitializeTaskScheduler(); | |
1346 | |
1331 SetupMetrics(); | 1347 SetupMetrics(); |
1332 | 1348 |
1333 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. | 1349 // ChromeOS needs ResourceBundle::InitSharedInstance to be called before this. |
1334 browser_process_->PreCreateThreads(); | 1350 browser_process_->PreCreateThreads(); |
1335 | 1351 |
1336 device::GeolocationProvider::SetGeolocationDelegate( | 1352 device::GeolocationProvider::SetGeolocationDelegate( |
1337 new ChromeGeolocationDelegate()); | 1353 new ChromeGeolocationDelegate()); |
1338 | 1354 |
1339 // This needs to be the last thing in PreCreateThreads() because the | |
gab
2016/09/16 19:57:04
I think we do want this to remain the last thing.
robliao
2016/09/16 21:35:40
This will have to stay here since browser_process_
gab
2016/09/19 17:51:32
Agreed I'm also not thrilled about buffering eithe
| |
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; | 1355 return content::RESULT_CODE_NORMAL_EXIT; |
1352 } | 1356 } |
1353 | 1357 |
1354 void ChromeBrowserMainParts::MojoShellConnectionStarted( | 1358 void ChromeBrowserMainParts::MojoShellConnectionStarted( |
1355 content::MojoShellConnection* connection) { | 1359 content::MojoShellConnection* connection) { |
1356 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) | 1360 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) |
1357 chrome_extra_parts_[i]->MojoShellConnectionStarted(connection); | 1361 chrome_extra_parts_[i]->MojoShellConnectionStarted(connection); |
1358 } | 1362 } |
1359 | 1363 |
1360 void ChromeBrowserMainParts::PreMainMessageLoopRun() { | 1364 void ChromeBrowserMainParts::PreMainMessageLoopRun() { |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2162 #endif // defined(SYZYASAN) | 2166 #endif // defined(SYZYASAN) |
2163 #endif // defined(OS_ANDROID) | 2167 #endif // defined(OS_ANDROID) |
2164 } | 2168 } |
2165 | 2169 |
2166 void ChromeBrowserMainParts::PostDestroyThreads() { | 2170 void ChromeBrowserMainParts::PostDestroyThreads() { |
2167 #if defined(OS_ANDROID) | 2171 #if defined(OS_ANDROID) |
2168 // On Android, there is no quit/exit. So the browser's main message loop will | 2172 // On Android, there is no quit/exit. So the browser's main message loop will |
2169 // not finish. | 2173 // not finish. |
2170 NOTREACHED(); | 2174 NOTREACHED(); |
2171 #else | 2175 #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_ | 2176 int restart_flags = restart_last_session_ |
2180 ? browser_shutdown::RESTART_LAST_SESSION | 2177 ? browser_shutdown::RESTART_LAST_SESSION |
2181 : browser_shutdown::NO_FLAGS; | 2178 : browser_shutdown::NO_FLAGS; |
2182 | 2179 |
2183 #if BUILDFLAG(ENABLE_BACKGROUND) | 2180 #if BUILDFLAG(ENABLE_BACKGROUND) |
2184 if (restart_flags) { | 2181 if (restart_flags) { |
2185 restart_flags |= BackgroundModeManager::should_restart_in_background() | 2182 restart_flags |= BackgroundModeManager::should_restart_in_background() |
2186 ? browser_shutdown::RESTART_IN_BACKGROUND | 2183 ? browser_shutdown::RESTART_IN_BACKGROUND |
2187 : browser_shutdown::NO_FLAGS; | 2184 : browser_shutdown::NO_FLAGS; |
2188 } | 2185 } |
2189 #endif // BUILDFLAG(ENABLE_BACKGROUND) | 2186 #endif // BUILDFLAG(ENABLE_BACKGROUND) |
2190 | 2187 |
2191 browser_process_->PostDestroyThreads(); | 2188 browser_process_->PostDestroyThreads(); |
2192 // browser_shutdown takes care of deleting browser_process, so we need to | 2189 // browser_shutdown takes care of deleting browser_process, so we need to |
2193 // release it. | 2190 // release it. |
2194 ignore_result(browser_process_.release()); | 2191 ignore_result(browser_process_.release()); |
2192 | |
2193 // The TaskScheduler was initialized before browser process PreCreateThreads. | |
fdoray
2016/09/16 18:20:28
"before the call to PreCreateThreads() on |browser
robliao
2016/09/16 21:35:40
Done.
| |
2194 // To maintain scoping symmetry, perform the shutdown after browser process | |
2195 // PostDestroyThreads. | |
2196 base::TaskScheduler* task_scheduler = base::TaskScheduler::GetInstance(); | |
2197 if (task_scheduler) | |
2198 task_scheduler->Shutdown(); | |
2199 | |
2195 browser_shutdown::ShutdownPostThreadsStop(restart_flags); | 2200 browser_shutdown::ShutdownPostThreadsStop(restart_flags); |
2196 master_prefs_.reset(); | 2201 master_prefs_.reset(); |
2197 process_singleton_.reset(); | 2202 process_singleton_.reset(); |
2198 device_event_log::Shutdown(); | 2203 device_event_log::Shutdown(); |
2199 | 2204 |
2200 // We need to do this check as late as possible, but due to modularity, this | 2205 // 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 | 2206 // 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 | 2207 // 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 | 2208 // to bypass this code. Perhaps we need a *final* hook that is called on all |
2204 // paths from content/browser/browser_main. | 2209 // paths from content/browser/browser_main. |
2205 CHECK(metrics::MetricsService::UmaMetricsProperlyShutdown()); | 2210 CHECK(metrics::MetricsService::UmaMetricsProperlyShutdown()); |
2206 | 2211 |
2207 #if defined(OS_CHROMEOS) | 2212 #if defined(OS_CHROMEOS) |
2208 chromeos::CrosSettings::Shutdown(); | 2213 chromeos::CrosSettings::Shutdown(); |
2209 #endif // defined(OS_CHROMEOS) | 2214 #endif // defined(OS_CHROMEOS) |
2210 #endif // defined(OS_ANDROID) | 2215 #endif // defined(OS_ANDROID) |
2211 } | 2216 } |
2212 | 2217 |
2213 // Public members: | 2218 // Public members: |
2214 | 2219 |
2215 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { | 2220 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { |
2216 chrome_extra_parts_.push_back(parts); | 2221 chrome_extra_parts_.push_back(parts); |
2217 } | 2222 } |
OLD | NEW |