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

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

Issue 16104008: First try at a user management screen for the desktop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clean up JS code Created 7 years, 6 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/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 22 matching lines...) Expand all
33 33
34 #if defined(ENABLE_MANAGED_USERS) 34 #if defined(ENABLE_MANAGED_USERS)
35 #include "chrome/browser/managed_mode/managed_user_service.h" 35 #include "chrome/browser/managed_mode/managed_user_service.h"
36 #include "chrome/browser/managed_mode/managed_user_service_factory.h" 36 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
37 #endif 37 #endif
38 38
39 using content::BrowserThread; 39 using content::BrowserThread;
40 40
41 namespace { 41 namespace {
42 42
43 void OnProfileCreated(bool always_create,
44 chrome::HostDesktopType desktop_type,
45 Profile* profile,
46 Profile::CreateStatus status) {
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
48
49 if (status == Profile::CREATE_STATUS_INITIALIZED) {
50 ProfileManager::FindOrCreateNewWindowForProfile(
51 profile,
52 chrome::startup::IS_NOT_PROCESS_STARTUP,
53 chrome::startup::IS_NOT_FIRST_RUN,
54 desktop_type,
55 always_create);
56 }
57 }
58
59 // Constants for the show profile switcher experiment 43 // Constants for the show profile switcher experiment
60 const char kShowProfileSwitcherFieldTrialName[] = "ShowProfileSwitcher"; 44 const char kShowProfileSwitcherFieldTrialName[] = "ShowProfileSwitcher";
61 const char kAlwaysShowSwitcherGroupName[] = "AlwaysShow"; 45 const char kAlwaysShowSwitcherGroupName[] = "AlwaysShow";
62 46
63 47
64 class SignoutTracker : public content::WebContentsObserver { 48 class SignoutTracker : public content::WebContentsObserver {
65 public: 49 public:
66 SignoutTracker(Profile* profile, const GURL& signout_landing_url, 50 SignoutTracker(Profile* profile, const GURL& signout_landing_url,
67 content::WebContents* contents); 51 content::WebContents* contents);
68 52
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 DCHECK(ProfileManager::IsMultipleProfilesEnabled() || 123 DCHECK(ProfileManager::IsMultipleProfilesEnabled() ||
140 index == GetActiveProfileIndex()); 124 index == GetActiveProfileIndex());
141 const Item& item = GetItemAt(index); 125 const Item& item = GetItemAt(index);
142 base::FilePath path = 126 base::FilePath path =
143 profile_info_->GetPathOfProfileAtIndex(item.model_index); 127 profile_info_->GetPathOfProfileAtIndex(item.model_index);
144 128
145 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); 129 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop();
146 if (browser_) 130 if (browser_)
147 desktop_type = browser_->host_desktop_type(); 131 desktop_type = browser_->host_desktop_type();
148 132
149 g_browser_process->profile_manager()->CreateProfileAsync( 133 ProfileManager::SwitchToProfile(path, desktop_type, always_create);
150 path,
151 base::Bind(&OnProfileCreated,
152 always_create,
153 desktop_type),
154 string16(),
155 string16(),
156 false);
157
158 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_ICON); 134 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_ICON);
159 } 135 }
160 136
161 void AvatarMenuModel::EditProfile(size_t index) { 137 void AvatarMenuModel::EditProfile(size_t index) {
162 Browser* browser = browser_; 138 Browser* browser = browser_;
163 if (!browser) { 139 if (!browser) {
164 Profile* profile = g_browser_process->profile_manager()->GetProfileByPath( 140 Profile* profile = g_browser_process->profile_manager()->GetProfileByPath(
165 profile_info_->GetPathOfProfileAtIndex(GetItemAt(index).model_index)); 141 profile_info_->GetPathOfProfileAtIndex(GetItemAt(index).model_index));
166 browser = new Browser(Browser::CreateParams(profile, 142 browser = new Browser(Browser::CreateParams(profile,
167 chrome::GetActiveDesktop())); 143 chrome::GetActiveDesktop()));
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 contents->GetController().LoadURL( 303 contents->GetController().LoadURL(
328 logout_url, content::Referrer(), 304 logout_url, content::Referrer(),
329 content::PAGE_TRANSITION_GENERATED, std::string()); 305 content::PAGE_TRANSITION_GENERATED, std::string());
330 306
331 // This object may be destructed when the menu closes but we need something 307 // This object may be destructed when the menu closes but we need something
332 // around to finish the sign-out process and close the profile windows. 308 // around to finish the sign-out process and close the profile windows.
333 new SignoutTracker(current_profile, GURL(landing_url), contents); 309 new SignoutTracker(current_profile, GURL(landing_url), contents);
334 310
335 return contents; // returned for testing purposes 311 return contents; // returned for testing purposes
336 } 312 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698