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

Side by Side Diff: chrome/browser/ui/webui/signin/user_manager_screen_handler.cc

Issue 149883004: Fix sketchy User Manager code :( (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compile Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/profiles/profile_window.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ui/webui/signin/user_manager_screen_handler.h" 5 #include "chrome/browser/ui/webui/signin/user_manager_screen_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/value_conversions.h" 8 #include "base/value_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 if (status != Profile::CREATE_STATUS_INITIALIZED) 73 if (status != Profile::CREATE_STATUS_INITIALIZED)
74 return; 74 return;
75 profiles::FindOrCreateNewWindowForProfile( 75 profiles::FindOrCreateNewWindowForProfile(
76 profile, 76 profile,
77 chrome::startup::IS_PROCESS_STARTUP, 77 chrome::startup::IS_PROCESS_STARTUP,
78 chrome::startup::IS_FIRST_RUN, 78 chrome::startup::IS_FIRST_RUN,
79 desktop_type, 79 desktop_type,
80 false); 80 false);
81 } 81 }
82 82
83 // This callback is run after switching to a new profile has finished. This
84 // means either a new browser window has been opened, or an existing one
85 // has been found, which means we can safely close the User Manager without
86 // accidentally terminating the browser process. The task needs to be posted,
87 // as HideUserManager will end up destroying its WebContents, which will
88 // destruct the UserManagerScreenHandler as well.
89 void OnSwitchToProfileComplete() {
90 base::MessageLoop::current()->PostTask(
91 FROM_HERE,
92 base::Bind(&chrome::HideUserManager));
93 }
94
83 std::string GetAvatarImageAtIndex( 95 std::string GetAvatarImageAtIndex(
84 size_t index, const ProfileInfoCache& info_cache) { 96 size_t index, const ProfileInfoCache& info_cache) {
85 bool is_gaia_picture = 97 bool is_gaia_picture =
86 info_cache.IsUsingGAIAPictureOfProfileAtIndex(index) && 98 info_cache.IsUsingGAIAPictureOfProfileAtIndex(index) &&
87 info_cache.GetGAIAPictureOfProfileAtIndex(index); 99 info_cache.GetGAIAPictureOfProfileAtIndex(index);
88 100
89 gfx::Image icon = profiles::GetSizedAvatarIconWithBorder( 101 gfx::Image icon = profiles::GetSizedAvatarIconWithBorder(
90 info_cache.GetAvatarIconOfProfileAtIndex(index), 102 info_cache.GetAvatarIconOfProfileAtIndex(index),
91 is_gaia_picture, kAvatarIconSize, kAvatarIconSize); 103 is_gaia_picture, kAvatarIconSize, kAvatarIconSize);
92 return webui::GetBitmapDataUrl(icon.AsBitmap()); 104 return webui::GetBitmapDataUrl(icon.AsBitmap());
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 190
179 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { 191 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) {
180 SendUserList(); 192 SendUserList();
181 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen"); 193 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen");
182 desktop_type_ = chrome::GetHostDesktopTypeForNativeView( 194 desktop_type_ = chrome::GetHostDesktopTypeForNativeView(
183 web_ui()->GetWebContents()->GetView()->GetNativeView()); 195 web_ui()->GetWebContents()->GetView()->GetNativeView());
184 } 196 }
185 197
186 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { 198 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) {
187 profiles::CreateAndSwitchToNewProfile(desktop_type_, 199 profiles::CreateAndSwitchToNewProfile(desktop_type_,
188 base::Bind(&chrome::HideUserManager), 200 base::Bind(&OnSwitchToProfileComplete),
189 ProfileMetrics::ADD_NEW_USER_MANAGER); 201 ProfileMetrics::ADD_NEW_USER_MANAGER);
190 } 202 }
191 203
192 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( 204 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser(
193 const base::ListValue* args) { 205 const base::ListValue* args) {
194 base::string16 email_address; 206 base::string16 email_address;
195 if (!args->GetString(0, &email_address)) 207 if (!args->GetString(0, &email_address))
196 return; 208 return;
197 209
198 base::string16 display_name; 210 base::string16 display_name;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 return; 268 return;
257 269
258 g_browser_process->profile_manager()->ScheduleProfileForDeletion( 270 g_browser_process->profile_manager()->ScheduleProfileForDeletion(
259 profile_path, 271 profile_path,
260 base::Bind(&OpenNewWindowForProfile, desktop_type_)); 272 base::Bind(&OpenNewWindowForProfile, desktop_type_));
261 ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::PROFILE_DELETED); 273 ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::PROFILE_DELETED);
262 } 274 }
263 275
264 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { 276 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) {
265 profiles::SwitchToGuestProfile(desktop_type_, 277 profiles::SwitchToGuestProfile(desktop_type_,
266 base::Bind(&chrome::HideUserManager)); 278 base::Bind(&OnSwitchToProfileComplete));
267 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST); 279 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST);
268 } 280 }
269 281
270 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { 282 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) {
271 base::string16 email_address; 283 base::string16 email_address;
272 base::string16 display_name; 284 base::string16 display_name;
273 285
274 if (!args->GetString(0, &email_address) || 286 if (!args->GetString(0, &email_address) ||
275 !args->GetString(1, &display_name)) { 287 !args->GetString(1, &display_name)) {
276 NOTREACHED(); 288 NOTREACHED();
(...skipping 16 matching lines...) Expand all
293 // we have to validate in (secure) C++ code that it really is a profile 305 // we have to validate in (secure) C++ code that it really is a profile
294 // not needing authentication. If it is, just ignore the "launch" request. 306 // not needing authentication. If it is, just ignore the "launch" request.
295 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) 307 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index))
296 return; 308 return;
297 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); 309 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY);
298 310
299 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); 311 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index);
300 profiles::SwitchToProfile(path, 312 profiles::SwitchToProfile(path,
301 desktop_type_, 313 desktop_type_,
302 false, /* reuse any existing windows */ 314 false, /* reuse any existing windows */
303 base::Bind(&chrome::HideUserManager), 315 base::Bind(&OnSwitchToProfileComplete),
304 ProfileMetrics::SWITCH_PROFILE_MANAGER); 316 ProfileMetrics::SWITCH_PROFILE_MANAGER);
305 } 317 }
306 318
307 void UserManagerScreenHandler::OnClientLoginSuccess( 319 void UserManagerScreenHandler::OnClientLoginSuccess(
308 const ClientLoginResult& result) { 320 const ClientLoginResult& result) {
309 chrome::SetLocalAuthCredentials(authenticating_profile_index_, 321 chrome::SetLocalAuthCredentials(authenticating_profile_index_,
310 password_attempt_); 322 password_attempt_);
311 ReportAuthenticationResult(true, ProfileMetrics::AUTH_ONLINE); 323 ReportAuthenticationResult(true, ProfileMetrics::AUTH_ONLINE);
312 } 324 }
313 325
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 password_attempt_.clear(); 477 password_attempt_.clear();
466 478
467 if (success) { 479 if (success) {
468 ProfileInfoCache& info_cache = 480 ProfileInfoCache& info_cache =
469 g_browser_process->profile_manager()->GetProfileInfoCache(); 481 g_browser_process->profile_manager()->GetProfileInfoCache();
470 info_cache.SetProfileSigninRequiredAtIndex( 482 info_cache.SetProfileSigninRequiredAtIndex(
471 authenticating_profile_index_, false); 483 authenticating_profile_index_, false);
472 base::FilePath path = info_cache.GetPathOfProfileAtIndex( 484 base::FilePath path = info_cache.GetPathOfProfileAtIndex(
473 authenticating_profile_index_); 485 authenticating_profile_index_);
474 profiles::SwitchToProfile(path, desktop_type_, true, 486 profiles::SwitchToProfile(path, desktop_type_, true,
475 base::Bind(&chrome::HideUserManager), 487 base::Bind(&OnSwitchToProfileComplete),
476 ProfileMetrics::SWITCH_PROFILE_UNLOCK); 488 ProfileMetrics::SWITCH_PROFILE_UNLOCK);
477 } else { 489 } else {
478 web_ui()->CallJavascriptFunction( 490 web_ui()->CallJavascriptFunction(
479 "cr.ui.Oobe.showSignInError", 491 "cr.ui.Oobe.showSignInError",
480 base::FundamentalValue(0), 492 base::FundamentalValue(0),
481 base::StringValue( 493 base::StringValue(
482 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), 494 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)),
483 base::StringValue(""), 495 base::StringValue(""),
484 base::FundamentalValue(0)); 496 base::FundamentalValue(0));
485 } 497 }
486 } 498 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_window.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698