Index: chrome/browser/background_mode_manager.h |
=================================================================== |
--- chrome/browser/background_mode_manager.h (revision 85937) |
+++ chrome/browser/background_mode_manager.h (working copy) |
@@ -6,14 +6,17 @@ |
#define CHROME_BROWSER_BACKGROUND_MODE_MANAGER_H_ |
#pragma once |
+#include <map> |
+ |
#include "base/gtest_prod_util.h" |
+#include "base/memory/singleton.h" |
#include "chrome/browser/background_application_list_model.h" |
#include "chrome/browser/prefs/pref_change_registrar.h" |
#include "chrome/browser/profiles/profile_keyed_service.h" |
+#include "chrome/browser/profiles/profile_status_menu_model.h" |
#include "chrome/browser/status_icons/status_icon.h" |
#include "content/common/notification_observer.h" |
#include "content/common/notification_registrar.h" |
-#include "ui/base/models/simple_menu_model.h" |
class Browser; |
class CommandLine; |
@@ -39,15 +42,17 @@ |
// background. |
class BackgroundModeManager |
: public NotificationObserver, |
- public ui::SimpleMenuModel::Delegate, |
+ public ProfileStatusMenuModel::Delegate, |
public BackgroundApplicationListModel::Observer, |
public ProfileKeyedService { |
public: |
- BackgroundModeManager(Profile* profile, CommandLine* command_line); |
+ explicit BackgroundModeManager(CommandLine* command_line); |
virtual ~BackgroundModeManager(); |
static void RegisterPrefs(PrefService* prefs); |
+ virtual void RegisterProfile(Profile* profile); |
+ |
private: |
friend class TestBackgroundModeManager; |
friend class BackgroundModeManagerTest; |
@@ -60,24 +65,51 @@ |
FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, |
EnableAfterBackgroundAppInstall); |
+ class BackgroundModeData { |
+ public: |
+ explicit BackgroundModeData(Profile* profile); |
+ ~BackgroundModeData(); |
+ |
+ // The cached list of BackgroundApplications. |
+ scoped_ptr<BackgroundApplicationListModel> applications_; |
+ |
+ // Reference to our status icon (if any) - owned by the StatusTray. |
+ StatusIcon* status_icon_; |
+ |
+ // Reference to our status icon's context menu (if any) - owned by the |
+ // status_icon_ |
+ ui::SimpleMenuModel* context_menu_; |
+ |
+ // Set to the position of the first application entry in the status icon's |
+ // context menu. |
+ int context_menu_application_offset_; |
+ }; |
+ |
+ typedef linked_ptr<BackgroundModeData> BackgroundModeInfo; |
+ |
// NotificationObserver implementation. |
virtual void Observe(NotificationType type, |
const NotificationSource& source, |
- const NotificationDetails& details); |
+ const NotificationDetails& details) OVERRIDE; |
- // SimpleMenuModel::Delegate implementation. |
- virtual bool IsCommandIdChecked(int command_id) const; |
- virtual bool IsCommandIdEnabled(int command_id) const; |
+ // Overrides from SimpleMenuModel::Delegate implementation. |
+ virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; |
+ virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; |
virtual bool GetAcceleratorForCommandId(int command_id, |
- ui::Accelerator* accelerator); |
- virtual void ExecuteCommand(int command_id); |
+ ui::Accelerator* accelerator) |
+ OVERRIDE; |
+ virtual void ExecuteCommand(int command_id) OVERRIDE; |
+ // Overrides from ProfileStatusMenuModel::Delegate implementation. |
+ virtual void ExecuteCommand(int command_id, Profile* profile) OVERRIDE; |
+ |
// Open an application in a new tab, opening a new window if needed. |
- virtual void ExecuteApplication(int application_id); |
+ virtual void ExecuteApplication(int application_id, Profile* profile); |
// BackgroundApplicationListModel::Observer implementation. |
- virtual void OnApplicationDataChanged(const Extension* extension); |
- virtual void OnApplicationListChanged(); |
+ virtual void OnApplicationDataChanged(const Extension* extension, |
+ Profile* profile) OVERRIDE; |
+ virtual void OnApplicationListChanged(Profile* profile) OVERRIDE; |
// Called when an extension is loaded to manage count of background apps. |
void OnBackgroundAppLoaded(); |
@@ -88,7 +120,7 @@ |
// Invoked when an extension is installed so we can ensure that |
// launch-on-startup is enabled if appropriate. |extension| can be NULL when |
// called from unit tests. |
- void OnBackgroundAppInstalled(const Extension* extension); |
+ void OnBackgroundAppInstalled(const Extension* extension, Profile* profile); |
// Invoked when an extension is uninstalled so we can ensure that |
// launch-on-startup is disabled if appropriate. |
@@ -100,12 +132,17 @@ |
// Invoked when a background app is installed so we can display a |
// platform-specific notification to the user. |
- void DisplayAppInstalledNotification(const Extension* extension); |
+ void DisplayAppInstalledNotification(const Extension* extension, |
+ Profile* profile); |
// Invoked to put Chrome in KeepAlive mode - chrome runs in the background |
// and has a status bar icon. |
void StartBackgroundMode(); |
+ // Invoked to create status icons for any profiles currently running |
+ // background apps so that there is a way to exit Chrome. |
+ void InitStatusTrayIcons(); |
+ |
// Invoked to take Chrome out of KeepAlive mode - chrome stops running in |
// the background and removes its status bar icon. |
void EndBackgroundMode(); |
@@ -122,27 +159,32 @@ |
// Create a status tray icon to allow the user to shutdown Chrome when running |
// in background mode. Virtual to enable testing. |
- virtual void CreateStatusTrayIcon(); |
+ virtual void CreateStatusTrayIcon(Profile* profile); |
// Removes the status tray icon because we are exiting background mode. |
// Virtual to enable testing. |
- virtual void RemoveStatusTrayIcon(); |
+ virtual void RemoveStatusTrayIcon(Profile* profile); |
// Updates the status icon's context menu entry corresponding to |extension| |
// to use the icon associated with |extension| in the |
// BackgroundApplicationListModel. |
- void UpdateContextMenuEntryIcon(const Extension* extension); |
+ void UpdateContextMenuEntryIcon(const Extension* extension, Profile* profile); |
// Create a context menu, or replace/update an existing context menu, for the |
// status tray icon which, among other things, allows the user to shutdown |
// Chrome when running in background mode. |
- virtual void UpdateStatusTrayIconContextMenu(); |
+ virtual void UpdateStatusTrayIconContextMenu(Profile* profile); |
// Returns a browser window, or creates one if none are open. Used by |
// operations (like displaying the preferences dialog) that require a Browser |
// window. |
- Browser* GetBrowserWindow(); |
+ Browser* GetBrowserWindow(Profile* profile); |
+ // Returns the BackgroundModeInfo associated with this profile. Does a |
+ // check to see if it exists. |
+ BackgroundModeManager::BackgroundModeInfo GetBackgroundModeInfo( |
Miranda Callahan
2011/05/20 15:16:53
nit: say in comment what happens if it doesn't exi
rpetterson
2011/05/23 03:23:19
Done.
|
+ Profile* profile); |
+ |
// Returns true if the "Let chrome run in the background" pref is checked. |
// (virtual to allow overriding in tests). |
virtual bool IsBackgroundModePrefEnabled(); |
@@ -162,23 +204,17 @@ |
NotificationRegistrar registrar_; |
PrefChangeRegistrar pref_registrar_; |
- // The parent profile for this object. |
- Profile* profile_; |
+ // The profile-keyed data for this background mode manager. Keyed on profile. |
+ std::map<Profile*, BackgroundModeInfo> background_mode_data_; |
- // The cached list of BackgroundApplications. |
- BackgroundApplicationListModel applications_; |
+ // Reference to our status tray. If null, the |
+ // platform doesn't support status icons. |
Miranda Callahan
2011/05/20 15:16:53
nit: line breaking is a bit too aggressive
rpetterson
2011/05/23 03:23:19
Done.
|
+ StatusTray* status_tray_; |
- // The number of background apps currently loaded. |
+ // The number of background apps currently loaded. This is the total over |
+ // all profiles. |
int background_app_count_; |
- // Reference to our status icon's context menu (if any) - owned by the |
- // status_icon_ |
- ui::SimpleMenuModel* context_menu_; |
- |
- // Set to the position of the first application entry in the status icon's |
- // context menu. |
- int context_menu_application_offset_; |
- |
// Set to true when we are running in background mode. Allows us to track our |
// current background state so we can take the appropriate action when the |
// user disables/enables background mode via preferences. |
@@ -189,13 +225,6 @@ |
// chrome would immediately exit due to having no open windows. |
bool keep_alive_for_startup_; |
- // Reference to our status tray (owned by our parent profile). If null, the |
- // platform doesn't support status icons. |
- StatusTray* status_tray_; |
- |
- // Reference to our status icon (if any) - owned by the StatusTray. |
- StatusIcon* status_icon_; |
- |
DISALLOW_COPY_AND_ASSIGN(BackgroundModeManager); |
}; |