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

Side by Side Diff: chrome/browser/profiles/avatar_menu.cc

Issue 33753002: Sooper experimental refactoring of the profile info cache. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 7 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/avatar_menu.h" 5 #include "chrome/browser/profiles/avatar_menu.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 // Register this as an observer of the info cache. 77 // Register this as an observer of the info cache.
78 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, 78 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
79 content::NotificationService::AllSources()); 79 content::NotificationService::AllSources());
80 } 80 }
81 81
82 AvatarMenu::~AvatarMenu() { 82 AvatarMenu::~AvatarMenu() {
83 } 83 }
84 84
85 AvatarMenu::Item::Item(size_t menu_index, 85 AvatarMenu::Item::Item(size_t menu_index,
86 size_t profile_index,
87 const gfx::Image& icon) 86 const gfx::Image& icon)
88 : icon(icon), 87 : icon(icon),
89 active(false), 88 active(false),
90 signed_in(false), 89 signed_in(false),
91 signin_required(false), 90 signin_required(false),
92 menu_index(menu_index), 91 menu_index(menu_index) {
93 profile_index(profile_index) {
94 } 92 }
95 93
96 AvatarMenu::Item::~Item() { 94 AvatarMenu::Item::~Item() {
97 } 95 }
98 96
99 // static 97 // static
100 bool AvatarMenu::ShouldShowAvatarMenu() { 98 bool AvatarMenu::ShouldShowAvatarMenu() {
101 if (base::FieldTrialList::FindFullName(kShowProfileSwitcherFieldTrialName) == 99 if (base::FieldTrialList::FindFullName(kShowProfileSwitcherFieldTrialName) ==
102 kAlwaysShowSwitcherGroupName) { 100 kAlwaysShowSwitcherGroupName) {
103 // We should only be in this group when multi-profiles is enabled. 101 // We should only be in this group when multi-profiles is enabled.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 profile_manager->CreateProfileAsync(ProfileManager::GetGuestProfilePath(), 134 profile_manager->CreateProfileAsync(ProfileManager::GetGuestProfilePath(),
137 base::Bind(&OnProfileCreated, 135 base::Bind(&OnProfileCreated,
138 false, 136 false,
139 desktop_type), 137 desktop_type),
140 string16(), 138 string16(),
141 string16(), 139 string16(),
142 std::string()); 140 std::string());
143 } 141 }
144 142
145 void AvatarMenu::SwitchToProfile(size_t index, bool always_create) { 143 void AvatarMenu::SwitchToProfile(size_t index, bool always_create) {
144 const Item& active_item = GetActiveProfileItem();
146 DCHECK(profiles::IsMultipleProfilesEnabled() || 145 DCHECK(profiles::IsMultipleProfilesEnabled() ||
147 index == GetActiveProfileIndex()); 146 index == active_item.menu_index);
147
148 const Item& item = GetItemAt(index); 148 const Item& item = GetItemAt(index);
149 base::FilePath path = 149 base::FilePath path = item.profile_path;
150 profile_info_->GetPathOfProfileAtIndex(item.profile_index);
151
152 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); 150 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop();
153 if (browser_) 151 if (browser_)
154 desktop_type = browser_->host_desktop_type(); 152 desktop_type = browser_->host_desktop_type();
155 153
156 profiles::SwitchToProfile(path, desktop_type, always_create); 154 profiles::SwitchToProfile(path, desktop_type, always_create);
157 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_ICON); 155 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_ICON);
158 } 156 }
159 157
160 void AvatarMenu::AddNewProfile(ProfileMetrics::ProfileAdd type) { 158 void AvatarMenu::AddNewProfile(ProfileMetrics::ProfileAdd type) {
161 menu_actions_->AddNewProfile(type); 159 menu_actions_->AddNewProfile(type);
162 } 160 }
163 161
164 void AvatarMenu::EditProfile(size_t index) { 162 void AvatarMenu::EditProfile(size_t index) {
165 // Get the index in the profile cache from the menu index. 163 // Get the index in the profile cache from the menu index.
166 size_t profile_index = profile_list_->GetItemAt(index).profile_index; 164 size_t profile_index = profile_list_->GetItemAt(index).profile_path;
167 165
168 Profile* profile = g_browser_process->profile_manager()->GetProfileByPath( 166 Profile* profile = g_browser_process->profile_manager()->GetProfileByPath(
169 profile_info_->GetPathOfProfileAtIndex(profile_index)); 167 profile_list_->GetItemAt(index).profile_path);
170 168
171 menu_actions_->EditProfile(profile, profile_index); 169 menu_actions_->EditProfile(profile);
172 } 170 }
173 171
174 void AvatarMenu::RebuildMenu() { 172 void AvatarMenu::RebuildMenu() {
175 profile_list_->RebuildMenu(); 173 profile_list_->RebuildMenu();
176 } 174 }
177 175
178 size_t AvatarMenu::GetNumberOfItems() const { 176 size_t AvatarMenu::GetNumberOfItems() const {
179 return profile_list_->GetNumberOfItems(); 177 return profile_list_->GetNumberOfItems();
180 } 178 }
181 179
182 const AvatarMenu::Item& AvatarMenu::GetItemAt(size_t index) const { 180 const AvatarMenu::Item& AvatarMenu::GetItemAt(size_t index) const {
183 return profile_list_->GetItemAt(index); 181 return profile_list_->GetItemAt(index);
184 } 182 }
185 size_t AvatarMenu::GetActiveProfileIndex() {
186 183
187 // During singleton profile deletion, this function can be called with no 184 const AvatarMenu::Item& AvatarMenu::GetActiveProfileItem() const {
188 // profiles in the model - crbug.com/102278 . 185 return profile_list_->GetActiveItem();
189 if (profile_list_->GetNumberOfItems() == 0)
190 return 0;
191
192 Profile* active_profile = NULL;
193 if (!browser_)
194 active_profile = ProfileManager::GetLastUsedProfile();
195 else
196 active_profile = browser_->profile();
197
198 size_t index =
199 profile_info_->GetIndexOfProfileWithPath(active_profile->GetPath());
200
201 index = profile_list_->MenuIndexFromProfileIndex(index);
202 DCHECK_LT(index, profile_list_->GetNumberOfItems());
203 return index;
204 } 186 }
205 187
206 base::string16 AvatarMenu::GetManagedUserInformation() const { 188 base::string16 AvatarMenu::GetManagedUserInformation() const {
207 // |browser_| can be NULL in unit_tests. 189 // |browser_| can be NULL in unit_tests.
208 if (browser_ && browser_->profile()->IsManaged()) { 190 if (browser_ && browser_->profile()->IsManaged()) {
209 #if defined(ENABLE_MANAGED_USERS) 191 #if defined(ENABLE_MANAGED_USERS)
210 ManagedUserService* service = ManagedUserServiceFactory::GetForProfile( 192 ManagedUserService* service = ManagedUserServiceFactory::GetForProfile(
211 browser_->profile()); 193 browser_->profile());
212 base::string16 custodian = UTF8ToUTF16(service->GetCustodianEmailAddress()); 194 base::string16 custodian = UTF8ToUTF16(service->GetCustodianEmailAddress());
213 return l10n_util::GetStringFUTF16(IDS_MANAGED_USER_INFO, custodian); 195 return l10n_util::GetStringFUTF16(IDS_MANAGED_USER_INFO, custodian);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 observer_->OnAvatarMenuChanged(this); 231 observer_->OnAvatarMenuChanged(this);
250 } 232 }
251 233
252 content::WebContents* AvatarMenu::BeginSignOut() { 234 content::WebContents* AvatarMenu::BeginSignOut() {
253 return menu_actions_->BeginSignOut(); 235 return menu_actions_->BeginSignOut();
254 } 236 }
255 237
256 void AvatarMenu::SetLogoutURL(const std::string& logout_url) { 238 void AvatarMenu::SetLogoutURL(const std::string& logout_url) {
257 menu_actions_->SetLogoutURL(logout_url); 239 menu_actions_->SetLogoutURL(logout_url);
258 } 240 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/avatar_menu.h ('k') | chrome/browser/profiles/avatar_menu_actions_desktop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698