Chromium Code Reviews| Index: chrome/browser/lifetime/application_lifetime.cc |
| diff --git a/chrome/browser/lifetime/application_lifetime.cc b/chrome/browser/lifetime/application_lifetime.cc |
| index 657c71bcc8fe3baa98d4f89488deb70dff6b106e..ba2fe825148d6b8c65d0ce04c4d4f9814187dcb6 100644 |
| --- a/chrome/browser/lifetime/application_lifetime.cc |
| +++ b/chrome/browser/lifetime/application_lifetime.cc |
| @@ -17,6 +17,7 @@ |
| #include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/browser/download/download_service.h" |
| #include "chrome/browser/lifetime/browser_close_manager.h" |
| +#include "chrome/browser/lifetime/keep_alive_registry.h" |
| #include "chrome/browser/metrics/thread_watcher.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| @@ -47,6 +48,7 @@ |
| #endif |
| namespace chrome { |
| + |
| namespace { |
| #if !defined(OS_ANDROID) |
| @@ -70,7 +72,6 @@ bool AreAllBrowsersCloseable() { |
| return true; |
| } |
| -int g_keep_alive_count = 0; |
| bool g_disable_shutdown_for_testing = false; |
| #endif // !defined(OS_ANDROID) |
| @@ -113,7 +114,8 @@ void CloseAllBrowsers() { |
| // application, send the APP_TERMINATING action here. Otherwise, it will be |
| // sent by RemoveBrowser() when the last browser has closed. |
| if (chrome::GetTotalBrowserCount() == 0 && |
| - (browser_shutdown::IsTryingToQuit() || !chrome::WillKeepAlive())) { |
| + (browser_shutdown::IsTryingToQuit() || |
| + !KeepAliveRegistry::GetInstance()->IsKeepingAlive())) { |
| // Tell everyone that we are shutting down. |
| browser_shutdown::SetTryingToQuit(true); |
| @@ -275,18 +277,7 @@ void SessionEnding() { |
| base::Process::Current().Terminate(0, false); |
| } |
| -void IncrementKeepAliveCount() { |
| - // Increment the browser process refcount as long as we're keeping the |
|
dgn
2016/03/09 23:49:23
moved to KeepAliveRegistry::OnKeepingAliveChanged
|
| - // application alive. |
| - if (!WillKeepAlive()) |
| - g_browser_process->AddRefModule(); |
| - ++g_keep_alive_count; |
| -} |
| - |
| void CloseAllBrowsersIfNeeded() { |
| - // If there are no browsers open and we aren't already shutting down, |
| - // initiate a shutdown. Also skips shutdown if this is a unit test. |
| - // (MessageLoop::current() == null or explicitly disabled). |
| if (chrome::GetTotalBrowserCount() == 0 && |
| !browser_shutdown::IsTryingToQuit() && base::MessageLoop::current() && |
| !g_disable_shutdown_for_testing) { |
| @@ -294,27 +285,6 @@ void CloseAllBrowsersIfNeeded() { |
| } |
| } |
| -void DecrementKeepAliveCount() { |
| - DCHECK_GT(g_keep_alive_count, 0); |
| - --g_keep_alive_count; |
| - // Although we should have a browser process, if there is none, |
|
dgn
2016/03/09 23:49:23
moved to KeepAliveRegistry::OnKeepingAliveChanged
|
| - // there is nothing to do. |
| - if (!g_browser_process) return; |
| - |
| - // Allow the app to shutdown again. |
| - if (!WillKeepAlive()) { |
| - g_browser_process->ReleaseModule(); |
| - CloseAllBrowsersIfNeeded(); |
| - } |
| -} |
| - |
| -int GetKeepAliveCountForTesting() { |
| - return g_keep_alive_count; |
| -} |
| - |
| -bool WillKeepAlive() { |
| - return g_keep_alive_count > 0; |
| -} |
| #endif // !defined(OS_ANDROID) |
| void NotifyAppTerminating() { |
| @@ -377,7 +347,8 @@ void OnAppExiting() { |
| void DisableShutdownForTesting(bool disable_shutdown_for_testing) { |
| g_disable_shutdown_for_testing = disable_shutdown_for_testing; |
| - if (!g_disable_shutdown_for_testing && !WillKeepAlive()) |
| + if (!g_disable_shutdown_for_testing && |
| + !KeepAliveRegistry::GetInstance()->IsKeepingAlive()) |
| CloseAllBrowsersIfNeeded(); |
| } |
| #endif // !defined(OS_ANDROID) |