Index: chrome/browser/background/background_mode_manager.cc |
diff --git a/chrome/browser/background/background_mode_manager.cc b/chrome/browser/background/background_mode_manager.cc |
index b1ffcd17cb0e3e4b0da6e9c18413ce006addab73..5761511e45d374ffbcd1ce73c24284c263e6265d 100644 |
--- a/chrome/browser/background/background_mode_manager.cc |
+++ b/chrome/browser/background/background_mode_manager.cc |
@@ -30,6 +30,7 @@ |
#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/browser_commands.h" |
#include "chrome/browser/ui/browser_finder.h" |
+#include "chrome/browser/ui/browser_list.h" |
#include "chrome/browser/ui/chrome_pages.h" |
#include "chrome/browser/ui/extensions/application_launch.h" |
#include "chrome/browser/ui/host_desktop.h" |
@@ -148,6 +149,7 @@ BackgroundModeManager::BackgroundModeManager( |
in_background_mode_(false), |
keep_alive_for_startup_(false), |
keep_alive_for_test_(false), |
+ background_mode_suspended_(false), |
current_command_id_(0) { |
// We should never start up if there is no browser process or if we are |
// currently quitting. |
@@ -188,6 +190,7 @@ BackgroundModeManager::BackgroundModeManager( |
// count. |
registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
content::NotificationService::AllSources()); |
+ BrowserList::AddObserver(this); |
} |
BackgroundModeManager::~BackgroundModeManager() { |
@@ -199,6 +202,7 @@ BackgroundModeManager::~BackgroundModeManager() { |
++it) { |
it->second->applications_->RemoveObserver(this); |
} |
+ BrowserList::RemoveObserver(this); |
// 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, |
@@ -457,7 +461,7 @@ void BackgroundModeManager::ExecuteCommand(int command_id, int event_flags) { |
break; |
case IDC_EXIT: |
content::RecordAction(UserMetricsAction("Exit")); |
- chrome::AttemptExit(); |
+ chrome::CloseAllBrowsers(); |
break; |
case IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND: { |
// Background mode must already be enabled (as otherwise this menu would |
@@ -502,11 +506,13 @@ void BackgroundModeManager::StartBackgroundMode() { |
// Mark ourselves as running in background mode. |
in_background_mode_ = true; |
- // Put ourselves in KeepAlive mode and create a status tray icon. |
- chrome::StartKeepAlive(); |
+ if (!background_mode_suspended_) { |
+ // Put ourselves in KeepAlive mode and create a status tray icon. |
+ chrome::StartKeepAlive(); |
- // Display a status icon to exit Chrome. |
- InitStatusTrayIcon(); |
+ // Display a status icon to exit Chrome. |
+ InitStatusTrayIcon(); |
+ } |
content::NotificationService::current()->Notify( |
chrome::NOTIFICATION_BACKGROUND_MODE_CHANGED, |
@@ -515,6 +521,7 @@ void BackgroundModeManager::StartBackgroundMode() { |
} |
void BackgroundModeManager::InitStatusTrayIcon() { |
+ DCHECK(!background_mode_suspended_); |
// Only initialize status tray icons for those profiles which actually |
// have a background app running. |
if (ShouldBeInBackgroundMode()) |
@@ -526,10 +533,12 @@ void BackgroundModeManager::EndBackgroundMode() { |
return; |
in_background_mode_ = false; |
- // End KeepAlive mode and blow away our status tray icon. |
- chrome::EndKeepAlive(); |
+ if (!background_mode_suspended_) { |
+ // End KeepAlive mode and blow away our status tray icon. |
+ chrome::EndKeepAlive(); |
- RemoveStatusTrayIcon(); |
+ RemoveStatusTrayIcon(); |
+ } |
content::NotificationService::current()->Notify( |
chrome::NOTIFICATION_BACKGROUND_MODE_CHANGED, |
content::Source<BackgroundModeManager>(this), |
@@ -554,6 +563,38 @@ void BackgroundModeManager::DisableBackgroundMode() { |
} |
} |
+void BackgroundModeManager::SuspendBackgroundMode() { |
+ if (background_mode_suspended_) |
+ return; |
+ |
+ background_mode_suspended_ = true; |
+ |
+ if (!in_background_mode_) |
+ return; |
+ |
+ chrome::EndKeepAlive(); |
benwells
2013/10/20 23:46:22
Move the keepalive / status tray stuff into functi
Sam McNally
2013/10/21 04:31:03
Done.
|
+ |
+ RemoveStatusTrayIcon(); |
+} |
+ |
+void BackgroundModeManager::ResumeBackgroundMode() { |
+ if (!background_mode_suspended_) |
+ return; |
+ |
+ background_mode_suspended_ = false; |
+ |
+ if (!in_background_mode_) |
+ return; |
+ |
+ chrome::StartKeepAlive(); |
+ |
+ InitStatusTrayIcon(); |
+} |
+ |
+void BackgroundModeManager::OnBrowserAdded(Browser* browser) { |
+ ResumeBackgroundMode(); |
+} |
+ |
int BackgroundModeManager::GetBackgroundAppCount() const { |
int count = 0; |
// Walk the BackgroundModeData for all profiles and count the number of apps. |
@@ -583,6 +624,8 @@ void BackgroundModeManager::OnBackgroundAppInstalled( |
// Background mode is disabled - don't do anything. |
if (!IsBackgroundModePrefEnabled()) |
return; |
+ if (background_mode_suspended_) |
+ return; |
// Check if we need a status tray icon and make one if we do (needed so we |
// can display the app-installed notification below). |
@@ -640,6 +683,9 @@ void BackgroundModeManager::CreateStatusTrayIcon() { |
} |
void BackgroundModeManager::UpdateStatusTrayIconContextMenu() { |
+ if (background_mode_suspended_) |
+ return; |
+ |
// If no status icon exists, it's either because one wasn't created when |
// it should have been which can happen when extensions load after the |
// profile has already been registered with the background mode manager. |