Index: chrome/browser/profiles/avatar_menu_model.cc |
diff --git a/chrome/browser/profiles/avatar_menu_model.cc b/chrome/browser/profiles/avatar_menu_model.cc |
index 7126fc122f596eb7ac401d23683552a3d9d523db..4327b3adc1b39a2ef6e6870b083c89c1d90f244b 100644 |
--- a/chrome/browser/profiles/avatar_menu_model.cc |
+++ b/chrome/browser/profiles/avatar_menu_model.cc |
@@ -77,12 +77,11 @@ AvatarMenuModel::Item::~Item() { |
void AvatarMenuModel::SwitchToProfile(size_t index) { |
const Item& item = GetItemAt(index); |
- FilePath path = profile_info_->GetPathOfProfileAtIndex(item.model_index); |
// This will be deleted by the manager after the profile is ready. |
ProfileSwitchObserver* observer = new ProfileSwitchObserver(); |
g_browser_process->profile_manager()->CreateProfileAsync( |
- path, observer); |
+ item.path, observer); |
ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::SWITCH_PROFILE_ICON); |
} |
@@ -90,7 +89,7 @@ void AvatarMenuModel::EditProfile(size_t index) { |
Browser* browser = browser_; |
if (!browser) { |
Profile* profile = g_browser_process->profile_manager()->GetProfileByPath( |
- profile_info_->GetPathOfProfileAtIndex(GetItemAt(index).model_index)); |
+ GetItemAt(index).path); |
browser = Browser::Create(profile); |
} |
std::string page = chrome::kManageProfileSubPage; |
@@ -110,22 +109,13 @@ size_t AvatarMenuModel::GetNumberOfItems() { |
} |
size_t AvatarMenuModel::GetActiveProfileIndex() { |
- // During singleton profile deletion, this function can be called with no |
- // profiles in the model - crbug.com/102278 . |
- if (items_.size() == 0) |
- return 0; |
- |
- Profile* active_profile = NULL; |
- if (!browser_) |
- active_profile = ProfileManager::GetLastUsedProfile(); |
- else |
- active_profile = browser_->profile(); |
- |
- size_t index = |
- profile_info_->GetIndexOfProfileWithPath(active_profile->GetPath()); |
+ for (size_t i = 0; i < items_.size(); ++i) { |
+ if (items_[i]->active) |
+ return i; |
+ } |
- DCHECK_LT(index, items_.size()); |
- return index; |
+ // We can reach here during singleton profile deleting. |
+ return 0; |
} |
const AvatarMenuModel::Item& AvatarMenuModel::GetItemAt(size_t index) { |
@@ -150,19 +140,19 @@ bool AvatarMenuModel::ShouldShowAvatarMenu() { |
void AvatarMenuModel::RebuildMenu() { |
ClearMenu(); |
- const size_t count = profile_info_->GetNumberOfProfiles(); |
- for (size_t i = 0; i < count; ++i) { |
- Item* item = new Item(i, profile_info_->GetAvatarIconOfProfileAtIndex(i)); |
- item->name = profile_info_->GetNameOfProfileAtIndex(i); |
- item->sync_state = profile_info_->GetUserNameOfProfileAtIndex(i); |
+ std::vector<ProfileInfoEntry> entries( |
+ profile_info_->GetProfilesSortedByName()); |
+ for (size_t i = 0; i < entries.size(); ++i) { |
+ const ProfileInfoEntry& entry = entries[i]; |
+ Item* item = new Item(i, entry.GetIcon()); |
+ item->name = entry.name(); |
+ item->sync_state = entry.user_name(); |
if (item->sync_state.empty()) { |
item->sync_state = l10n_util::GetStringUTF16( |
IDS_PROFILES_LOCAL_PROFILE_STATE); |
} |
- if (browser_) { |
- FilePath path = profile_info_->GetPathOfProfileAtIndex(i); |
- item->active = browser_->profile()->GetPath() == path; |
- } |
+ if (browser_) |
+ item->active = browser_->profile()->GetPath() == entry.path(); |
items_.push_back(item); |
} |
} |