summaryrefslogtreecommitdiffstats
path: root/chrome/browser/app_menu_model.cc
diff options
context:
space:
mode:
authorxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-06 00:16:40 +0000
committerxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-06 00:16:40 +0000
commita3354454938083e933e2c988777a1c53d94b4277 (patch)
tree5cbfca015873e7c56eccefe80d1a979e500b33cb /chrome/browser/app_menu_model.cc
parent50a376f0d18e4f76a3ab04c46c66df965b6b2192 (diff)
downloadchromium_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/browser/app_menu_model.cc')
-rw-r--r--chrome/browser/app_menu_model.cc39
1 files changed, 31 insertions, 8 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 {