Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2085)

Unified Diff: chrome/browser/profiles/avatar_menu_model.cc

Issue 8539043: Refactor ProfileInfoCache (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/profiles/avatar_menu_model.h ('k') | chrome/browser/profiles/profile_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
}
« no previous file with comments | « chrome/browser/profiles/avatar_menu_model.h ('k') | chrome/browser/profiles/profile_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698