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

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

Issue 20656002: Add profile selector menu to app list. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: undo app_list_service_mac changes Created 7 years, 4 months 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_model.h" 5 #include "chrome/browser/profiles/avatar_menu_model.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 content::NotificationService::AllSources()); 134 content::NotificationService::AllSources());
135 135
136 // Build the initial menu. 136 // Build the initial menu.
137 RebuildMenu(); 137 RebuildMenu();
138 } 138 }
139 139
140 AvatarMenuModel::~AvatarMenuModel() { 140 AvatarMenuModel::~AvatarMenuModel() {
141 ClearMenu(); 141 ClearMenu();
142 } 142 }
143 143
144 AvatarMenuModel::Item::Item(size_t model_index, const gfx::Image& icon)
145 : icon(icon),
146 active(false),
147 signed_in(false),
148 signin_required(false),
149 model_index(model_index) {
150 }
151
152 AvatarMenuModel::Item::~Item() {
153 }
154
155 void AvatarMenuModel::SwitchToProfile(size_t index, bool always_create) { 144 void AvatarMenuModel::SwitchToProfile(size_t index, bool always_create) {
156 DCHECK(profiles::IsMultipleProfilesEnabled() || 145 DCHECK(profiles::IsMultipleProfilesEnabled() ||
157 index == GetActiveProfileIndex()); 146 index == GetActiveProfileIndex());
158 const Item& item = GetItemAt(index); 147 const ui::AvatarMenuItemModel& item = GetItemAt(index);
159 base::FilePath path = 148 base::FilePath path =
160 profile_info_->GetPathOfProfileAtIndex(item.model_index); 149 profile_info_->GetPathOfProfileAtIndex(item.model_index);
161 150
162 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); 151 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop();
163 if (browser_) 152 if (browser_)
164 desktop_type = browser_->host_desktop_type(); 153 desktop_type = browser_->host_desktop_type();
165 154
166 profiles::SwitchToProfile(path, desktop_type, always_create); 155 profiles::SwitchToProfile(path, desktop_type, always_create);
167 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_ICON); 156 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_ICON);
168 } 157 }
(...skipping 17 matching lines...) Expand all
186 if (!browser) { 175 if (!browser) {
187 const Browser::CreateParams params(ProfileManager::GetLastUsedProfile(), 176 const Browser::CreateParams params(ProfileManager::GetLastUsedProfile(),
188 chrome::GetActiveDesktop()); 177 chrome::GetActiveDesktop());
189 browser = new Browser(params); 178 browser = new Browser(params);
190 } 179 }
191 chrome::ShowSettingsSubPage(browser, chrome::kCreateProfileSubPage); 180 chrome::ShowSettingsSubPage(browser, chrome::kCreateProfileSubPage);
192 ProfileMetrics::LogProfileAddNewUser(type); 181 ProfileMetrics::LogProfileAddNewUser(type);
193 } 182 }
194 183
195 base::FilePath AvatarMenuModel::GetProfilePath(size_t index) { 184 base::FilePath AvatarMenuModel::GetProfilePath(size_t index) {
196 const Item& item = GetItemAt(index); 185 const ui::AvatarMenuItemModel& item = GetItemAt(index);
197 return profile_info_->GetPathOfProfileAtIndex(item.model_index); 186 return profile_info_->GetPathOfProfileAtIndex(item.model_index);
198 } 187 }
199 188
200 // static 189 // static
201 void AvatarMenuModel::SwitchToGuestProfileWindow(Browser* browser) { 190 void AvatarMenuModel::SwitchToGuestProfileWindow(Browser* browser) {
202 ProfileManager* profile_manager = g_browser_process->profile_manager(); 191 ProfileManager* profile_manager = g_browser_process->profile_manager();
203 profile_manager->CreateProfileAsync(ProfileManager::GetGuestProfilePath(), 192 profile_manager->CreateProfileAsync(ProfileManager::GetGuestProfilePath(),
204 base::Bind(&OnGuestProfileCreated, 193 base::Bind(&OnGuestProfileCreated,
205 false, 194 false,
206 browser->host_desktop_type()), 195 browser->host_desktop_type()),
(...skipping 18 matching lines...) Expand all
225 else 214 else
226 active_profile = browser_->profile(); 215 active_profile = browser_->profile();
227 216
228 size_t index = 217 size_t index =
229 profile_info_->GetIndexOfProfileWithPath(active_profile->GetPath()); 218 profile_info_->GetIndexOfProfileWithPath(active_profile->GetPath());
230 219
231 DCHECK_LT(index, items_.size()); 220 DCHECK_LT(index, items_.size());
232 return index; 221 return index;
233 } 222 }
234 223
235 const AvatarMenuModel::Item& AvatarMenuModel::GetItemAt(size_t index) { 224 const ui::AvatarMenuItemModel& AvatarMenuModel::GetItemAt(size_t index) {
236 DCHECK_LT(index, items_.size()); 225 DCHECK_LT(index, items_.size());
237 return *items_[index]; 226 return *items_[index];
238 } 227 }
239 228
240 bool AvatarMenuModel::ShouldShowAddNewProfileLink() const { 229 bool AvatarMenuModel::ShouldShowAddNewProfileLink() const {
241 #if defined(ENABLE_MANAGED_USERS) 230 #if defined(ENABLE_MANAGED_USERS)
242 // |browser_| can be NULL in unit_tests. 231 // |browser_| can be NULL in unit_tests.
243 return !browser_ || 232 return !browser_ ||
244 !ManagedUserService::ProfileIsManaged(browser_->profile()); 233 !ManagedUserService::ProfileIsManaged(browser_->profile());
245 #endif 234 #endif
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 return profiles::IsNewProfileManagementEnabled() || 282 return profiles::IsNewProfileManagementEnabled() ||
294 (g_browser_process->profile_manager() && 283 (g_browser_process->profile_manager() &&
295 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1); 284 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1);
296 } 285 }
297 return false; 286 return false;
298 } 287 }
299 288
300 void AvatarMenuModel::RebuildMenu() { 289 void AvatarMenuModel::RebuildMenu() {
301 ClearMenu(); 290 ClearMenu();
302 291
303 const size_t count = profile_info_->GetNumberOfProfiles(); 292 profiles::PopulateAvatarMenuItemModels(items_,
304 for (size_t i = 0; i < count; ++i) { 293 profile_info_,
305 bool is_gaia_picture = 294 browser_->profile()->GetPath());
tapted 2013/07/31 05:43:53 The old code had an `if (browser_)` - is that stil
calamity 2013/08/01 08:35:45 Done.
306 profile_info_->IsUsingGAIAPictureOfProfileAtIndex(i) &&
307 profile_info_->GetGAIAPictureOfProfileAtIndex(i);
308
309 gfx::Image icon = profile_info_->GetAvatarIconOfProfileAtIndex(i);
310 if (!CommandLine::ForCurrentProcess()->HasSwitch(
311 switches::kNewProfileManagement)) {
312 // old avatar menu uses resized-small images
313 icon = profiles::GetAvatarIconForMenu(icon, is_gaia_picture);
314 }
315
316 Item* item = new Item(i, icon);
317 item->name = profile_info_->GetNameOfProfileAtIndex(i);
318 item->sync_state = profile_info_->GetUserNameOfProfileAtIndex(i);
319 item->signed_in = !item->sync_state.empty();
320 if (!item->signed_in) {
321 item->sync_state = l10n_util::GetStringUTF16(
322 profile_info_->ProfileIsManagedAtIndex(i) ?
323 IDS_MANAGED_USER_AVATAR_LABEL : IDS_PROFILES_LOCAL_PROFILE_STATE);
324 }
325 if (browser_) {
326 base::FilePath path = profile_info_->GetPathOfProfileAtIndex(i);
327 item->active = browser_->profile()->GetPath() == path;
328 }
329 item->signin_required = profile_info_->ProfileIsSigninRequiredAtIndex(i);
330 items_.push_back(item);
331 }
332 } 295 }
333 296
334 void AvatarMenuModel::ClearMenu() { 297 void AvatarMenuModel::ClearMenu() {
335 STLDeleteElements(&items_); 298 STLDeleteElements(&items_);
336 } 299 }
337 300
338 301
339 content::WebContents* AvatarMenuModel::BeginSignOut() { 302 content::WebContents* AvatarMenuModel::BeginSignOut() {
340 ProfileManager* profile_manager = g_browser_process->profile_manager(); 303 ProfileManager* profile_manager = g_browser_process->profile_manager();
341 Profile* current_profile = browser_->profile(); 304 Profile* current_profile = browser_->profile();
(...skipping 18 matching lines...) Expand all
360 contents->GetController().LoadURL( 323 contents->GetController().LoadURL(
361 logout_url, content::Referrer(), 324 logout_url, content::Referrer(),
362 content::PAGE_TRANSITION_GENERATED, std::string()); 325 content::PAGE_TRANSITION_GENERATED, std::string());
363 326
364 // This object may be destructed when the menu closes but we need something 327 // This object may be destructed when the menu closes but we need something
365 // around to finish the sign-out process and close the profile windows. 328 // around to finish the sign-out process and close the profile windows.
366 new SignoutTracker(current_profile, GURL(landing_url), contents); 329 new SignoutTracker(current_profile, GURL(landing_url), contents);
367 330
368 return contents; // returned for testing purposes 331 return contents; // returned for testing purposes
369 } 332 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698