diff options
author | rlp@chromium.org <rlp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-25 22:26:28 +0000 |
---|---|---|
committer | rlp@chromium.org <rlp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-25 22:26:28 +0000 |
commit | df3d71d622f8c0c2b716872705358d3f3c928ffb (patch) | |
tree | 2a0fc0a16f0d2506107b2bf29c1db7d464c33ce8 | |
parent | 5ecfbdd7b3f61d372536bd68cc9a372beeec9dfb (diff) | |
download | chromium_src-df3d71d622f8c0c2b716872705358d3f3c928ffb.zip chromium_src-df3d71d622f8c0c2b716872705358d3f3c928ffb.tar.gz chromium_src-df3d71d622f8c0c2b716872705358d3f3c928ffb.tar.bz2 |
Modifying the BackgroundModeManager to handle multiple profiles.
The background mode manager is now owned by the broser
The status tray is also owned by the browser process since there is only one per browser. Previously it was owned by the profile, but now that there are multiple profiles, it makes sense to have the browser process own it.
Note: This CL does not unify the status tray into one icon.
TEST=unittests (added BackgroundModeManagerTest::MultiProfile)
BUG=80069,82215
Review URL: http://codereview.chromium.org/6914021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86724 0039d316-1c4b-4281-b951-d872f2087c98
20 files changed, 506 insertions, 261 deletions
diff --git a/chrome/browser/background_application_list_model.cc b/chrome/browser/background_application_list_model.cc index eac372c..df6d6a0 100644 --- a/chrome/browser/background_application_list_model.cc +++ b/chrome/browser/background_application_list_model.cc @@ -96,11 +96,12 @@ bool HasBackgroundAppPermission( void BackgroundApplicationListModel::Observer::OnApplicationDataChanged( - const Extension* extension) { + const Extension* extension, Profile* profile) { } void -BackgroundApplicationListModel::Observer::OnApplicationListChanged() { +BackgroundApplicationListModel::Observer::OnApplicationListChanged( + Profile* profile) { } BackgroundApplicationListModel::Observer::~Observer() { @@ -125,7 +126,7 @@ void BackgroundApplicationListModel::Application::OnImageLoaded( if (!image) return; icon_.reset(new SkBitmap(*image)); - model_->OnApplicationDataChanged(extension_); + model_->SendApplicationDataChangedNotifications(extension_); } void BackgroundApplicationListModel::Application::RequestIcon( @@ -263,9 +264,10 @@ void BackgroundApplicationListModel::Observe( } } -void BackgroundApplicationListModel::OnApplicationDataChanged( +void BackgroundApplicationListModel::SendApplicationDataChangedNotifications( const Extension* extension) { - FOR_EACH_OBSERVER(Observer, observers_, OnApplicationDataChanged(extension)); + FOR_EACH_OBSERVER(Observer, observers_, OnApplicationDataChanged(extension, + profile_)); } void BackgroundApplicationListModel::OnExtensionLoaded(Extension* extension) { @@ -310,6 +312,6 @@ void BackgroundApplicationListModel::Update() { } if (old_cursor != extensions_.end() || new_cursor != extensions.end()) { extensions_ = extensions; - FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged()); + FOR_EACH_OBSERVER(Observer, observers_, OnApplicationListChanged(profile_)); } } diff --git a/chrome/browser/background_application_list_model.h b/chrome/browser/background_application_list_model.h index ba23aef..02aea2f 100644 --- a/chrome/browser/background_application_list_model.h +++ b/chrome/browser/background_application_list_model.h @@ -32,11 +32,12 @@ class BackgroundApplicationListModel : public NotificationObserver { public: // Invoked when data that the model associates with the extension, such as // the Icon, has changed. - virtual void OnApplicationDataChanged(const Extension* extension); + virtual void OnApplicationDataChanged(const Extension* extension, + Profile* profile); // Invoked when the model detects a previously unknown extension and/or when // it no longer detects a previously known extension. - virtual void OnApplicationListChanged(); + virtual void OnApplicationListChanged(Profile* profile); protected: virtual ~Observer(); @@ -110,11 +111,11 @@ class BackgroundApplicationListModel : public NotificationObserver { // Notifies observers that some of the data associated with this background // application, e. g. the Icon, has changed. - void OnApplicationDataChanged(const Extension* extension); + void SendApplicationDataChangedNotifications(const Extension* extension); // Notifies observers that at least one background application has been added // or removed. - void OnApplicationListChanged(); + void SendApplicationListChangedNotifications(); // Invoked by Observe for EXTENSION_LOADED notifications. void OnExtensionLoaded(Extension* extension); diff --git a/chrome/browser/background_mode_manager.cc b/chrome/browser/background_mode_manager.cc index 63150e0..346e787 100644 --- a/chrome/browser/background_mode_manager.cc +++ b/chrome/browser/background_mode_manager.cc @@ -29,26 +29,114 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" -void BackgroundModeManager::OnApplicationDataChanged( + +BackgroundModeManager::BackgroundModeData::BackgroundModeData( + Profile* profile, + BackgroundModeManager* background_mode_manager) + : applications_(new BackgroundApplicationListModel(profile)), + status_icon_(NULL), + context_menu_(NULL), + context_menu_application_offset_(0), + profile_(profile), + background_mode_manager_(background_mode_manager) { +} + +BackgroundModeManager::BackgroundModeData::~BackgroundModeData() { +} + +/////////////////////////////////////////////////////////////////////////////// +// BackgroundModeManager::BackgroundModeData, ui::SimpleMenuModel overrides +bool BackgroundModeManager::BackgroundModeData::IsCommandIdChecked( + int command_id) const { + DCHECK(command_id == IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND); + return true; +} + +bool BackgroundModeManager::BackgroundModeData::IsCommandIdEnabled( + int command_id) const { + // For now, we do not support disabled items. + return true; +} + +bool BackgroundModeManager::BackgroundModeData::GetAcceleratorForCommandId( + int command_id, ui::Accelerator* accelerator) { + // No accelerators for status icon context menus. + return false; +} + +void BackgroundModeManager::BackgroundModeData::ExecuteCommand(int item) { + switch (item) { + case IDC_ABOUT: + GetBrowserWindow()->OpenAboutChromeDialog(); + break; + case IDC_EXIT: + UserMetrics::RecordAction(UserMetricsAction("Exit")); + BrowserList::CloseAllBrowsersAndExit(); + break; + case IDC_OPTIONS: + GetBrowserWindow()->OpenOptionsDialog(); + break; + case IDC_TASK_MANAGER: + GetBrowserWindow()->OpenTaskManager(true); + break; + case IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND: { + // Background mode must already be enabled (as otherwise this menu would + // not be visible). + DCHECK(background_mode_manager_->IsBackgroundModePrefEnabled()); + DCHECK(BrowserList::WillKeepAlive()); + + // Set the background mode pref to "disabled" - the resulting notification + // will result in a call to DisableBackgroundMode(). + PrefService* service = g_browser_process->local_state(); + DCHECK(service); + service->SetBoolean(prefs::kBackgroundModeEnabled, false); + break; + } + default: + ExecuteApplication(item); + break; + } +} + +void BackgroundModeManager::BackgroundModeData::ExecuteApplication( + int item) { + Browser* browser = GetBrowserWindow(); + const Extension* extension = applications_->GetExtension(item); + browser->OpenApplicationTab(profile_, extension, NEW_FOREGROUND_TAB); +} + +Browser* BackgroundModeManager::BackgroundModeData::GetBrowserWindow() { + Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); + if (!browser) { + Browser::OpenEmptyWindow(profile_); + browser = BrowserList::GetLastActiveWithProfile(profile_); + } + return browser; +} + +void BackgroundModeManager::BackgroundModeData::UpdateContextMenuEntryIcon( const Extension* extension) { - UpdateContextMenuEntryIcon(extension); + if (!context_menu_) + return; + context_menu_->SetIcon( + context_menu_application_offset_ + + applications_->GetPosition(extension), + *(applications_->GetIcon(extension))); + + status_icon_->SetContextMenu(context_menu_); // for Update effect } -void BackgroundModeManager::OnApplicationListChanged() { - UpdateStatusTrayIconContextMenu(); +bool BackgroundModeManager::BackgroundModeData::HasBackgroundApp() { + return (applications_->size() > 0); } -BackgroundModeManager::BackgroundModeManager(Profile* profile, - CommandLine* command_line) - : profile_(profile), - applications_(profile), +/////////////////////////////////////////////////////////////////////////////// +// BackgroundModeManager, public +BackgroundModeManager::BackgroundModeManager(CommandLine* command_line) + : status_tray_(NULL), background_app_count_(0), - context_menu_(NULL), - context_menu_application_offset_(0), in_background_mode_(false), - keep_alive_for_startup_(false), - status_tray_(NULL), - status_icon_(NULL) { + keep_alive_for_startup_(false) { // If background mode is currently disabled, just exit - don't listen for any // notifications. if (IsBackgroundModePermanentlyDisabled(command_line)) @@ -72,9 +160,43 @@ BackgroundModeManager::BackgroundModeManager(Profile* profile, // If the -keep-alive-for-test flag is passed, then always keep chrome running // in the background until the user explicitly terminates it, by acting as if // we loaded a background app. - if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKeepAliveForTest)) + if (command_line->HasSwitch(switches::kKeepAliveForTest)) OnBackgroundAppLoaded(); + // Listen for the application shutting down so we can decrement our KeepAlive + // count. + registrar_.Add(this, NotificationType::APP_TERMINATING, + NotificationService::AllSources()); +} + +BackgroundModeManager::~BackgroundModeManager() { + for (std::map<Profile*, BackgroundModeInfo>::iterator it = + background_mode_data_.begin(); + it != background_mode_data_.end(); + ++it) { + it->second->applications_->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, + // because in an actual running system we'd get an APP_TERMINATING + // notification before being destroyed. + EndBackgroundMode(); +} + +// static +void BackgroundModeManager::RegisterPrefs(PrefService* prefs) { + prefs->RegisterBooleanPref(prefs::kUserCreatedLoginItem, false); + prefs->RegisterBooleanPref(prefs::kBackgroundModeEnabled, true); +} + + +void BackgroundModeManager::RegisterProfile(Profile* profile) { + // We don't want to register multiple times for one profile. + DCHECK(background_mode_data_.find(profile) == background_mode_data_.end()); + BackgroundModeInfo bmd(new BackgroundModeData(profile, this)); + background_mode_data_[profile] = bmd; + // Listen for when extensions are loaded/unloaded so we can track the // number of background apps and modify our keep-alive and launch-on-startup // state appropriately. @@ -89,24 +211,11 @@ BackgroundModeManager::BackgroundModeManager(Profile* profile, registrar_.Add(this, NotificationType::EXTENSIONS_READY, Source<Profile>(profile)); - // Listen for the application shutting down so we can decrement our KeepAlive - // count. - registrar_.Add(this, NotificationType::APP_TERMINATING, - NotificationService::AllSources()); - - applications_.AddObserver(this); -} - -BackgroundModeManager::~BackgroundModeManager() { - applications_.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, - // because in an actual running system we'd get an APP_TERMINATING - // notification before being destroyed. - EndBackgroundMode(); + background_mode_data_[profile]->applications_->AddObserver(this); } +/////////////////////////////////////////////////////////////////////////////// +// BackgroundModeManager, NotificationObserver overrides void BackgroundModeManager::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { @@ -139,8 +248,9 @@ void BackgroundModeManager::Observe(NotificationType type, if (BackgroundApplicationListModel::IsBackgroundApp(*extension)) { // Extensions loaded after the ExtensionsService is ready should be // treated as new installs. - if (profile_->GetExtensionService()->is_ready()) - OnBackgroundAppInstalled(extension); + Profile* profile = Source<Profile>(source).ptr(); + if (profile->GetExtensionService()->is_ready()) + OnBackgroundAppInstalled(extension, profile); OnBackgroundAppLoaded(); } } @@ -157,7 +267,8 @@ void BackgroundModeManager::Observe(NotificationType type, if (info->already_disabled) return; OnBackgroundAppUnloaded(); - OnBackgroundAppUninstalled(); + Profile* profile = Source<Profile>(source).ptr(); + OnBackgroundAppUninstalled(profile); } break; case NotificationType::APP_TERMINATING: @@ -177,6 +288,20 @@ void BackgroundModeManager::Observe(NotificationType type, } } +/////////////////////////////////////////////////////////////////////////////// +// BackgroundModeManager, BackgroundApplicationListModel::Observer overrides +void BackgroundModeManager::OnApplicationDataChanged( + const Extension* extension, Profile* profile) { + UpdateContextMenuEntryIcon(extension, profile); +} + +void BackgroundModeManager::OnApplicationListChanged(Profile* profile) { + UpdateStatusTrayIconContextMenu(profile); +} + + +/////////////////////////////////////////////////////////////////////////////// +// BackgroundModeManager, private void BackgroundModeManager::EndKeepAliveForStartup() { if (keep_alive_for_startup_) { keep_alive_for_startup_ = false; @@ -191,6 +316,8 @@ void BackgroundModeManager::EndKeepAliveForStartup() { void BackgroundModeManager::OnBackgroundAppLoaded() { // When a background app loads, increment our count and also enable // KeepAlive mode if the preference is set. + // The count here is across all profiles since we must have background + // mode if there is even one. background_app_count_++; if (background_app_count_ == 1) StartBackgroundMode(); @@ -209,7 +336,19 @@ void BackgroundModeManager::StartBackgroundMode() { BrowserList::StartKeepAlive(); // Display a status icon to exit Chrome. - CreateStatusTrayIcon(); + InitStatusTrayIcons(); +} + +void BackgroundModeManager::InitStatusTrayIcons() { + // Only initialize status tray icons for those profiles which actually + // have a background app running. + for (std::map<Profile*, BackgroundModeInfo>::iterator it = + background_mode_data_.begin(); + it != background_mode_data_.end(); + ++it) { + if (it->second->HasBackgroundApp()) + CreateStatusTrayIcon(it->first); + } } void BackgroundModeManager::OnBackgroundAppUnloaded() { @@ -228,7 +367,13 @@ void BackgroundModeManager::EndBackgroundMode() { // End KeepAlive mode and blow away our status tray icon. BrowserList::EndKeepAlive(); - RemoveStatusTrayIcon(); + // There is a status tray icon for each profile. Blow them all away. + for (std::map<Profile*, BackgroundModeInfo>::iterator it = + background_mode_data_.begin(); + it != background_mode_data_.end(); + ++it) { + RemoveStatusTrayIcon(it->first); + } } void BackgroundModeManager::EnableBackgroundMode() { @@ -250,7 +395,7 @@ void BackgroundModeManager::DisableBackgroundMode() { } void BackgroundModeManager::OnBackgroundAppInstalled( - const Extension* extension) { + const Extension* extension, Profile* profile) { // Background mode is disabled - don't do anything. if (!IsBackgroundModePrefEnabled()) return; @@ -260,58 +405,84 @@ void BackgroundModeManager::OnBackgroundAppInstalled( if (background_app_count_ == 0) EnableLaunchOnStartup(true); + // Check if we need a status tray icon and make one if we do. + CreateStatusTrayIcon(profile); + // Notify the user that a background app has been installed. if (extension) // NULL when called by unit tests. - DisplayAppInstalledNotification(extension); + DisplayAppInstalledNotification(extension, profile); } -void BackgroundModeManager::OnBackgroundAppUninstalled() { +void BackgroundModeManager::OnBackgroundAppUninstalled(Profile* profile) { + // Check if we need to remove the status tray icon if there are no + // more background apps. + BackgroundModeInfo bmd = GetBackgroundModeInfo(profile); + DCHECK(bmd.get()); + // If there are still background apps for this profile, don't remove + // the status tray icon. + if (!bmd->HasBackgroundApp()) + RemoveStatusTrayIcon(profile); + // When uninstalling a background app, disable launch on startup if // we have no more background apps. if (background_app_count_ == 0) EnableLaunchOnStartup(false); } -void BackgroundModeManager::CreateStatusTrayIcon() { +void BackgroundModeManager::CreateStatusTrayIcon(Profile* profile) { // Only need status icons on windows/linux. ChromeOS doesn't allow exiting // Chrome and Mac can use the dock icon instead. + + // Since there are multiple profiles which share the status tray, we now + // use the browser process to keep track of it. #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) if (!status_tray_) - status_tray_ = profile_->GetStatusTray(); + status_tray_ = g_browser_process->status_tray(); #endif // If the platform doesn't support status icons, or we've already created // our status icon, just return. - if (!status_tray_ || status_icon_) + BackgroundModeInfo bmd = GetBackgroundModeInfo(profile); + if (!status_tray_ || bmd->status_icon_) return; - status_icon_ = status_tray_->CreateStatusIcon(); - if (!status_icon_) + + bmd->status_icon_ = status_tray_->CreateStatusIcon(); + if (!bmd->status_icon_) return; - // Set the image and add ourselves as a click observer on it + // Set the image and add ourselves as a click observer on it. + // TODO(rlp): Status tray icon should have submenus for each profile. SkBitmap* bitmap = ResourceBundle::GetSharedInstance().GetBitmapNamed( IDR_STATUS_TRAY_ICON); - status_icon_->SetImage(*bitmap); - status_icon_->SetToolTip(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); - UpdateStatusTrayIconContextMenu(); + bmd->status_icon_->SetImage(*bitmap); + bmd->status_icon_->SetToolTip(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); + UpdateStatusTrayIconContextMenu(profile); } void BackgroundModeManager::UpdateContextMenuEntryIcon( - const Extension* extension) { - if (!context_menu_) - return; - context_menu_->SetIcon( - context_menu_application_offset_ + applications_.GetPosition(extension), - *(applications_.GetIcon(extension))); - status_icon_->SetContextMenu(context_menu_); // for Update effect + const Extension* extension, Profile* profile) { + BackgroundModeInfo bmd = GetBackgroundModeInfo(profile); + DCHECK(bmd.get()); + bmd->UpdateContextMenuEntryIcon(extension); } -void BackgroundModeManager::UpdateStatusTrayIconContextMenu() { - if (!status_icon_) - return; +void BackgroundModeManager::UpdateStatusTrayIconContextMenu(Profile* profile) { + BackgroundModeInfo bmd = GetBackgroundModeInfo(profile); + DCHECK(bmd.get()); + if (!bmd->status_icon_) { + // 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. + // The other case is if we aren't in background mode. + if (in_background_mode_) + CreateStatusTrayIcon(profile); + else + return; + } + // TODO(rlp): Add current profile color. // Create a context menu item for Chrome. - ui::SimpleMenuModel* menu = new ui::SimpleMenuModel(this); + ui::SimpleMenuModel* menu = new ui::SimpleMenuModel(bmd.get()); // Add About item menu->AddItem(IDC_ABOUT, l10n_util::GetStringFUTF16(IDS_ABOUT, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); @@ -319,103 +490,41 @@ void BackgroundModeManager::UpdateStatusTrayIconContextMenu() { menu->AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER); menu->AddSeparator(); int position = 0; - context_menu_application_offset_ = menu->GetItemCount(); - for (ExtensionList::const_iterator cursor = applications_.begin(); - cursor != applications_.end(); + bmd->context_menu_application_offset_ = menu->GetItemCount(); + for (ExtensionList::const_iterator cursor = bmd->applications_->begin(); + cursor != bmd->applications_->end(); ++cursor, ++position) { - const SkBitmap* icon = applications_.GetIcon(*cursor); - DCHECK(position == applications_.GetPosition(*cursor)); + const SkBitmap* icon = bmd->applications_->GetIcon(*cursor); + DCHECK(position == bmd->applications_->GetPosition(*cursor)); const std::string& name = (*cursor)->name(); menu->AddItem(position, UTF8ToUTF16(name)); if (icon) menu->SetIcon(menu->GetItemCount() - 1, *icon); } - if (applications_.size() > 0) + if (bmd->applications_->size() > 0) menu->AddSeparator(); menu->AddCheckItemWithStringId( IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND, IDS_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND); menu->AddItemWithStringId(IDC_EXIT, IDS_EXIT); - context_menu_ = menu; - status_icon_->SetContextMenu(menu); -} - -bool BackgroundModeManager::IsCommandIdChecked(int command_id) const { - DCHECK(command_id == IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND); - return true; -} - -bool BackgroundModeManager::IsCommandIdEnabled(int command_id) const { - // For now, we do not support disabled items. - return true; -} - -bool BackgroundModeManager::GetAcceleratorForCommandId( - int command_id, - ui::Accelerator* accelerator) { - // No accelerators for status icon context menus. - return false; -} - -void BackgroundModeManager::RemoveStatusTrayIcon() { - if (status_icon_) - status_tray_->RemoveStatusIcon(status_icon_); - status_icon_ = NULL; - context_menu_ = NULL; // Do not delete, points within |status_icon_|. + bmd->context_menu_ = menu; + bmd->status_icon_->SetContextMenu(menu); } -void BackgroundModeManager::ExecuteApplication(int item) { - DCHECK(item >= 0 && item < static_cast<int>(applications_.size())); - Browser* browser = BrowserList::GetLastActive(); - if (!browser) { - Browser::OpenEmptyWindow(profile_); - browser = BrowserList::GetLastActive(); - } - const Extension* extension = applications_.GetExtension(item); - browser->OpenApplicationTab(profile_, extension, NEW_FOREGROUND_TAB); -} +void BackgroundModeManager::RemoveStatusTrayIcon(Profile* profile) { + BackgroundModeInfo bmd = GetBackgroundModeInfo(profile); + DCHECK(bmd.get()); -void BackgroundModeManager::ExecuteCommand(int item) { - switch (item) { - case IDC_ABOUT: - GetBrowserWindow()->OpenAboutChromeDialog(); - break; - case IDC_EXIT: - UserMetrics::RecordAction(UserMetricsAction("Exit")); - BrowserList::CloseAllBrowsersAndExit(); - break; - case IDC_OPTIONS: - GetBrowserWindow()->OpenOptionsDialog(); - break; - case IDC_TASK_MANAGER: - GetBrowserWindow()->OpenTaskManager(true); - break; - case IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND: { - // Background mode must already be enabled (as otherwise this menu would - // not be visible). - DCHECK(IsBackgroundModePrefEnabled()); - DCHECK(BrowserList::WillKeepAlive()); - - // Set the background mode pref to "disabled" - the resulting notification - // will result in a call to DisableBackgroundMode(). - PrefService* service = g_browser_process->local_state(); - DCHECK(service); - service->SetBoolean(prefs::kBackgroundModeEnabled, false); - break; - } - default: - ExecuteApplication(item); - break; - } + if (bmd->status_icon_) + status_tray_->RemoveStatusIcon(bmd->status_icon_); + bmd->status_icon_ = NULL; + bmd->context_menu_ = NULL; // Do not delete, points within |status_icon_|. } -Browser* BackgroundModeManager::GetBrowserWindow() { - Browser* browser = BrowserList::GetLastActive(); - if (!browser) { - Browser::OpenEmptyWindow(profile_); - browser = BrowserList::GetLastActive(); - } - return browser; +BackgroundModeManager::BackgroundModeInfo +BackgroundModeManager::GetBackgroundModeInfo(Profile* profile) { + DCHECK(background_mode_data_.find(profile) != background_mode_data_.end()); + return background_mode_data_[profile]; } // static @@ -440,10 +549,4 @@ bool BackgroundModeManager::IsBackgroundModePrefEnabled() { PrefService* service = g_browser_process->local_state(); DCHECK(service); return service->GetBoolean(prefs::kBackgroundModeEnabled); -} - -// static -void BackgroundModeManager::RegisterPrefs(PrefService* prefs) { - prefs->RegisterBooleanPref(prefs::kUserCreatedLoginItem, false); - prefs->RegisterBooleanPref(prefs::kBackgroundModeEnabled, true); -} +}
\ No newline at end of file diff --git a/chrome/browser/background_mode_manager.h b/chrome/browser/background_mode_manager.h index 4ef8d81..87e0490 100644 --- a/chrome/browser/background_mode_manager.h +++ b/chrome/browser/background_mode_manager.h @@ -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 @@ class StatusTray; // 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,80 @@ class BackgroundModeManager 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(); + }; + + // Ideally we would want our BackgroundModeData to be scoped_ptrs, + // but since maps copy their entries, we can't used scoped_ptrs. + // Similarly, we can't just have a map of BackgroundModeData objects, + // since BackgroundModeData contains a scoped_ptr which once again + // can't be copied. So rather than using BackgroundModeData* which + // we'd have to remember to delete, we use the ref-counted linked_ptr + // which is similar to a shared_ptr. + typedef linked_ptr<BackgroundModeData> BackgroundModeInfo; // NotificationObserver implementation. virtual void Observe(NotificationType type, const NotificationSource& source, - const NotificationDetails& details); - - // 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); + const NotificationDetails& details) OVERRIDE; // 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 +146,11 @@ class BackgroundModeManager // 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 +158,17 @@ class BackgroundModeManager // 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 +185,26 @@ class BackgroundModeManager // 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( + Profile* profile); // Returns true if the "Let chrome run in the background" pref is checked. // (virtual to allow overriding in tests). @@ -162,23 +225,17 @@ class BackgroundModeManager 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 +246,6 @@ class BackgroundModeManager // 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); }; diff --git a/chrome/browser/background_mode_manager_linux.cc b/chrome/browser/background_mode_manager_linux.cc index b172633..33f42ba 100644 --- a/chrome/browser/background_mode_manager_linux.cc +++ b/chrome/browser/background_mode_manager_linux.cc @@ -79,7 +79,8 @@ void EnableLaunchOnStartupTask::Run() { } void BackgroundModeManager::DisplayAppInstalledNotification( - const Extension* extension) { + const Extension* extension, + Profile* profile) { // TODO(atwilson): Display a platform-appropriate notification here. // http://crbug.com/74970 } diff --git a/chrome/browser/background_mode_manager_mac.mm b/chrome/browser/background_mode_manager_mac.mm index f7fad87..4bbae6a 100644 --- a/chrome/browser/background_mode_manager_mac.mm +++ b/chrome/browser/background_mode_manager_mac.mm @@ -86,7 +86,8 @@ void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) { } void BackgroundModeManager::DisplayAppInstalledNotification( - const Extension* extension) { + const Extension* extension, + Profile* profile) { // TODO(atwilson): Display a platform-appropriate notification here. // http://crbug.com/74970 } diff --git a/chrome/browser/background_mode_manager_unittest.cc b/chrome/browser/background_mode_manager_unittest.cc index dc19e2a..a1607cc 100644 --- a/chrome/browser/background_mode_manager_unittest.cc +++ b/chrome/browser/background_mode_manager_unittest.cc @@ -13,6 +13,7 @@ #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" +using testing::_; using testing::AtLeast; using testing::InSequence; using testing::Return; @@ -29,12 +30,12 @@ class BackgroundModeManagerTest : public TestingBrowserProcessTest { class TestBackgroundModeManager : public BackgroundModeManager { public: - TestBackgroundModeManager(Profile* profile, CommandLine* cl) - : BackgroundModeManager(profile, cl), + explicit TestBackgroundModeManager(CommandLine* command_line) + : BackgroundModeManager(command_line), enabled_(true) {} MOCK_METHOD1(EnableLaunchOnStartup, void(bool)); - MOCK_METHOD0(CreateStatusTrayIcon, void()); - MOCK_METHOD0(RemoveStatusTrayIcon, void()); + MOCK_METHOD1(CreateStatusTrayIcon, void(Profile*)); // NOLINT + MOCK_METHOD1(RemoveStatusTrayIcon, void(Profile*)); // NOLINT virtual bool IsBackgroundModePrefEnabled() { return enabled_; } void SetEnabled(bool enabled) { enabled_ = enabled; } private: @@ -44,12 +45,14 @@ class TestBackgroundModeManager : public BackgroundModeManager { TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { InSequence s; TestingProfile profile; - TestBackgroundModeManager manager(&profile, command_line_.get()); - EXPECT_CALL(manager, CreateStatusTrayIcon()); - EXPECT_CALL(manager, RemoveStatusTrayIcon()); + TestBackgroundModeManager manager(command_line_.get()); + manager.RegisterProfile(&profile); + EXPECT_CALL(manager, RemoveStatusTrayIcon(_)); EXPECT_FALSE(BrowserList::WillKeepAlive()); - // Call to AppLoaded() will cause the status tray to be created, then call to - // unloaded will result in call to remove the icon. + // Call to AppLoaded() will not cause the status tray to be created, + // because no apps have been installed. However the call to AppUnloaded() + // will result in a call RemoveStatusTrayIcon since it will try to unload + // all icons now that there are no apps. manager.OnBackgroundAppLoaded(); EXPECT_TRUE(BrowserList::WillKeepAlive()); manager.OnBackgroundAppUnloaded(); @@ -59,35 +62,37 @@ TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstall) { InSequence s; TestingProfile profile; - TestBackgroundModeManager manager(&profile, command_line_.get()); + TestBackgroundModeManager manager(command_line_.get()); + manager.RegisterProfile(&profile); // Call to AppInstalled() will cause chrome to be set to launch on startup, // and call to AppUninstalled() set chrome to not launch on startup. EXPECT_CALL(manager, EnableLaunchOnStartup(true)); - EXPECT_CALL(manager, CreateStatusTrayIcon()); - EXPECT_CALL(manager, RemoveStatusTrayIcon()); + EXPECT_CALL(manager, CreateStatusTrayIcon(_)); + EXPECT_CALL(manager, RemoveStatusTrayIcon(_)).Times(2); EXPECT_CALL(manager, EnableLaunchOnStartup(false)); - manager.OnBackgroundAppInstalled(NULL); + manager.OnBackgroundAppInstalled(NULL, &profile); manager.OnBackgroundAppLoaded(); manager.OnBackgroundAppUnloaded(); - manager.OnBackgroundAppUninstalled(); -} + manager.OnBackgroundAppUninstalled(&profile);} // App installs while disabled should do nothing. TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstallWhileDisabled) { InSequence s; TestingProfile profile; - TestBackgroundModeManager manager(&profile, command_line_.get()); + TestBackgroundModeManager manager(command_line_.get()); + manager.RegisterProfile(&profile); // Turn off background mode. + EXPECT_CALL(manager, RemoveStatusTrayIcon(_)); manager.SetEnabled(false); manager.DisableBackgroundMode(); // Status tray icons will not be created, launch on startup status will be set // to "do not launch on startup". EXPECT_CALL(manager, EnableLaunchOnStartup(false)); - manager.OnBackgroundAppInstalled(NULL); + manager.OnBackgroundAppInstalled(NULL, &profile); manager.OnBackgroundAppLoaded(); manager.OnBackgroundAppUnloaded(); - manager.OnBackgroundAppUninstalled(); + manager.OnBackgroundAppUninstalled(&profile); // Re-enable background mode. manager.SetEnabled(true); @@ -99,29 +104,77 @@ TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstallWhileDisabled) { TEST_F(BackgroundModeManagerTest, EnableAfterBackgroundAppInstall) { InSequence s; TestingProfile profile; - TestBackgroundModeManager manager(&profile, command_line_.get()); + TestBackgroundModeManager manager(command_line_.get()); + manager.RegisterProfile(&profile); EXPECT_CALL(manager, EnableLaunchOnStartup(true)); - EXPECT_CALL(manager, CreateStatusTrayIcon()); - EXPECT_CALL(manager, RemoveStatusTrayIcon()); + EXPECT_CALL(manager, CreateStatusTrayIcon(_)); + EXPECT_CALL(manager, RemoveStatusTrayIcon(_)); EXPECT_CALL(manager, EnableLaunchOnStartup(false)); - EXPECT_CALL(manager, CreateStatusTrayIcon()); EXPECT_CALL(manager, EnableLaunchOnStartup(true)); - EXPECT_CALL(manager, RemoveStatusTrayIcon()); + EXPECT_CALL(manager, RemoveStatusTrayIcon(_)).Times(2); EXPECT_CALL(manager, EnableLaunchOnStartup(false)); // Install app, should show status tray icon. - manager.OnBackgroundAppInstalled(NULL); + manager.OnBackgroundAppInstalled(NULL, &profile); + // OnBackgroundAppInstalled does not actually add an app to the + // BackgroundApplicationListModel which would result in another + // call to CreateStatusTray. manager.OnBackgroundAppLoaded(); // Turn off background mode - should hide status tray icon. manager.SetEnabled(false); manager.DisableBackgroundMode(); - // Turn back on background mode - should show status tray icon. + // Turn back on background mode - again, no status tray icon + // will show up since we didn't actually add anything to the list. manager.SetEnabled(true); manager.EnableBackgroundMode(); // Uninstall app, should hide status tray icon again. manager.OnBackgroundAppUnloaded(); - manager.OnBackgroundAppUninstalled(); + manager.OnBackgroundAppUninstalled(&profile); +} + +TEST_F(BackgroundModeManagerTest, MultiProfile) { + InSequence s; + TestingProfile profile1; + TestingProfile profile2; + TestBackgroundModeManager manager(command_line_.get()); + manager.RegisterProfile(&profile1); + manager.RegisterProfile(&profile2); + EXPECT_CALL(manager, EnableLaunchOnStartup(true)); + EXPECT_CALL(manager, CreateStatusTrayIcon(_)).Times(2); + EXPECT_CALL(manager, RemoveStatusTrayIcon(_)).Times(2); + EXPECT_CALL(manager, EnableLaunchOnStartup(false)); + EXPECT_CALL(manager, EnableLaunchOnStartup(true)); + EXPECT_CALL(manager, RemoveStatusTrayIcon(_)).Times(4); + EXPECT_CALL(manager, EnableLaunchOnStartup(false)); + EXPECT_FALSE(BrowserList::WillKeepAlive()); + + // Install app, should show status tray icon. + manager.OnBackgroundAppInstalled(NULL, &profile1); + // OnBackgroundAppInstalled does not actually add an app to the + // BackgroundApplicationListModel which would result in another + // call to CreateStatusTray. + manager.OnBackgroundAppLoaded(); + + // Install app for other profile, hsould show other status tray icon. + manager.OnBackgroundAppInstalled(NULL, &profile2); + manager.OnBackgroundAppLoaded(); + + // Should hide both status tray icons. + manager.SetEnabled(false); + manager.DisableBackgroundMode(); + + // Turn back on background mode - should show both status tray icons. + manager.SetEnabled(true); + manager.EnableBackgroundMode(); + + manager.OnBackgroundAppUnloaded(); + manager.OnBackgroundAppUninstalled(&profile1); + // There is still one background app alive + EXPECT_TRUE(BrowserList::WillKeepAlive()); + manager.OnBackgroundAppUnloaded(); + manager.OnBackgroundAppUninstalled(&profile2); + EXPECT_FALSE(BrowserList::WillKeepAlive()); } diff --git a/chrome/browser/background_mode_manager_win.cc b/chrome/browser/background_mode_manager_win.cc index 9be2219..7dab7d8 100644 --- a/chrome/browser/background_mode_manager_win.cc +++ b/chrome/browser/background_mode_manager_win.cc @@ -88,11 +88,12 @@ void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) { } void BackgroundModeManager::DisplayAppInstalledNotification( - const Extension* extension) { + const Extension* extension, + Profile* profile) { // Create a status tray notification balloon explaining to the user that // a background app has been installed. - CreateStatusTrayIcon(); - status_icon_->DisplayBalloon( + CreateStatusTrayIcon(profile); + background_mode_data_[profile]->status_icon_->DisplayBalloon( l10n_util::GetStringUTF16(IDS_BACKGROUND_APP_INSTALLED_BALLOON_TITLE), l10n_util::GetStringFUTF16( IDS_BACKGROUND_APP_INSTALLED_BALLOON_BODY, diff --git a/chrome/browser/browser_process.h b/chrome/browser/browser_process.h index e1944bd..2a3822a 100644 --- a/chrome/browser/browser_process.h +++ b/chrome/browser/browser_process.h @@ -24,6 +24,7 @@ namespace safe_browsing { class ClientSideDetectionService; } +class BackgroundModeManager; class ChromeNetLog; class DevToolsManager; class DownloadRequestLimiter; @@ -39,6 +40,7 @@ class PrefService; class ProfileManager; class ResourceDispatcherHost; class SidebarManager; +class StatusTray; class TabCloseableStateWatcher; class ThumbnailGenerator; class WatchDogThread; @@ -203,6 +205,14 @@ class BrowserProcess { // Returns the object that watches for changes in the closeable state of tab. virtual TabCloseableStateWatcher* tab_closeable_state_watcher() = 0; + // Returns the object that manages background applications. + virtual BackgroundModeManager* background_mode_manager() = 0; + + // Returns the StatusTray, which provides an API for displaying status icons + // in the system status tray. Returns NULL if status icons are not supported + // on this platform (or this is a unit test). + virtual StatusTray* status_tray() = 0; + // Returns an object which handles communication with the SafeBrowsing // client-side detection servers. virtual safe_browsing::ClientSideDetectionService* diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index 481fa18..da43113 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -16,6 +16,7 @@ #include "base/threading/thread.h" #include "base/threading/thread_restrictions.h" #include "chrome/browser/automation/automation_provider_list.h" +#include "chrome/browser/background_mode_manager.h" #include "chrome/browser/browser_main.h" #include "chrome/browser/browser_process_sub_thread.h" #include "chrome/browser/browser_trial.h" @@ -55,6 +56,7 @@ #include "chrome/browser/safe_browsing/safe_browsing_service.h" #include "chrome/browser/shell_integration.h" #include "chrome/browser/sidebar/sidebar_manager.h" +#include "chrome/browser/status_icons/status_tray.h" #include "chrome/browser/tab_closeable_state_watcher.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/common/chrome_constants.h" @@ -637,6 +639,20 @@ TabCloseableStateWatcher* BrowserProcessImpl::tab_closeable_state_watcher() { return tab_closeable_state_watcher_.get(); } +BackgroundModeManager* BrowserProcessImpl::background_mode_manager() { + DCHECK(CalledOnValidThread()); + if (!background_mode_manager_.get()) + CreateBackgroundModeManager(); + return background_mode_manager_.get(); +} + +StatusTray* BrowserProcessImpl::status_tray() { + DCHECK(CalledOnValidThread()); + if (!status_tray_.get()) + CreateStatusTray(); + return status_tray_.get(); +} + safe_browsing::ClientSideDetectionService* BrowserProcessImpl::safe_browsing_detection_service() { DCHECK(CalledOnValidThread()); @@ -989,6 +1005,17 @@ void BrowserProcessImpl::CreateTabCloseableStateWatcher() { tab_closeable_state_watcher_.reset(TabCloseableStateWatcher::Create()); } +void BrowserProcessImpl::CreateBackgroundModeManager() { + DCHECK(background_mode_manager_.get() == NULL); + background_mode_manager_.reset( + new BackgroundModeManager(CommandLine::ForCurrentProcess())); +} + +void BrowserProcessImpl::CreateStatusTray() { + DCHECK(status_tray_.get() == NULL); + status_tray_.reset(StatusTray::Create()); +} + void BrowserProcessImpl::CreatePrintPreviewTabController() { DCHECK(print_preview_tab_controller_.get() == NULL); print_preview_tab_controller_ = new printing::PrintPreviewTabController(); diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h index eb8a9b6..81e0c9a 100644 --- a/chrome/browser/browser_process_impl.h +++ b/chrome/browser/browser_process_impl.h @@ -97,6 +97,8 @@ class BrowserProcessImpl : public BrowserProcess, virtual DownloadStatusUpdater* download_status_updater(); virtual base::WaitableEvent* shutdown_event(); virtual TabCloseableStateWatcher* tab_closeable_state_watcher(); + virtual BackgroundModeManager* background_mode_manager(); + virtual StatusTray* status_tray(); virtual safe_browsing::ClientSideDetectionService* safe_browsing_detection_service(); virtual bool plugin_finder_disabled() const; @@ -155,6 +157,8 @@ class BrowserProcessImpl : public BrowserProcess, void CreatePrintPreviewTabController(); void CreateBackgroundPrintingManager(); void CreateSafeBrowsingDetectionService(); + void CreateStatusTray(); + void CreateBackgroundModeManager(); bool IsSafeBrowsingDetectionServiceEnabled(); @@ -245,6 +249,10 @@ class BrowserProcessImpl : public BrowserProcess, scoped_ptr<TabCloseableStateWatcher> tab_closeable_state_watcher_; + scoped_ptr<BackgroundModeManager> background_mode_manager_; + + scoped_ptr<StatusTray> status_tray_; + bool created_safe_browsing_detection_service_; scoped_ptr<safe_browsing::ClientSideDetectionService> safe_browsing_detection_service_; diff --git a/chrome/browser/profiles/profile.cc b/chrome/browser/profiles/profile.cc index 85bbef2..e88f407 100644 --- a/chrome/browser/profiles/profile.cc +++ b/chrome/browser/profiles/profile.cc @@ -294,10 +294,6 @@ class OffTheRecordProfileImpl : public Profile, return GetOriginalProfile()->GetExtensionService(); } - virtual StatusTray* GetStatusTray() { - return GetOriginalProfile()->GetStatusTray(); - } - virtual UserScriptMaster* GetUserScriptMaster() { return GetOriginalProfile()->GetUserScriptMaster(); } diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h index 37d2c5a..22c983b 100644 --- a/chrome/browser/profiles/profile.h +++ b/chrome/browser/profiles/profile.h @@ -86,7 +86,6 @@ class SQLitePersistentCookieStore; class SSLConfigServiceManager; class SSLHostState; class SpellCheckHost; -class StatusTray; class TemplateURLFetcher; class TemplateURLModel; class TokenService; @@ -451,11 +450,6 @@ class Profile { // Returns the WebKitContext assigned to this profile. virtual WebKitContext* GetWebKitContext() = 0; - // Returns the StatusTray, which provides an API for displaying status icons - // in the system status tray. Returns NULL if status icons are not supported - // on this platform (or this is a unit test). - virtual StatusTray* GetStatusTray() = 0; - // Marks the profile as cleanly shutdown. // // NOTE: this is invoked internally on a normal shutdown, but is public so diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index 650901c..974d618 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -17,7 +17,7 @@ #include "chrome/browser/autocomplete/autocomplete_classifier.h" #include "chrome/browser/autofill/personal_data_manager.h" #include "chrome/browser/background_contents_service_factory.h" -#include "chrome/browser/background_mode_manager_factory.h" +#include "chrome/browser/background_mode_manager.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_signin.h" @@ -62,7 +62,6 @@ #include "chrome/browser/sessions/session_service_factory.h" #include "chrome/browser/spellcheck_host.h" #include "chrome/browser/ssl/ssl_host_state.h" -#include "chrome/browser/status_icons/status_tray.h" #include "chrome/browser/sync/profile_sync_factory_impl.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/tabs/pinned_tab_service_factory.h" @@ -363,7 +362,8 @@ void ProfileImpl::DoFinalInit() { // ChromeOS because Chrome is always running (no need for special keep-alive // or launch-on-startup support). #if !defined(OS_CHROMEOS) - BackgroundModeManagerFactory::GetForProfile(this); + if (g_browser_process->background_mode_manager()) + g_browser_process->background_mode_manager()->RegisterProfile(this); #endif BackgroundContentsServiceFactory::GetForProfile(this); @@ -748,12 +748,6 @@ ExtensionService* ProfileImpl::GetExtensionService() { return extension_service_.get(); } -StatusTray* ProfileImpl::GetStatusTray() { - if (!status_tray_.get()) - status_tray_.reset(StatusTray::Create()); - return status_tray_.get(); -} - UserScriptMaster* ProfileImpl::GetUserScriptMaster() { return user_script_master_.get(); } diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h index f5eb627..77977cc 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -109,7 +109,6 @@ class ProfileImpl : public Profile, virtual SpellCheckHost* GetSpellCheckHost(); virtual void ReinitializeSpellCheckHost(bool force); virtual WebKitContext* GetWebKitContext(); - virtual StatusTray* GetStatusTray(); virtual void MarkAsCleanShutdown(); virtual void InitExtensions(bool extensions_enabled); virtual void InitPromoResources(); @@ -241,7 +240,6 @@ class ProfileImpl : public Profile, scoped_refptr<WebDataService> web_data_service_; scoped_refptr<PasswordStore> password_store_; scoped_refptr<WebKitContext> webkit_context_; - scoped_ptr<StatusTray> status_tray_; scoped_refptr<PersonalDataManager> personal_data_manager_; scoped_refptr<fileapi::FileSystemContext> file_system_context_; scoped_ptr<BrowserSignin> browser_signin_; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index d19927a..7fbf1ab 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -257,8 +257,6 @@ 'browser/background_mode_manager.cc', 'browser/background_mode_manager.h', 'browser/background_mode_manager_chromeos.cc', - 'browser/background_mode_manager_factory.cc', - 'browser/background_mode_manager_factory.h', 'browser/background_mode_manager_linux.cc', 'browser/background_mode_manager_mac.mm', 'browser/background_mode_manager_win.cc', diff --git a/chrome/test/testing_browser_process.cc b/chrome/test/testing_browser_process.cc index b4b1594..6aace05 100644 --- a/chrome/test/testing_browser_process.cc +++ b/chrome/test/testing_browser_process.cc @@ -124,6 +124,14 @@ TabCloseableStateWatcher* TestingBrowserProcess::tab_closeable_state_watcher() { return NULL; } +BackgroundModeManager* TestingBrowserProcess::background_mode_manager() { + return NULL; +} + +StatusTray* TestingBrowserProcess::status_tray() { + return NULL; +} + safe_browsing::ClientSideDetectionService* TestingBrowserProcess::safe_browsing_detection_service() { return NULL; diff --git a/chrome/test/testing_browser_process.h b/chrome/test/testing_browser_process.h index 3fc3c7d..f613a7c 100644 --- a/chrome/test/testing_browser_process.h +++ b/chrome/test/testing_browser_process.h @@ -18,6 +18,7 @@ #include "chrome/browser/browser_process.h" #include "content/common/notification_service.h" +class BackgroundModeManager; class IOThread; class GoogleURLTracker; class NotificationUIManager; @@ -87,6 +88,10 @@ class TestingBrowserProcess : public BrowserProcess { virtual TabCloseableStateWatcher* tab_closeable_state_watcher(); + virtual BackgroundModeManager* background_mode_manager(); + + virtual StatusTray* status_tray(); + virtual safe_browsing::ClientSideDetectionService* safe_browsing_detection_service(); diff --git a/chrome/test/testing_profile.cc b/chrome/test/testing_profile.cc index 2c1d98c..c4123ca 100644 --- a/chrome/test/testing_profile.cc +++ b/chrome/test/testing_profile.cc @@ -677,10 +677,6 @@ NTPResourceCache* TestingProfile::GetNTPResourceCache() { return ntp_resource_cache_.get(); } -StatusTray* TestingProfile::GetStatusTray() { - return NULL; -} - FilePath TestingProfile::last_selected_directory() { return last_selected_directory_; } diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h index 18f925a..f4ea40d 100644 --- a/chrome/test/testing_profile.h +++ b/chrome/test/testing_profile.h @@ -249,7 +249,6 @@ class TestingProfile : public Profile { virtual void InitRegisteredProtocolHandlers() {} virtual NTPResourceCache* GetNTPResourceCache(); - virtual StatusTray* GetStatusTray(); virtual FilePath last_selected_directory(); virtual void set_last_selected_directory(const FilePath& path); #if defined(OS_CHROMEOS) |