summaryrefslogtreecommitdiffstats
path: root/chrome/browser/background
diff options
context:
space:
mode:
authorsidharthms@chromium.org <sidharthms@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-28 08:23:59 +0000
committersidharthms@chromium.org <sidharthms@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-28 08:23:59 +0000
commitf528059f1c18b4f5b29509d6270bed5812d8b467 (patch)
treef73e32df4235f022055f2376a16718ccaa00532f /chrome/browser/background
parentafd7186b06526ff947e6df14ce25a51c7297ff47 (diff)
downloadchromium_src-f528059f1c18b4f5b29509d6270bed5812d8b467.zip
chromium_src-f528059f1c18b4f5b29509d6270bed5812d8b467.tar.gz
chromium_src-f528059f1c18b4f5b29509d6270bed5812d8b467.tar.bz2
Update Status Icon menu when menu model changes (Linux Aura)
Status icon context menus currently do not update themselves when the menu model changes or when the check state of a menu item changes. This patch fixes that behavior. BUG=263926,262395 Review URL: https://chromiumcodereview.appspot.com/20728003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@219964 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/background')
-rw-r--r--chrome/browser/background/background_mode_manager.cc70
-rw-r--r--chrome/browser/background/background_mode_manager.h26
2 files changed, 29 insertions, 67 deletions
diff --git a/chrome/browser/background/background_mode_manager.cc b/chrome/browser/background/background_mode_manager.cc
index 579f031..7dc5c5e 100644
--- a/chrome/browser/background/background_mode_manager.cc
+++ b/chrome/browser/background/background_mode_manager.cc
@@ -63,24 +63,7 @@ BackgroundModeManager::BackgroundModeData::~BackgroundModeData() {
}
///////////////////////////////////////////////////////////////////////////////
-// BackgroundModeManager::BackgroundModeData, ui::SimpleMenuModel overrides
-bool BackgroundModeManager::BackgroundModeData::IsCommandIdChecked(
- int command_id) const {
- NOTREACHED() << "There are no checked items in the profile submenu.";
- return false;
-}
-
-bool BackgroundModeManager::BackgroundModeData::IsCommandIdEnabled(
- int command_id) const {
- return command_id != IDC_MinimumLabelValue;
-}
-
-bool BackgroundModeManager::BackgroundModeData::GetAcceleratorForCommandId(
- int command_id, ui::Accelerator* accelerator) {
- // No accelerators for status icon context menus.
- return false;
-}
-
+// BackgroundModeManager::BackgroundModeData, StatusIconMenuModel overrides
void BackgroundModeManager::BackgroundModeData::ExecuteCommand(
int item,
int event_flags) {
@@ -110,14 +93,15 @@ int BackgroundModeManager::BackgroundModeData::GetBackgroundAppCount() const {
}
void BackgroundModeManager::BackgroundModeData::BuildProfileMenu(
- ui::SimpleMenuModel* menu,
- ui::SimpleMenuModel* containing_menu) {
+ StatusIconMenuModel* menu,
+ StatusIconMenuModel* containing_menu) {
int position = 0;
// When there are no background applications, we want to display
// just a label stating that none are running.
if (applications_->size() < 1) {
menu->AddItemWithStringId(IDC_MinimumLabelValue,
IDS_BACKGROUND_APP_NOT_INSTALLED);
+ menu->SetCommandIdEnabled(IDC_MinimumLabelValue, false);
} else {
for (extensions::ExtensionList::const_iterator cursor =
applications_->begin();
@@ -459,29 +443,7 @@ void BackgroundModeManager::OnProfileNameChanged(
}
///////////////////////////////////////////////////////////////////////////////
-// BackgroundModeManager::BackgroundModeData, ui::SimpleMenuModel overrides
-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 {
- if (command_id == IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND) {
- PrefService* service = g_browser_process->local_state();
- DCHECK(service);
- return service->IsUserModifiablePreference(prefs::kBackgroundModeEnabled);
- }
- return command_id != IDC_MinimumLabelValue;
-}
-
-bool BackgroundModeManager::GetAcceleratorForCommandId(
- int command_id, ui::Accelerator* accelerator) {
- // No accelerators for status icon context menus.
- return false;
-}
-
+// BackgroundModeManager::BackgroundModeData, StatusIconMenuModel overrides
void BackgroundModeManager::ExecuteCommand(int command_id, int event_flags) {
// When a browser window is necessary, we use the first profile. The windows
// opened for these commands are not profile-specific, so any profile would
@@ -699,7 +661,7 @@ void BackgroundModeManager::UpdateStatusTrayIconContextMenu() {
// TODO(rlp): Add current profile color or indicator.
// Create a context menu item for Chrome.
- ui::SimpleMenuModel* menu = new ui::SimpleMenuModel(this);
+ scoped_ptr<StatusIconMenuModel> menu(new StatusIconMenuModel(this));
// Add About item
menu->AddItem(IDC_ABOUT, l10n_util::GetStringUTF16(IDS_ABOUT));
menu->AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER);
@@ -724,8 +686,8 @@ void BackgroundModeManager::UpdateStatusTrayIconContextMenu() {
// We should only display the profile in the status icon if it has at
// least one background app.
if (bmd->GetBackgroundAppCount() > 0) {
- ui::SimpleMenuModel* submenu = new ui::SimpleMenuModel(bmd);
- bmd->BuildProfileMenu(submenu, menu);
+ StatusIconMenuModel* submenu = new StatusIconMenuModel(bmd);
+ bmd->BuildProfileMenu(submenu, menu.get());
profiles_with_apps++;
}
}
@@ -738,17 +700,27 @@ void BackgroundModeManager::UpdateStatusTrayIconContextMenu() {
// have any profiles in the cache.
DCHECK(profile_cache_->GetNumberOfProfiles() == size_t(1) ||
keep_alive_for_test_);
- background_mode_data_.begin()->second->BuildProfileMenu(menu, NULL);
+ background_mode_data_.begin()->second->BuildProfileMenu(menu.get(), NULL);
}
menu->AddSeparator(ui::NORMAL_SEPARATOR);
menu->AddCheckItemWithStringId(
IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND,
IDS_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND);
+ menu->SetCommandIdChecked(IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND,
+ true);
+
+ PrefService* service = g_browser_process->local_state();
+ DCHECK(service);
+ bool enabled =
+ service->IsUserModifiablePreference(prefs::kBackgroundModeEnabled);
+ menu->SetCommandIdEnabled(IDC_STATUS_TRAY_KEEP_CHROME_RUNNING_IN_BACKGROUND,
+ enabled);
+
menu->AddItemWithStringId(IDC_EXIT, IDS_EXIT);
- context_menu_ = menu;
- status_icon_->SetContextMenu(menu);
+ context_menu_ = menu.get();
+ status_icon_->SetContextMenu(menu.Pass());
}
void BackgroundModeManager::RemoveStatusTrayIcon() {
diff --git a/chrome/browser/background/background_mode_manager.h b/chrome/browser/background/background_mode_manager.h
index e1c8051..118d386 100644
--- a/chrome/browser/background/background_mode_manager.h
+++ b/chrome/browser/background/background_mode_manager.h
@@ -12,10 +12,10 @@
#include "chrome/browser/background/background_application_list_model.h"
#include "chrome/browser/profiles/profile_info_cache_observer.h"
#include "chrome/browser/status_icons/status_icon.h"
+#include "chrome/browser/status_icons/status_icon_menu_model.h"
#include "components/browser_context_keyed_service/browser_context_keyed_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
-#include "ui/base/models/simple_menu_model.h"
class Browser;
class CommandLine;
@@ -47,7 +47,7 @@ class BackgroundModeManager
: public content::NotificationObserver,
public BackgroundApplicationListModel::Observer,
public ProfileInfoCacheObserver,
- public ui::SimpleMenuModel::Delegate {
+ public StatusIconMenuModel::Delegate {
public:
BackgroundModeManager(CommandLine* command_line,
ProfileInfoCache* profile_cache);
@@ -88,7 +88,7 @@ class BackgroundModeManager
FRIEND_TEST_ALL_PREFIXES(BackgroundAppBrowserTest,
ReloadBackgroundApp);
- class BackgroundModeData : public ui::SimpleMenuModel::Delegate {
+ class BackgroundModeData : public StatusIconMenuModel::Delegate {
public:
explicit BackgroundModeData(
int command_id,
@@ -98,12 +98,7 @@ class BackgroundModeManager
// The cached list of BackgroundApplications.
scoped_ptr<BackgroundApplicationListModel> applications_;
- // 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;
+ // Overrides from StatusIconMenuModel::Delegate implementation.
virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
// Returns a browser window, or creates one if none are open. Used by
@@ -118,8 +113,8 @@ class BackgroundModeManager
// be a submenu in the case of multi-profiles or the main menu in the case
// of the single profile case. If containing_menu is valid, we will add
// menu as a submenu to it.
- void BuildProfileMenu(ui::SimpleMenuModel* menu,
- ui::SimpleMenuModel* containing_menu);
+ void BuildProfileMenu(StatusIconMenuModel* menu,
+ StatusIconMenuModel* containing_menu);
// Set the name associated with this background mode data for displaying in
// the status tray.
@@ -175,12 +170,7 @@ class BackgroundModeManager
virtual void OnProfileNameChanged(const base::FilePath& profile_path,
const string16& old_profile_name) OVERRIDE;
- // 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;
+ // Overrides from StatusIconMenuModel::Delegate implementation.
virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
// Invoked when an extension is installed so we can ensure that
@@ -295,7 +285,7 @@ class BackgroundModeManager
// Reference to our status icon's context menu (if any) - owned by the
// status_icon_.
- ui::SimpleMenuModel* context_menu_;
+ StatusIconMenuModel* context_menu_;
// 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