OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/profiles/profile_list_desktop.h" | 5 #include "chrome/browser/profiles/profile_list_desktop.h" |
6 | 6 |
7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 8 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
9 #include "chrome/browser/profiles/profile_info_cache.h" | 9 #include "chrome/browser/profiles/profile_info_cache.h" |
10 #include "chrome/grit/generated_resources.h" | 10 #include "chrome/grit/generated_resources.h" |
11 #include "components/signin/core/common/profile_management_switches.h" | 11 #include "components/signin/core/common/profile_management_switches.h" |
12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
13 | 13 |
14 ProfileListDesktop::ProfileListDesktop(ProfileInfoInterface* profile_cache) | 14 ProfileListDesktop::ProfileListDesktop( |
15 : profile_info_(profile_cache), | 15 ProfileAttributesStorage* profile_storage) |
16 omitted_item_count_(0) { | 16 : profile_storage_(profile_storage) { |
17 } | 17 } |
18 | 18 |
19 ProfileListDesktop::~ProfileListDesktop() { | 19 ProfileListDesktop::~ProfileListDesktop() { |
20 ClearMenu(); | 20 ClearMenu(); |
21 } | 21 } |
22 | 22 |
23 // static | 23 // static |
24 ProfileList* ProfileList::Create(ProfileInfoInterface* profile_cache) { | 24 ProfileList* ProfileList::Create(ProfileAttributesStorage* profile_storage) { |
25 return new ProfileListDesktop(profile_cache); | 25 return new ProfileListDesktop(profile_storage); |
26 } | 26 } |
27 | 27 |
28 size_t ProfileListDesktop::GetNumberOfItems() const { | 28 size_t ProfileListDesktop::GetNumberOfItems() const { |
29 return items_.size(); | 29 return items_.size(); |
30 } | 30 } |
31 | 31 |
32 const AvatarMenu::Item& ProfileListDesktop::GetItemAt(size_t index) const { | 32 const AvatarMenu::Item& ProfileListDesktop::GetItemAt(size_t index) const { |
33 DCHECK_LT(index, items_.size()); | 33 DCHECK_LT(index, items_.size()); |
34 return *items_[index]; | 34 return *items_[index]; |
35 } | 35 } |
36 | 36 |
37 void ProfileListDesktop::RebuildMenu() { | 37 void ProfileListDesktop::RebuildMenu() { |
38 ClearMenu(); | 38 ClearMenu(); |
39 | 39 |
40 const size_t count = profile_info_->GetNumberOfProfiles(); | 40 std::vector<ProfileAttributesEntry*> entries = |
41 for (size_t i = 0; i < count; ++i) { | 41 profile_storage_->GetAllProfilesAttributes(); |
42 if (profile_info_->IsOmittedProfileAtIndex(i)) { | 42 std::sort(entries.begin(), entries.end(), |
43 omitted_item_count_++; | 43 [] (ProfileAttributesEntry* first, ProfileAttributesEntry* second) { |
44 return first->LessThan(*second); | |
Mike Lerman
2015/08/06 16:06:19
If this is the only reference to LessThan(), can w
| |
45 }); | |
46 size_t item_count = 0; | |
47 for (ProfileAttributesEntry* entry: entries) { | |
48 if (entry->IsOmitted()) { | |
44 continue; | 49 continue; |
45 } | 50 } |
46 | 51 |
47 gfx::Image icon = profile_info_->GetAvatarIconOfProfileAtIndex(i); | 52 gfx::Image icon = entry->GetAvatarIcon(); |
Mike Lerman
2015/08/06 16:06:19
You can just inline icon below.
| |
48 AvatarMenu::Item* item = new AvatarMenu::Item(i - omitted_item_count_, | 53 AvatarMenu::Item* item = new AvatarMenu::Item(item_count++, icon); |
49 i, | 54 item->name = entry->GetName(); |
50 icon); | 55 item->username = entry->GetUserName(); |
51 item->name = profile_info_->GetNameOfProfileAtIndex(i); | 56 item->profile_path = entry->GetPath(); |
52 item->username = profile_info_->GetUserNameOfProfileAtIndex(i); | 57 item->legacy_supervised = entry->IsLegacySupervised(); |
53 item->profile_path = profile_info_->GetPathOfProfileAtIndex(i); | 58 item->child_account = entry->IsChild(); |
54 item->legacy_supervised = | 59 item->signed_in = entry->IsAuthenticated(); |
55 profile_info_->ProfileIsLegacySupervisedAtIndex(i); | |
56 item->child_account = profile_info_->ProfileIsChildAtIndex(i); | |
57 item->signed_in = profile_info_->ProfileIsAuthenticatedAtIndex(i); | |
58 if (!item->signed_in) { | 60 if (!item->signed_in) { |
59 item->username = l10n_util::GetStringUTF16( | 61 item->username = l10n_util::GetStringUTF16( |
60 item->legacy_supervised ? IDS_SUPERVISED_USER_AVATAR_LABEL : | 62 item->legacy_supervised ? IDS_SUPERVISED_USER_AVATAR_LABEL : |
61 IDS_PROFILES_LOCAL_PROFILE_STATE); | 63 IDS_PROFILES_LOCAL_PROFILE_STATE); |
62 } | 64 } |
63 item->active = profile_info_->GetPathOfProfileAtIndex(i) == | 65 item->active = entry->GetPath() == active_profile_path_; |
64 active_profile_path_; | 66 item->signin_required = entry->IsSigninRequired(); |
65 item->signin_required = profile_info_->ProfileIsSigninRequiredAtIndex(i); | |
66 items_.push_back(item); | 67 items_.push_back(item); |
67 } | 68 } |
68 // One omitted item is expected when a supervised-user profile is in the | |
69 // process of being registered, but there shouldn't be more than one. | |
70 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
| |
71 << " profiles omitted fom list."; | |
72 } | 69 } |
73 | 70 |
74 size_t ProfileListDesktop::MenuIndexFromProfileIndex(size_t index) { | 71 size_t ProfileListDesktop::MenuIndexFromProfilePath( |
72 const base::FilePath& path) { | |
75 const size_t menu_count = GetNumberOfItems(); | 73 const size_t menu_count = GetNumberOfItems(); |
76 DCHECK_LT(index, menu_count + omitted_item_count_); | |
77 | |
78 // In the common case, valid profile-cache indices correspond to indices in | |
79 // the menu. | |
80 if (!omitted_item_count_) | |
81 return index; | |
82 | |
83 for (size_t i = 0; i < menu_count; ++i) { | 74 for (size_t i = 0; i < menu_count; ++i) { |
84 const AvatarMenu::Item item = GetItemAt(i); | 75 const AvatarMenu::Item item = GetItemAt(i); |
85 if (item.profile_index == index) | 76 if (item.profile_path == path) |
86 return i; | 77 return i; |
87 } | 78 } |
88 | 79 |
89 // The desired index was not found; return a fallback value. | 80 // The desired index was not found; return a fallback value. |
90 NOTREACHED(); | 81 NOTREACHED(); |
91 return 0; | 82 return 0; |
92 } | 83 } |
93 | 84 |
94 void ProfileListDesktop::ActiveProfilePathChanged(base::FilePath& path) { | 85 void ProfileListDesktop::ActiveProfilePathChanged(base::FilePath& path) { |
95 active_profile_path_ = path; | 86 active_profile_path_ = path; |
96 } | 87 } |
97 | 88 |
98 void ProfileListDesktop::ClearMenu() { | 89 void ProfileListDesktop::ClearMenu() { |
99 STLDeleteElements(&items_); | 90 STLDeleteElements(&items_); |
100 omitted_item_count_ = 0; | |
101 } | 91 } |
OLD | NEW |