Index: chrome/browser/profiles/profile_list_desktop.cc |
diff --git a/chrome/browser/profiles/profile_list_desktop.cc b/chrome/browser/profiles/profile_list_desktop.cc |
index bfa0c4f242b29f5c43186ec64c40793b36275eb1..83c3bee560986c6f42d7e70dc8e9317077393f5b 100644 |
--- a/chrome/browser/profiles/profile_list_desktop.cc |
+++ b/chrome/browser/profiles/profile_list_desktop.cc |
@@ -11,9 +11,9 @@ |
#include "components/signin/core/common/profile_management_switches.h" |
#include "ui/base/l10n/l10n_util.h" |
-ProfileListDesktop::ProfileListDesktop(ProfileInfoInterface* profile_cache) |
- : profile_info_(profile_cache), |
- omitted_item_count_(0) { |
+ProfileListDesktop::ProfileListDesktop( |
+ ProfileAttributesStorage* profile_storage) |
+ : profile_storage_(profile_storage) { |
} |
ProfileListDesktop::~ProfileListDesktop() { |
@@ -21,8 +21,8 @@ ProfileListDesktop::~ProfileListDesktop() { |
} |
// static |
-ProfileList* ProfileList::Create(ProfileInfoInterface* profile_cache) { |
- return new ProfileListDesktop(profile_cache); |
+ProfileList* ProfileList::Create(ProfileAttributesStorage* profile_storage) { |
+ return new ProfileListDesktop(profile_storage); |
} |
size_t ProfileListDesktop::GetNumberOfItems() const { |
@@ -37,52 +37,43 @@ const AvatarMenu::Item& ProfileListDesktop::GetItemAt(size_t index) const { |
void ProfileListDesktop::RebuildMenu() { |
ClearMenu(); |
- const size_t count = profile_info_->GetNumberOfProfiles(); |
- for (size_t i = 0; i < count; ++i) { |
- if (profile_info_->IsOmittedProfileAtIndex(i)) { |
- omitted_item_count_++; |
+ std::vector<ProfileAttributesEntry*> entries = |
+ profile_storage_->GetAllProfilesAttributes(); |
+ std::sort(entries.begin(), entries.end(), |
+ [] (ProfileAttributesEntry* first, ProfileAttributesEntry* second) { |
+ return first->LessThan(*second); |
Mike Lerman
2015/08/06 16:06:19
If this is the only reference to LessThan(), can w
|
+ }); |
+ size_t item_count = 0; |
+ for (ProfileAttributesEntry* entry: entries) { |
+ if (entry->IsOmitted()) { |
continue; |
} |
- gfx::Image icon = profile_info_->GetAvatarIconOfProfileAtIndex(i); |
- AvatarMenu::Item* item = new AvatarMenu::Item(i - omitted_item_count_, |
- i, |
- icon); |
- item->name = profile_info_->GetNameOfProfileAtIndex(i); |
- item->username = profile_info_->GetUserNameOfProfileAtIndex(i); |
- item->profile_path = profile_info_->GetPathOfProfileAtIndex(i); |
- item->legacy_supervised = |
- profile_info_->ProfileIsLegacySupervisedAtIndex(i); |
- item->child_account = profile_info_->ProfileIsChildAtIndex(i); |
- item->signed_in = profile_info_->ProfileIsAuthenticatedAtIndex(i); |
+ gfx::Image icon = entry->GetAvatarIcon(); |
Mike Lerman
2015/08/06 16:06:19
You can just inline icon below.
|
+ AvatarMenu::Item* item = new AvatarMenu::Item(item_count++, icon); |
+ item->name = entry->GetName(); |
+ item->username = entry->GetUserName(); |
+ item->profile_path = entry->GetPath(); |
+ item->legacy_supervised = entry->IsLegacySupervised(); |
+ item->child_account = entry->IsChild(); |
+ item->signed_in = entry->IsAuthenticated(); |
if (!item->signed_in) { |
item->username = l10n_util::GetStringUTF16( |
item->legacy_supervised ? IDS_SUPERVISED_USER_AVATAR_LABEL : |
IDS_PROFILES_LOCAL_PROFILE_STATE); |
} |
- item->active = profile_info_->GetPathOfProfileAtIndex(i) == |
- active_profile_path_; |
- item->signin_required = profile_info_->ProfileIsSigninRequiredAtIndex(i); |
+ item->active = entry->GetPath() == active_profile_path_; |
+ item->signin_required = entry->IsSigninRequired(); |
items_.push_back(item); |
} |
- // One omitted item is expected when a supervised-user profile is in the |
- // process of being registered, but there shouldn't be more than one. |
- VLOG_IF(2, (omitted_item_count_ > 1)) << omitted_item_count_ |
Mike Lerman
2015/08/06 16:06:19
Can you check with treib@ or bernhard@ that we can
|
- << " profiles omitted fom list."; |
} |
-size_t ProfileListDesktop::MenuIndexFromProfileIndex(size_t index) { |
+size_t ProfileListDesktop::MenuIndexFromProfilePath( |
+ const base::FilePath& path) { |
const size_t menu_count = GetNumberOfItems(); |
- DCHECK_LT(index, menu_count + omitted_item_count_); |
- |
- // In the common case, valid profile-cache indices correspond to indices in |
- // the menu. |
- if (!omitted_item_count_) |
- return index; |
- |
for (size_t i = 0; i < menu_count; ++i) { |
const AvatarMenu::Item item = GetItemAt(i); |
- if (item.profile_index == index) |
+ if (item.profile_path == path) |
return i; |
} |
@@ -97,5 +88,4 @@ void ProfileListDesktop::ActiveProfilePathChanged(base::FilePath& path) { |
void ProfileListDesktop::ClearMenu() { |
STLDeleteElements(&items_); |
- omitted_item_count_ = 0; |
} |