Chromium Code Reviews| Index: chrome/browser/background_mode_manager.h |
| =================================================================== |
| --- chrome/browser/background_mode_manager.h (revision 85413) |
| +++ 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; |
| @@ -23,6 +26,7 @@ |
| class StatusIcon; |
| class StatusTray; |
| + |
| // BackgroundModeManager is responsible for switching Chrome into and out of |
| // "background mode" and for providing UI for the user to exit Chrome when there |
| // are no open browser windows. |
| @@ -39,16 +43,21 @@ |
| // background. |
| class BackgroundModeManager |
| : public NotificationObserver, |
| - public ui::SimpleMenuModel::Delegate, |
| + public ProfileStatusMenuModel::Delegate, |
| public BackgroundApplicationListModel::Observer, |
| public ProfileKeyedService { |
| public: |
| - BackgroundModeManager(Profile* profile, CommandLine* command_line); |
| + BackgroundModeManager(); |
| virtual ~BackgroundModeManager(); |
| + static BackgroundModeManager* GetInstance(); |
| + |
| static void RegisterPrefs(PrefService* prefs); |
| + virtual void RegisterProfile(Profile* profile); |
| + |
| private: |
| + friend struct DefaultSingletonTraits<BackgroundModeManager>; |
| friend class TestBackgroundModeManager; |
| friend class BackgroundModeManagerTest; |
| FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, |
| @@ -60,24 +69,47 @@ |
| FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, |
| EnableAfterBackgroundAppInstall); |
| + struct BackgroundModeData { |
| + BackgroundModeData(); |
| + ~BackgroundModeData(); |
| + |
| + // The cached list of BackgroundApplications. |
| + BackgroundApplicationListModel* applications_; |
|
Andrew T Wilson (Slow)
2011/05/20 00:22:09
nit: struct member variables should not have trail
Andrew T Wilson (Slow)
2011/05/20 00:22:09
Should this be a scoped_ptr<> so you don't have to
rpetterson
2011/05/20 05:53:17
Not an issue any more.
rpetterson
2011/05/20 05:53:17
Done.
|
| + |
| + // 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_; |
| + }; |
| + |
| // 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 ProfileSatusMenuModel::Delegate implementation. |
|
Andrew T Wilson (Slow)
2011/05/20 00:22:09
nit: ProfileStatusMenuModel (not ProfileSatus)
rpetterson
2011/05/20 05:53:17
Done.
|
| + 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,7 +132,8 @@ |
| // 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. |
| @@ -122,26 +155,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(); |
| + Browser* GetBrowserWindow(Profile* profile); |
| // Returns true if the "Let chrome run in the background" pref is checked. |
| // (virtual to allow overriding in tests). |
| @@ -162,23 +195,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*, BackgroundModeData> background_mode_data_; |
| - // The cached list of BackgroundApplications. |
| - BackgroundApplicationListModel applications_; |
| + // Reference to our status tray (owned by our parent profile). If null, the |
|
Andrew T Wilson (Slow)
2011/05/20 00:22:09
Since we don't have a parent profile any more, thi
rpetterson
2011/05/20 05:53:17
Done.
|
| + // 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 +216,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); |
| }; |