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

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

Issue 18615010: Refactor utility methods out of the ProfileManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix includes Created 7 years, 5 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"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/profiles/avatar_menu_model_observer.h" 14 #include "chrome/browser/profiles/avatar_menu_model_observer.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/profiles/profile_info_cache.h" 16 #include "chrome/browser/profiles/profile_info_cache.h"
17 #include "chrome/browser/profiles/profile_info_util.h" 17 #include "chrome/browser/profiles/profile_info_util.h"
18 #include "chrome/browser/profiles/profile_manager.h" 18 #include "chrome/browser/profiles/profile_manager.h"
19 #include "chrome/browser/profiles/profile_manager_util.h"
19 #include "chrome/browser/profiles/profile_metrics.h" 20 #include "chrome/browser/profiles/profile_metrics.h"
20 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_list.h" 22 #include "chrome/browser/ui/browser_list.h"
22 #include "chrome/browser/ui/browser_window.h" 23 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/browser/ui/chrome_pages.h" 24 #include "chrome/browser/ui/chrome_pages.h"
24 #include "chrome/browser/ui/host_desktop.h" 25 #include "chrome/browser/ui/host_desktop.h"
25 #include "chrome/browser/ui/startup/startup_browser_creator.h" 26 #include "chrome/browser/ui/startup/startup_browser_creator.h"
26 #include "chrome/common/chrome_notification_types.h" 27 #include "chrome/common/chrome_notification_types.h"
27 #include "chrome/common/chrome_switches.h" 28 #include "chrome/common/chrome_switches.h"
28 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
(...skipping 15 matching lines...) Expand all
44 45
45 namespace { 46 namespace {
46 47
47 void OnProfileCreated(bool always_create, 48 void OnProfileCreated(bool always_create,
48 chrome::HostDesktopType desktop_type, 49 chrome::HostDesktopType desktop_type,
49 Profile* profile, 50 Profile* profile,
50 Profile::CreateStatus status) { 51 Profile::CreateStatus status) {
51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
52 53
53 if (status == Profile::CREATE_STATUS_INITIALIZED) { 54 if (status == Profile::CREATE_STATUS_INITIALIZED) {
54 ProfileManager::FindOrCreateNewWindowForProfile( 55 profiles::FindOrCreateNewWindowForProfile(
55 profile, 56 profile,
56 chrome::startup::IS_NOT_PROCESS_STARTUP, 57 chrome::startup::IS_NOT_PROCESS_STARTUP,
57 chrome::startup::IS_NOT_FIRST_RUN, 58 chrome::startup::IS_NOT_FIRST_RUN,
58 desktop_type, 59 desktop_type,
59 always_create); 60 always_create);
60 } 61 }
61 } 62 }
62 63
63 // Constants for the show profile switcher experiment 64 // Constants for the show profile switcher experiment
64 const char kShowProfileSwitcherFieldTrialName[] = "ShowProfileSwitcher"; 65 const char kShowProfileSwitcherFieldTrialName[] = "ShowProfileSwitcher";
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 active(false), 134 active(false),
134 signed_in(false), 135 signed_in(false),
135 signin_required(false), 136 signin_required(false),
136 model_index(model_index) { 137 model_index(model_index) {
137 } 138 }
138 139
139 AvatarMenuModel::Item::~Item() { 140 AvatarMenuModel::Item::~Item() {
140 } 141 }
141 142
142 void AvatarMenuModel::SwitchToProfile(size_t index, bool always_create) { 143 void AvatarMenuModel::SwitchToProfile(size_t index, bool always_create) {
143 DCHECK(ProfileManager::IsMultipleProfilesEnabled() || 144 DCHECK(profiles::IsMultipleProfilesEnabled() ||
144 index == GetActiveProfileIndex()); 145 index == GetActiveProfileIndex());
145 const Item& item = GetItemAt(index); 146 const Item& item = GetItemAt(index);
146 base::FilePath path = 147 base::FilePath path =
147 profile_info_->GetPathOfProfileAtIndex(item.model_index); 148 profile_info_->GetPathOfProfileAtIndex(item.model_index);
148 149
149 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); 150 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop();
150 if (browser_) 151 if (browser_)
151 desktop_type = browser_->host_desktop_type(); 152 desktop_type = browser_->host_desktop_type();
152 153
153 g_browser_process->profile_manager()->CreateProfileAsync( 154 g_browser_process->profile_manager()->CreateProfileAsync(
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 // static 263 // static
263 bool AvatarMenuModel::ShouldShowAvatarMenu() { 264 bool AvatarMenuModel::ShouldShowAvatarMenu() {
264 #if defined(OS_CHROMEOS) 265 #if defined(OS_CHROMEOS)
265 // On Chrome OS we use different UI for multi-profiles. 266 // On Chrome OS we use different UI for multi-profiles.
266 return false; 267 return false;
267 #endif 268 #endif
268 269
269 if (base::FieldTrialList::FindFullName(kShowProfileSwitcherFieldTrialName) == 270 if (base::FieldTrialList::FindFullName(kShowProfileSwitcherFieldTrialName) ==
270 kAlwaysShowSwitcherGroupName) { 271 kAlwaysShowSwitcherGroupName) {
271 // We should only be in this group when multi-profiles is enabled. 272 // We should only be in this group when multi-profiles is enabled.
272 DCHECK(ProfileManager::IsMultipleProfilesEnabled()); 273 DCHECK(profiles::IsMultipleProfilesEnabled());
273 return true; 274 return true;
274 } 275 }
275 return ProfileManager::IsMultipleProfilesEnabled() && 276 return profiles::IsMultipleProfilesEnabled() &&
276 g_browser_process->profile_manager() && 277 g_browser_process->profile_manager() &&
277 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1; 278 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1;
278 } 279 }
279 280
280 void AvatarMenuModel::RebuildMenu() { 281 void AvatarMenuModel::RebuildMenu() {
281 ClearMenu(); 282 ClearMenu();
282 283
283 const size_t count = profile_info_->GetNumberOfProfiles(); 284 const size_t count = profile_info_->GetNumberOfProfiles();
284 for (size_t i = 0; i < count; ++i) { 285 for (size_t i = 0; i < count; ++i) {
285 bool is_gaia_picture = 286 bool is_gaia_picture =
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 contents->GetController().LoadURL( 341 contents->GetController().LoadURL(
341 logout_url, content::Referrer(), 342 logout_url, content::Referrer(),
342 content::PAGE_TRANSITION_GENERATED, std::string()); 343 content::PAGE_TRANSITION_GENERATED, std::string());
343 344
344 // This object may be destructed when the menu closes but we need something 345 // This object may be destructed when the menu closes but we need something
345 // around to finish the sign-out process and close the profile windows. 346 // around to finish the sign-out process and close the profile windows.
346 new SignoutTracker(current_profile, GURL(landing_url), contents); 347 new SignoutTracker(current_profile, GURL(landing_url), contents);
347 348
348 return contents; // returned for testing purposes 349 return contents; // returned for testing purposes
349 } 350 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698