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

Unified Diff: chrome/browser/background_mode_manager.cc

Issue 3198007: BackgroudModeManager now listens for APP_TERMINATING and shuts down background (Closed)
Patch Set: Created 10 years, 4 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/background_mode_manager.cc
diff --git a/chrome/browser/background_mode_manager.cc b/chrome/browser/background_mode_manager.cc
index f67a34bab9eb97f815b5e92532b673b0e66a2c34..52b198375215da01d497420e8609a78f6bae3818 100644
--- a/chrome/browser/background_mode_manager.cc
+++ b/chrome/browser/background_mode_manager.cc
@@ -35,13 +35,10 @@ BackgroundModeManager::BackgroundModeManager(Profile* profile)
return;
// If the -keep-alive-for-test flag is passed, then always keep chrome running
- // in the background until the user explicitly terminates it.
- if (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kKeepAliveForTest)) {
- StartBackgroundMode();
- registrar_.Add(this, NotificationType::APP_TERMINATING,
- NotificationService::AllSources());
- }
+ // in the background until the user explicitly terminates it, by acting as if
+ // we loaded a background app.
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKeepAliveForTest))
+ OnBackgroundAppLoaded();
// When an extension is installed, make sure launch on startup is properly
// set if appropriate. Likewise, turn off launch on startup when the last
@@ -63,6 +60,12 @@ BackgroundModeManager::BackgroundModeManager(Profile* profile)
registrar_.Add(this, NotificationType::EXTENSIONS_READY,
Source<Profile>(profile));
+ // Listen for the application shutting down so we can decrement our KeepAlive
+ // count.
+ registrar_.Add(this, NotificationType::APP_TERMINATING,
+ NotificationService::AllSources());
+
+
}
BackgroundModeManager::~BackgroundModeManager() {
@@ -100,12 +103,13 @@ void BackgroundModeManager::Observe(NotificationType type,
OnBackgroundAppUninstalled();
break;
case NotificationType::APP_TERMINATING:
- // Performing an explicit shutdown, so allow the browser process to exit.
- // (we only listen for this notification if the keep-alive-for-test flag
- // is passed).
- DCHECK(CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kKeepAliveForTest));
- EndBackgroundMode();
+ // Performing an explicit shutdown, so exit background mode if we were in
+ // background mode.
+ if (background_app_count_ > 0 && IsBackgroundModeEnabled())
+ EndBackgroundMode();
+ // Shutting down, so don't listen for any more notifications so we don't
+ // try to re-enter/exit background mode again.
+ registrar_.RemoveAll();
break;
default:
NOTREACHED();

Powered by Google App Engine
This is Rietveld 408576698