Chromium Code Reviews| Index: chrome/browser/background_mode_manager.h |
| =================================================================== |
| --- chrome/browser/background_mode_manager.h (revision 86440) |
| +++ chrome/browser/background_mode_manager.h (working copy) |
| @@ -6,6 +6,8 @@ |
| #define CHROME_BROWSER_BACKGROUND_MODE_MANAGER_H_ |
| #pragma once |
| +#include <map> |
| + |
| #include "base/gtest_prod_util.h" |
| #include "chrome/browser/background_application_list_model.h" |
| #include "chrome/browser/prefs/pref_change_registrar.h" |
| @@ -39,15 +41,16 @@ |
| // background. |
| class BackgroundModeManager |
| : public NotificationObserver, |
| - public ui::SimpleMenuModel::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; |
| @@ -59,25 +62,73 @@ |
| BackgroundAppInstallUninstallWhileDisabled); |
| FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, |
| EnableAfterBackgroundAppInstall); |
| + FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, |
| + MultiProfile); |
| + class BackgroundModeData : public ui::SimpleMenuModel::Delegate { |
| + public: |
| + explicit BackgroundModeData( |
| + Profile* profile, |
| + BackgroundModeManager* background_mode_manager); |
| + virtual ~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_; |
| + |
| + // The profile associated with this background app data. |
| + Profile* profile_; |
| + |
| + // The background mode manager which owns this BackgroundModeData |
| + BackgroundModeManager* background_mode_manager_; |
| + |
| + // 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) |
| + OVERRIDE; |
| + virtual void ExecuteCommand(int command_id) OVERRIDE; |
| + |
| + // 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(); |
| + |
| + // Open an application in a new tab, opening a new window if needed. |
| + virtual void ExecuteApplication(int application_id); |
| + |
| + // Updates the status icon's context menu entry corresponding to |
| + // |extension| to use the icon associated with |extension| in the |
| + // BackgroundApplicationListModel. |
| + // TODO(rlp): Remove after creating one status icon. |
| + void UpdateContextMenuEntryIcon(const Extension* extension); |
| + |
| + // Returns whether any of the extensions are background apps. |
| + bool HasBackgroundApp(); |
| + }; |
| + |
| + typedef linked_ptr<BackgroundModeData> BackgroundModeInfo; |
|
Andrew T Wilson (Slow)
2011/05/25 01:17:44
Add a comment about why we are using linked_ptr he
rpetterson
2011/05/25 19:57:12
Done.
|
| + |
| // 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; |
| - virtual bool GetAcceleratorForCommandId(int command_id, |
| - ui::Accelerator* accelerator); |
| - virtual void ExecuteCommand(int command_id); |
| - |
| - // Open an application in a new tab, opening a new window if needed. |
| - virtual void ExecuteApplication(int application_id); |
| - |
| // 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,11 +139,11 @@ |
| // 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. |
| - void OnBackgroundAppUninstalled(); |
| + void OnBackgroundAppUninstalled(Profile* profile); |
| // Called to make sure that our launch-on-startup mode is properly set. |
| // (virtual so we can override for tests). |
| @@ -100,12 +151,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,26 +178,26 @@ |
| // 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(); |
| + // Returns the BackgroundModeInfo associated with this profile. If it does |
| + // not exist, returns an empty BackgroundModeInfo. |
| + BackgroundModeManager::BackgroundModeInfo GetBackgroundModeInfo( |
|
Andrew T Wilson (Slow)
2011/05/25 01:17:44
The other thing I wanted to mention is that we pro
rpetterson
2011/05/25 19:57:12
I understand your point now. I'll include this in
|
| + Profile* profile); |
| // Returns true if the "Let chrome run in the background" pref is checked. |
| // (virtual to allow overriding in tests). |
| @@ -162,23 +218,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. |
| + 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 +239,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); |
| }; |