| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 if (DownloadService::NonMaliciousDownloadCountAllProfiles() > 0) | 63 if (DownloadService::NonMaliciousDownloadCountAllProfiles() > 0) |
| 64 return false; | 64 return false; |
| 65 | 65 |
| 66 // Check TabsNeedBeforeUnloadFired(). | 66 // Check TabsNeedBeforeUnloadFired(). |
| 67 for (auto* browser : *BrowserList::GetInstance()) { | 67 for (auto* browser : *BrowserList::GetInstance()) { |
| 68 if (browser->TabsNeedBeforeUnloadFired()) | 68 if (browser->TabsNeedBeforeUnloadFired()) |
| 69 return false; | 69 return false; |
| 70 } | 70 } |
| 71 return true; | 71 return true; |
| 72 } | 72 } |
| 73 | |
| 74 bool g_disable_shutdown_for_testing = false; | |
| 75 #endif // !defined(OS_ANDROID) | 73 #endif // !defined(OS_ANDROID) |
| 76 | 74 |
| 77 #if defined(OS_CHROMEOS) | 75 #if defined(OS_CHROMEOS) |
| 78 // Whether chrome should send stop request to a session manager. | 76 // Whether chrome should send stop request to a session manager. |
| 79 bool g_send_stop_request_to_session_manager = false; | 77 bool g_send_stop_request_to_session_manager = false; |
| 80 #endif | 78 #endif |
| 81 | 79 |
| 82 } // namespace | 80 } // namespace |
| 83 | 81 |
| 84 void MarkAsCleanShutdown() { | 82 void MarkAsCleanShutdown() { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 101 | 99 |
| 102 g_browser_process->platform_part()->AttemptExit(); | 100 g_browser_process->platform_part()->AttemptExit(); |
| 103 } | 101 } |
| 104 | 102 |
| 105 #if !defined(OS_ANDROID) | 103 #if !defined(OS_ANDROID) |
| 106 void CloseAllBrowsersAndQuit() { | 104 void CloseAllBrowsersAndQuit() { |
| 107 browser_shutdown::SetTryingToQuit(true); | 105 browser_shutdown::SetTryingToQuit(true); |
| 108 CloseAllBrowsers(); | 106 CloseAllBrowsers(); |
| 109 } | 107 } |
| 110 | 108 |
| 109 void ShutdownIfNoBrowsers() { |
| 110 if (chrome::GetTotalBrowserCount() > 0) |
| 111 return; |
| 112 |
| 113 // Tell everyone that we are shutting down. |
| 114 browser_shutdown::SetTryingToQuit(true); |
| 115 |
| 116 #if defined(ENABLE_SESSION_SERVICE) |
| 117 // If ShuttingDownWithoutClosingBrowsers() returns true, the session |
| 118 // services may not get a chance to shut down normally, so explicitly shut |
| 119 // them down here to ensure they have a chance to persist their data. |
| 120 ProfileManager::ShutdownSessionServices(); |
| 121 #endif |
| 122 |
| 123 chrome::NotifyAndTerminate(true); |
| 124 chrome::OnAppExiting(); |
| 125 } |
| 126 |
| 111 void CloseAllBrowsers() { | 127 void CloseAllBrowsers() { |
| 112 // If there are no browsers and closing the last browser would quit the | 128 // 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 | 129 // application, send the APP_TERMINATING action here. Otherwise, it will be |
| 114 // sent by RemoveBrowser() when the last browser has closed. | 130 // sent by RemoveBrowser() when the last browser has closed. |
| 115 if (chrome::GetTotalBrowserCount() == 0 && | 131 if (chrome::GetTotalBrowserCount() == 0 && |
| 116 (browser_shutdown::IsTryingToQuit() || | 132 (browser_shutdown::IsTryingToQuit() || |
| 117 !KeepAliveRegistry::GetInstance()->IsKeepingAlive())) { | 133 !KeepAliveRegistry::GetInstance()->IsKeepingAlive())) { |
| 118 // Tell everyone that we are shutting down. | 134 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; | 135 return; |
| 131 } | 136 } |
| 132 | 137 |
| 133 #if defined(OS_CHROMEOS) | 138 #if defined(OS_CHROMEOS) |
| 134 chromeos::BootTimesRecorder::Get()->AddLogoutTimeMarker( | 139 chromeos::BootTimesRecorder::Get()->AddLogoutTimeMarker( |
| 135 "StartedClosingWindows", false); | 140 "StartedClosingWindows", false); |
| 136 #endif | 141 #endif |
| 137 scoped_refptr<BrowserCloseManager> browser_close_manager = | 142 scoped_refptr<BrowserCloseManager> browser_close_manager = |
| 138 new BrowserCloseManager; | 143 new BrowserCloseManager; |
| 139 browser_close_manager->StartClosingBrowsers(); | 144 browser_close_manager->StartClosingBrowsers(); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 #if defined(OS_WIN) | 274 #if defined(OS_WIN) |
| 270 base::win::SetShouldCrashOnProcessDetach(false); | 275 base::win::SetShouldCrashOnProcessDetach(false); |
| 271 #endif | 276 #endif |
| 272 // On Windows 7 and later, the system will consider the process ripe for | 277 // 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 | 278 // termination as soon as it hides or destroys its windows. Since any |
| 274 // execution past that point will be non-deterministically cut short, we | 279 // execution past that point will be non-deterministically cut short, we |
| 275 // might as well put ourselves out of that misery deterministically. | 280 // might as well put ourselves out of that misery deterministically. |
| 276 base::Process::Current().Terminate(0, false); | 281 base::Process::Current().Terminate(0, false); |
| 277 } | 282 } |
| 278 | 283 |
| 279 void CloseAllBrowsersIfNeeded() { | 284 void ShutdownIfNeeded() { |
| 280 if (chrome::GetTotalBrowserCount() == 0 && | 285 if (browser_shutdown::IsTryingToQuit()) |
| 281 !browser_shutdown::IsTryingToQuit() && base::MessageLoop::current() && | 286 return; |
| 282 !g_disable_shutdown_for_testing) { | 287 |
| 283 CloseAllBrowsers(); | 288 ShutdownIfNoBrowsers(); |
| 284 } | |
| 285 } | 289 } |
| 286 | 290 |
| 287 #endif // !defined(OS_ANDROID) | 291 #endif // !defined(OS_ANDROID) |
| 288 | 292 |
| 289 void NotifyAppTerminating() { | 293 void NotifyAppTerminating() { |
| 290 static bool notified = false; | 294 static bool notified = false; |
| 291 if (notified) | 295 if (notified) |
| 292 return; | 296 return; |
| 293 notified = true; | 297 notified = true; |
| 294 content::NotificationService::current()->Notify( | 298 content::NotificationService::current()->Notify( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 } | 340 } |
| 337 | 341 |
| 338 #if !defined(OS_ANDROID) | 342 #if !defined(OS_ANDROID) |
| 339 void OnAppExiting() { | 343 void OnAppExiting() { |
| 340 static bool notified = false; | 344 static bool notified = false; |
| 341 if (notified) | 345 if (notified) |
| 342 return; | 346 return; |
| 343 notified = true; | 347 notified = true; |
| 344 HandleAppExitingForPlatform(); | 348 HandleAppExitingForPlatform(); |
| 345 } | 349 } |
| 346 | |
| 347 void DisableShutdownForTesting(bool disable_shutdown_for_testing) { | |
| 348 g_disable_shutdown_for_testing = disable_shutdown_for_testing; | |
| 349 if (!g_disable_shutdown_for_testing && | |
| 350 !KeepAliveRegistry::GetInstance()->IsKeepingAlive()) | |
| 351 CloseAllBrowsersIfNeeded(); | |
| 352 } | |
| 353 #endif // !defined(OS_ANDROID) | 350 #endif // !defined(OS_ANDROID) |
| 354 | 351 |
| 355 } // namespace chrome | 352 } // namespace chrome |
| OLD | NEW |