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/lifetime/application_lifetime.h" | 5 #include "chrome/browser/lifetime/application_lifetime.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 | 101 |
| 102 g_browser_process->platform_part()->AttemptExit(); | 102 g_browser_process->platform_part()->AttemptExit(); |
| 103 } | 103 } |
| 104 | 104 |
| 105 #if !defined(OS_ANDROID) | 105 #if !defined(OS_ANDROID) |
| 106 void CloseAllBrowsersAndQuit() { | 106 void CloseAllBrowsersAndQuit() { |
| 107 browser_shutdown::SetTryingToQuit(true); | 107 browser_shutdown::SetTryingToQuit(true); |
| 108 CloseAllBrowsers(); | 108 CloseAllBrowsers(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void ShutdownIfNoBrowsers() { | |
| 112 if (chrome::GetTotalBrowserCount() > 0) | |
| 113 return; | |
| 114 | |
| 115 // Tell everyone that we are shutting down. | |
| 116 browser_shutdown::SetTryingToQuit(true); | |
| 117 | |
| 118 #if defined(ENABLE_SESSION_SERVICE) | |
| 119 // If ShuttingDownWithoutClosingBrowsers() returns true, the session | |
| 120 // services may not get a chance to shut down normally, so explicitly shut | |
| 121 // them down here to ensure they have a chance to persist their data. | |
| 122 ProfileManager::ShutdownSessionServices(); | |
| 123 #endif | |
| 124 | |
| 125 chrome::NotifyAndTerminate(true); | |
| 126 chrome::OnAppExiting(); | |
| 127 } | |
| 128 | |
| 111 void CloseAllBrowsers() { | 129 void CloseAllBrowsers() { |
| 112 // If there are no browsers and closing the last browser would quit the | 130 // If there are no browsers and closing the last browser would quit the |
| 113 // application, send the APP_TERMINATING action here. Otherwise, it will be | 131 // application, send the APP_TERMINATING action here. Otherwise, it will be |
| 114 // sent by RemoveBrowser() when the last browser has closed. | 132 // sent by RemoveBrowser() when the last browser has closed. |
| 115 if (chrome::GetTotalBrowserCount() == 0 && | 133 if (chrome::GetTotalBrowserCount() == 0 && |
| 116 (browser_shutdown::IsTryingToQuit() || | 134 (browser_shutdown::IsTryingToQuit() || |
| 117 !KeepAliveRegistry::GetInstance()->IsKeepingAlive())) { | 135 !KeepAliveRegistry::GetInstance()->IsKeepingAlive())) { |
| 118 // Tell everyone that we are shutting down. | 136 ShutdownIfNoBrowsers(); |
| 119 browser_shutdown::SetTryingToQuit(true); | |
| 120 | |
| 121 #if defined(ENABLE_SESSION_SERVICE) | |
| 122 // If ShuttingDownWithoutClosingBrowsers() returns true, the session | |
| 123 // services may not get a chance to shut down normally, so explicitly shut | |
| 124 // them down here to ensure they have a chance to persist their data. | |
| 125 ProfileManager::ShutdownSessionServices(); | |
| 126 #endif | |
| 127 | |
| 128 chrome::NotifyAndTerminate(true); | |
| 129 chrome::OnAppExiting(); | |
| 130 return; | 137 return; |
| 131 } | 138 } |
| 132 | 139 |
| 133 #if defined(OS_CHROMEOS) | 140 #if defined(OS_CHROMEOS) |
| 134 chromeos::BootTimesRecorder::Get()->AddLogoutTimeMarker( | 141 chromeos::BootTimesRecorder::Get()->AddLogoutTimeMarker( |
| 135 "StartedClosingWindows", false); | 142 "StartedClosingWindows", false); |
| 136 #endif | 143 #endif |
| 137 scoped_refptr<BrowserCloseManager> browser_close_manager = | 144 scoped_refptr<BrowserCloseManager> browser_close_manager = |
| 138 new BrowserCloseManager; | 145 new BrowserCloseManager; |
| 139 browser_close_manager->StartClosingBrowsers(); | 146 browser_close_manager->StartClosingBrowsers(); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 #if defined(OS_WIN) | 276 #if defined(OS_WIN) |
| 270 base::win::SetShouldCrashOnProcessDetach(false); | 277 base::win::SetShouldCrashOnProcessDetach(false); |
| 271 #endif | 278 #endif |
| 272 // On Windows 7 and later, the system will consider the process ripe for | 279 // On Windows 7 and later, the system will consider the process ripe for |
| 273 // termination as soon as it hides or destroys its windows. Since any | 280 // termination as soon as it hides or destroys its windows. Since any |
| 274 // execution past that point will be non-deterministically cut short, we | 281 // execution past that point will be non-deterministically cut short, we |
| 275 // might as well put ourselves out of that misery deterministically. | 282 // might as well put ourselves out of that misery deterministically. |
| 276 base::Process::Current().Terminate(0, false); | 283 base::Process::Current().Terminate(0, false); |
| 277 } | 284 } |
| 278 | 285 |
| 279 void CloseAllBrowsersIfNeeded() { | 286 void ShutdownIfNeeded() { |
| 280 if (chrome::GetTotalBrowserCount() == 0 && | 287 if (g_disable_shutdown_for_testing) |
| 281 !browser_shutdown::IsTryingToQuit() && base::MessageLoop::current() && | 288 return; |
| 282 !g_disable_shutdown_for_testing) { | 289 |
| 283 CloseAllBrowsers(); | 290 // We are already in the process of shutting down, no need to renotify. |
| 284 } | 291 if (browser_shutdown::IsTryingToQuit()) |
| 292 return; | |
| 293 | |
| 294 ShutdownIfNoBrowsers(); | |
|
dgn
2016/03/16 15:10:50
Moved the method out of CloseAllBrowsers to make w
| |
| 285 } | 295 } |
| 286 | 296 |
| 287 #endif // !defined(OS_ANDROID) | 297 #endif // !defined(OS_ANDROID) |
| 288 | 298 |
| 289 void NotifyAppTerminating() { | 299 void NotifyAppTerminating() { |
| 290 static bool notified = false; | 300 static bool notified = false; |
| 291 if (notified) | 301 if (notified) |
| 292 return; | 302 return; |
| 293 notified = true; | 303 notified = true; |
| 294 content::NotificationService::current()->Notify( | 304 content::NotificationService::current()->Notify( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 void OnAppExiting() { | 349 void OnAppExiting() { |
| 340 static bool notified = false; | 350 static bool notified = false; |
| 341 if (notified) | 351 if (notified) |
| 342 return; | 352 return; |
| 343 notified = true; | 353 notified = true; |
| 344 HandleAppExitingForPlatform(); | 354 HandleAppExitingForPlatform(); |
| 345 } | 355 } |
| 346 | 356 |
| 347 void DisableShutdownForTesting(bool disable_shutdown_for_testing) { | 357 void DisableShutdownForTesting(bool disable_shutdown_for_testing) { |
| 348 g_disable_shutdown_for_testing = disable_shutdown_for_testing; | 358 g_disable_shutdown_for_testing = disable_shutdown_for_testing; |
| 349 if (!g_disable_shutdown_for_testing && | 359 |
| 350 !KeepAliveRegistry::GetInstance()->IsKeepingAlive()) | 360 if (!KeepAliveRegistry::GetInstance()->IsKeepingAlive()) |
| 351 CloseAllBrowsersIfNeeded(); | 361 ShutdownIfNeeded(); |
| 352 } | 362 } |
| 353 #endif // !defined(OS_ANDROID) | 363 #endif // !defined(OS_ANDROID) |
| 354 | 364 |
| 355 } // namespace chrome | 365 } // namespace chrome |
| OLD | NEW |