Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1864)

Unified Diff: chrome/browser/lifetime/application_lifetime.cc

Issue 1086733002: Ensure tests have an active task runner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/lifetime/application_lifetime.cc
diff --git a/chrome/browser/lifetime/application_lifetime.cc b/chrome/browser/lifetime/application_lifetime.cc
index ac9ff01f43aa4ea60b611be98da1c58cd94896a6..0d80bd111cac9330417e18fd9bf65e512f3007bc 100644
--- a/chrome/browser/lifetime/application_lifetime.cc
+++ b/chrome/browser/lifetime/application_lifetime.cc
@@ -82,6 +82,7 @@ bool AreAllBrowsersCloseable() {
#endif // !defined(OS_ANDROID)
int g_keep_alive_count = 0;
+bool g_disable_shutdown_for_testing = false;
#if defined(OS_CHROMEOS)
// Whether chrome should send stop request to a session manager.
@@ -319,11 +320,20 @@ void IncrementKeepAliveCount() {
++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) {
+ CloseAllBrowsers();
+ }
+}
+
void DecrementKeepAliveCount() {
DCHECK_GT(g_keep_alive_count, 0);
--g_keep_alive_count;
-
- DCHECK(g_browser_process);
// Although we should have a browser process, if there is none,
// there is nothing to do.
if (!g_browser_process) return;
@@ -331,14 +341,7 @@ void DecrementKeepAliveCount() {
// Allow the app to shutdown again.
if (!WillKeepAlive()) {
g_browser_process->ReleaseModule();
- // 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).
- if (chrome::GetTotalBrowserCount() == 0 &&
- !browser_shutdown::IsTryingToQuit() &&
- base::MessageLoop::current()) {
- CloseAllBrowsers();
- }
+ CloseAllBrowsersIfNeeded();
}
}
@@ -422,4 +425,10 @@ bool ShouldStartShutdown(Browser* browser) {
return true;
}
+void DisableShutdownForTesting(bool disable_shutdown_for_testing) {
+ g_disable_shutdown_for_testing = disable_shutdown_for_testing;
+ if (!g_disable_shutdown_for_testing && !WillKeepAlive())
+ CloseAllBrowsersIfNeeded();
+}
+
} // namespace chrome
« no previous file with comments | « chrome/browser/lifetime/application_lifetime.h ('k') | chrome/browser/media/webrtc_log_uploader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698