Index: chrome/browser/chromeos/profiles/profile_list_chromeos.cc |
diff --git a/chrome/browser/chromeos/profiles/profile_list_chromeos.cc b/chrome/browser/chromeos/profiles/profile_list_chromeos.cc |
index 840d29f084511c2cf753115a80a4ffe31c7b7d88..91e22da524bf6a151ec6ee00892e7ce62fa6c910 100644 |
--- a/chrome/browser/chromeos/profiles/profile_list_chromeos.cc |
+++ b/chrome/browser/chromeos/profiles/profile_list_chromeos.cc |
@@ -9,6 +9,8 @@ |
#include "ash/shell.h" |
#include "base/command_line.h" |
#include "chrome/browser/chromeos/profiles/profile_helper.h" |
+#include "chrome/browser/profiles/profile_attributes_entry.h" |
+#include "chrome/browser/profiles/profile_attributes_storage.h" |
#include "chrome/browser/profiles/profile_avatar_icon_util.h" |
#include "chrome/browser/profiles/profile_manager.h" |
#include "chrome/common/chrome_switches.h" |
@@ -16,14 +18,15 @@ |
#include "components/user_manager/user_manager.h" |
// static |
-ProfileList* ProfileList::Create(ProfileInfoInterface* profile_cache) { |
- return new chromeos::ProfileListChromeOS(profile_cache); |
+ProfileList* ProfileList::Create(ProfileAttributesStorage* profile_storage) { |
+ return new chromeos::ProfileListChromeOS(profile_storage); |
} |
namespace chromeos { |
-ProfileListChromeOS::ProfileListChromeOS(ProfileInfoInterface* profile_cache) |
- : profile_info_(profile_cache) { |
+ProfileListChromeOS::ProfileListChromeOS( |
+ ProfileAttributesStorage* profile_storage) |
+ : profile_storage_(profile_storage) { |
} |
ProfileListChromeOS::~ProfileListChromeOS() { |
@@ -46,12 +49,24 @@ void ProfileListChromeOS::RebuildMenu() { |
user_manager::UserList users = |
user_manager::UserManager::Get()->GetLoggedInUsers(); |
+ std::vector<ProfileAttributesEntry*> entries = |
+ profile_storage_->GetAllProfilesAttributes(); |
+ // Prepare a sorted vector of the profile attributes entries that will be used |
+ // to determine an item's index in the AvatarMenu. |
+ std::sort(entries.begin(), entries.end(), |
+ [](ProfileAttributesEntry* first, ProfileAttributesEntry* second) { |
+ return first->LessThan(*second); |
+ }); |
// Add corresponding profiles. |
for (user_manager::UserList::const_iterator it = users.begin(); |
it != users.end(); |
++it) { |
- size_t i = profile_info_->GetIndexOfProfileWithPath( |
- ProfileHelper::GetProfilePathByUserIdHash((*it)->username_hash())); |
+ const base::FilePath& path = |
+ ProfileHelper::GetProfilePathByUserIdHash((*it)->username_hash()); |
+ ProfileAttributesEntry* entry; |
+ if (!profile_storage_->GetProfileAttributesWithPath(path, &entry)) { |
+ continue; |
+ } |
gfx::Image icon = gfx::Image((*it)->GetImage()); |
if (!switches::IsNewProfileManagement() && !icon.IsEmpty()) { |
@@ -59,17 +74,19 @@ void ProfileListChromeOS::RebuildMenu() { |
icon = profiles::GetAvatarIconForMenu(icon, true); |
} |
- AvatarMenu::Item* item = new AvatarMenu::Item(i, i, icon); |
+ size_t sorted_index = |
Mike Lerman
2015/08/06 16:06:19
Why not just keep an iterator i that you increment
|
+ std::find(entries.begin(), entries.end(), entry) - entries.begin(); |
+ DCHECK(sorted_index < entries.size()); |
+ AvatarMenu::Item* item = new AvatarMenu::Item(sorted_index, icon); |
item->name = (*it)->GetDisplayName(); |
- item->username = profile_info_->GetUserNameOfProfileAtIndex(i); |
- item->profile_path = profile_info_->GetPathOfProfileAtIndex(i); |
- DCHECK(!profile_info_->ProfileIsLegacySupervisedAtIndex(i)); |
+ item->username = entry->GetUserName(); |
+ item->profile_path = entry->GetPath(); |
+ DCHECK(!entry->IsLegacySupervised()); |
item->legacy_supervised = false; |
- item->child_account = profile_info_->ProfileIsChildAtIndex(i); |
+ item->child_account = entry->IsChild(); |
item->signed_in = true; |
- 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); |
} |
@@ -80,13 +97,14 @@ void ProfileListChromeOS::RebuildMenu() { |
items_[i]->menu_index = i; |
} |
-size_t ProfileListChromeOS::MenuIndexFromProfileIndex(size_t index) { |
+size_t ProfileListChromeOS::MenuIndexFromProfilePath( |
+ const base::FilePath& path) { |
// On ChromeOS, the active profile might be Default, which does not show |
// up in the model as a logged-in user. In that case, we return 0. |
size_t menu_index = 0; |
for (size_t i = 0; i < GetNumberOfItems(); ++i) { |
- if (items_[i]->profile_index == index) { |
+ if (items_[i]->profile_path == path) { |
menu_index = i; |
break; |
} |