diff options
Diffstat (limited to 'chrome/browser/app_menu_model.cc')
-rw-r--r-- | chrome/browser/app_menu_model.cc | 39 |
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 { |