diff options
author | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-06 00:16:40 +0000 |
---|---|---|
committer | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-06 00:16:40 +0000 |
commit | a3354454938083e933e2c988777a1c53d94b4277 (patch) | |
tree | 5cbfca015873e7c56eccefe80d1a979e500b33cb /chrome | |
parent | 50a376f0d18e4f76a3ab04c46c66df965b6b2192 (diff) | |
download | chromium_src-a3354454938083e933e2c988777a1c53d94b4277.zip chromium_src-a3354454938083e933e2c988777a1c53d94b4277.tar.gz chromium_src-a3354454938083e933e2c988777a1c53d94b4277.tar.bz2 |
Rebuild app menu in ToolbarView::RunAppMenu
When "enable-udd-profiles" switch is set, update profile submenu and
rebuild app menu if necessary.
BUG=30417
TEST=Verify that comment 5 in issue 30417 is fixed.
Review URL: http://codereview.chromium.org/571015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38281 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/app_menu_model.cc | 39 | ||||
-rw-r--r-- | chrome/browser/app_menu_model.h | 20 | ||||
-rw-r--r-- | chrome/browser/views/toolbar_view.cc | 2 |
3 files changed, 49 insertions, 12 deletions
diff --git a/chrome/browser/app_menu_model.cc b/chrome/browser/app_menu_model.cc index 7ecaa57..dd5ce6a 100644 --- a/chrome/browser/app_menu_model.cc +++ b/chrome/browser/app_menu_model.cc @@ -1,9 +1,11 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this -// source code is governed by a BSD-style license that can be found in the -// LICENSE file. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. #include "chrome/browser/app_menu_model.h" +#include <algorithm> + #include "app/l10n_util.h" #include "base/command_line.h" #include "chrome/app/chrome_dll_resource.h" @@ -43,9 +45,6 @@ void AppMenuModel::Build() { // done. See OnGetProfilesDone(). const CommandLine& command_line = *CommandLine::ForCurrentProcess(); if (command_line.HasSwitch(switches::kEnableUserDataDirProfiles)) { - // Triggers profile list refresh in case it's changed. - UserDataManager::Get()->RefreshUserDataDirProfiles(); - if (!profiles_menu_contents_.get()) { profiles_menu_contents_.reset(new menus::SimpleMenuModel(delegate())); BuildProfileSubMenu(); @@ -91,15 +90,28 @@ void AppMenuModel::Build() { } } -void AppMenuModel::BuildProfileSubMenu() { +bool AppMenuModel::BuildProfileSubMenu() { // Nothing to do if the menu has gone away. if (!profiles_menu_contents_.get()) - return; + return false; + + // Triggers profile list refresh in case it's changed. + UserDataManager::Get()->RefreshUserDataDirProfiles(); // Use the list of profiles in the browser. const std::vector<std::wstring>& profiles = browser_->user_data_dir_profiles(); + // Check if profiles have changed. + if (!ProfilesChanged(profiles)) + return false; + + // Update known profiles. + known_profiles_.assign(profiles.begin(), profiles.end()); + + // Clear old profile menu items. + profiles_menu_contents_->Clear(); + // Add direct submenu items for profiles. std::vector<std::wstring>::const_iterator iter = profiles.begin(); for (int i = IDC_NEW_WINDOW_PROFILE_0; @@ -119,6 +131,17 @@ void AppMenuModel::BuildProfileSubMenu() { profiles_menu_contents_->AddItemWithStringId( IDC_NEW_PROFILE, IDS_SELECT_PROFILE_DIALOG_NEW_PROFILE_ENTRY); + + return true; +} + +bool AppMenuModel::ProfilesChanged( + const std::vector<std::wstring>& profiles) const { + if (profiles.size() != known_profiles_.size()) + return true; + + return !std::equal(profiles.begin(), profiles.end(), + known_profiles_.begin()); } string16 AppMenuModel::GetSyncMenuLabel() const { diff --git a/chrome/browser/app_menu_model.h b/chrome/browser/app_menu_model.h index a3d7e0e..b0daac7 100644 --- a/chrome/browser/app_menu_model.h +++ b/chrome/browser/app_menu_model.h @@ -1,10 +1,13 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this -// source code is governed by a BSD-style license that can be found in the -// LICENSE file. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. #ifndef CHROME_BROWSER_APP_MENU_MODEL_H_ #define CHROME_BROWSER_APP_MENU_MODEL_H_ +#include <set> +#include <vector> + #include "app/menus/simple_menu_model.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" @@ -24,9 +27,14 @@ class AppMenuModel : public menus::SimpleMenuModel { virtual bool IsLabelDynamicAt(int index) const; virtual string16 GetLabelAt(int index) const; + // Build/update profile submenu. Return true if profiles submenu is built or + // updated. False otherwise. + bool BuildProfileSubMenu(); + private: void Build(); - void BuildProfileSubMenu(); + + bool ProfilesChanged(const std::vector<std::wstring>& profiles) const; string16 GetSyncMenuLabel() const; bool IsSyncItem(int index) const; @@ -34,6 +42,10 @@ class AppMenuModel : public menus::SimpleMenuModel { // Contents of the profiles menu to populate with profile names. scoped_ptr<menus::SimpleMenuModel> profiles_menu_contents_; + // Profile names that are in profiles_menu_contents_. This is used to + // detect profile change. + std::vector<std::wstring> known_profiles_; + Browser* browser_; // weak DISALLOW_COPY_AND_ASSIGN(AppMenuModel); diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc index 0762ce2..cde3b64 100644 --- a/chrome/browser/views/toolbar_view.cc +++ b/chrome/browser/views/toolbar_view.cc @@ -706,5 +706,7 @@ void ToolbarView::RunPageMenu(const gfx::Point& pt) { } void ToolbarView::RunAppMenu(const gfx::Point& pt) { + if (app_menu_model_->BuildProfileSubMenu()) + app_menu_menu_->Rebuild(); app_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); } |