diff options
author | atwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-27 23:44:55 +0000 |
---|---|---|
committer | atwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-27 23:44:55 +0000 |
commit | 3190a0188be239b00c8781b096db50dd72e5e00b (patch) | |
tree | 8d3caa26daa181b6df65fff462500fda7e2b46be /chrome/browser/background_mode_manager.cc | |
parent | 07dc3928e698dbcb8a51151442caef94dff45ab3 (diff) | |
download | chromium_src-3190a0188be239b00c8781b096db50dd72e5e00b.zip chromium_src-3190a0188be239b00c8781b096db50dd72e5e00b.tar.gz chromium_src-3190a0188be239b00c8781b096db50dd72e5e00b.tar.bz2 |
Revert 57749 - Disable background mode when associated pref changes.
Disabling because new tests don't work now that BackgroundModeManager is
disabled by default from r57713.
BUG=53173
TEST=new BackgroundModeManager unit tests
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=57642
Review URL: http://codereview.chromium.org/3205008
TBR=atwilson@chromium.org
Review URL: http://codereview.chromium.org/3223008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57752 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/background_mode_manager.cc')
-rw-r--r-- | chrome/browser/background_mode_manager.cc | 59 |
1 files changed, 9 insertions, 50 deletions
diff --git a/chrome/browser/background_mode_manager.cc b/chrome/browser/background_mode_manager.cc index 7c5a4e2..4fe5e2e 100644 --- a/chrome/browser/background_mode_manager.cc +++ b/chrome/browser/background_mode_manager.cc @@ -34,7 +34,6 @@ BackgroundModeManager::BackgroundModeManager(Profile* profile) : profile_(profile), background_app_count_(0), - in_background_mode_(false), status_tray_(NULL), status_icon_(NULL) { // If background mode is globally disabled, just exit - don't listen for @@ -74,20 +73,13 @@ BackgroundModeManager::BackgroundModeManager(Profile* profile) registrar_.Add(this, NotificationType::APP_TERMINATING, NotificationService::AllSources()); - // Listen for changes to the background mode preference. - profile_->GetPrefs()->AddPrefObserver(prefs::kBackgroundModeEnabled, this); + } BackgroundModeManager::~BackgroundModeManager() { - // We're going away, so exit background mode (does nothing if we aren't in - // background mode currently). This is primarily needed for unit tests, - // because in an actual running system we'd get an APP_TERMINATING - // notification before being destroyed. - EndBackgroundMode(); - // Manually remove our pref observer so we don't get notified for prefs - // changes (have to do it manually because we can't use the registrar for - // prefs notifications). - profile_->GetPrefs()->RemovePrefObserver(prefs::kBackgroundModeEnabled, this); + // If we're going away, remove our status tray icon so we don't get any events + // from it. + RemoveStatusTrayIcon(); } bool BackgroundModeManager::IsBackgroundModeEnabled() { @@ -133,18 +125,14 @@ void BackgroundModeManager::Observe(NotificationType type, OnBackgroundAppUninstalled(); break; case NotificationType::APP_TERMINATING: - // Performing an explicit shutdown, so exit background mode (does nothing - // if we aren't in background mode currently). - 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; - case NotificationType::PREF_CHANGED: - DCHECK(0 == Details<std::string>(details).ptr()->compare( - prefs::kBackgroundModeEnabled)); - OnBackgroundModePrefChanged(); - break; default: NOTREACHED(); break; @@ -155,24 +143,6 @@ bool BackgroundModeManager::IsBackgroundApp(Extension* extension) { return extension->HasApiPermission(Extension::kBackgroundPermission); } - -void BackgroundModeManager::OnBackgroundModePrefChanged() { - // Background mode has been enabled/disabled in preferences, so update our - // state accordingly. - if (IsBackgroundModeEnabled() && !in_background_mode_ && - background_app_count_ > 0) { - // We should be in background mode, but we're not, so switch to background - // mode. - EnableLaunchOnStartup(true); - StartBackgroundMode(); - } - if (!IsBackgroundModeEnabled() && in_background_mode_) { - // We're in background mode, but we shouldn't be any longer. - EnableLaunchOnStartup(false); - EndBackgroundMode(); - } -} - void BackgroundModeManager::OnBackgroundAppLoaded() { // When a background app loads, increment our count and also enable // KeepAlive mode if the preference is set. @@ -182,13 +152,6 @@ void BackgroundModeManager::OnBackgroundAppLoaded() { } void BackgroundModeManager::StartBackgroundMode() { - // Don't bother putting ourselves in background mode if we're already there. - if (in_background_mode_) - return; - - // Mark ourselves as running in background mode. - in_background_mode_ = true; - // Put ourselves in KeepAlive mode and create a status tray icon. BrowserList::StartKeepAlive(); @@ -200,16 +163,12 @@ void BackgroundModeManager::OnBackgroundAppUnloaded() { // When a background app unloads, decrement our count and also end // KeepAlive mode if appropriate. background_app_count_--; - DCHECK(background_app_count_ >= 0); + DCHECK(background_app_count_ == 0); if (background_app_count_ == 0 && IsBackgroundModeEnabled()) EndBackgroundMode(); } void BackgroundModeManager::EndBackgroundMode() { - if (!in_background_mode_) - return; - in_background_mode_ = false; - // End KeepAlive mode and blow away our status tray icon. BrowserList::EndKeepAlive(); RemoveStatusTrayIcon(); |