Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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. | |
| 87 void OnSwitchToProfileComplete() { | |
| 88 base::MessageLoop::current()->PostTask( | |
|
Alexei Svitkine (slow)
2014/02/06 22:02:12
Your comment should explain why this is posted rat
noms (inactive)
2014/02/06 22:51:34
Done.
| |
| 89 FROM_HERE, | |
| 90 base::Bind(&chrome::HideUserManager)); | |
| 91 } | |
| 92 | |
| 83 std::string GetAvatarImageAtIndex( | 93 std::string GetAvatarImageAtIndex( |
| 84 size_t index, const ProfileInfoCache& info_cache) { | 94 size_t index, const ProfileInfoCache& info_cache) { |
| 85 bool is_gaia_picture = | 95 bool is_gaia_picture = |
| 86 info_cache.IsUsingGAIAPictureOfProfileAtIndex(index) && | 96 info_cache.IsUsingGAIAPictureOfProfileAtIndex(index) && |
| 87 info_cache.GetGAIAPictureOfProfileAtIndex(index); | 97 info_cache.GetGAIAPictureOfProfileAtIndex(index); |
| 88 | 98 |
| 89 gfx::Image icon = profiles::GetSizedAvatarIconWithBorder( | 99 gfx::Image icon = profiles::GetSizedAvatarIconWithBorder( |
| 90 info_cache.GetAvatarIconOfProfileAtIndex(index), | 100 info_cache.GetAvatarIconOfProfileAtIndex(index), |
| 91 is_gaia_picture, kAvatarIconSize, kAvatarIconSize); | 101 is_gaia_picture, kAvatarIconSize, kAvatarIconSize); |
| 92 return webui::GetBitmapDataUrl(icon.AsBitmap()); | 102 return webui::GetBitmapDataUrl(icon.AsBitmap()); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 | 188 |
| 179 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { | 189 void UserManagerScreenHandler::HandleInitialize(const base::ListValue* args) { |
| 180 SendUserList(); | 190 SendUserList(); |
| 181 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen"); | 191 web_ui()->CallJavascriptFunction("cr.ui.Oobe.showUserManagerScreen"); |
| 182 desktop_type_ = chrome::GetHostDesktopTypeForNativeView( | 192 desktop_type_ = chrome::GetHostDesktopTypeForNativeView( |
| 183 web_ui()->GetWebContents()->GetView()->GetNativeView()); | 193 web_ui()->GetWebContents()->GetView()->GetNativeView()); |
| 184 } | 194 } |
| 185 | 195 |
| 186 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { | 196 void UserManagerScreenHandler::HandleAddUser(const base::ListValue* args) { |
| 187 profiles::CreateAndSwitchToNewProfile(desktop_type_, | 197 profiles::CreateAndSwitchToNewProfile(desktop_type_, |
| 188 base::Bind(&chrome::HideUserManager), | 198 base::Bind(&OnSwitchToProfileComplete), |
| 189 ProfileMetrics::ADD_NEW_USER_MANAGER); | 199 ProfileMetrics::ADD_NEW_USER_MANAGER); |
| 190 } | 200 } |
| 191 | 201 |
| 192 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( | 202 void UserManagerScreenHandler::HandleAuthenticatedLaunchUser( |
| 193 const base::ListValue* args) { | 203 const base::ListValue* args) { |
| 194 base::string16 email_address; | 204 base::string16 email_address; |
| 195 if (!args->GetString(0, &email_address)) | 205 if (!args->GetString(0, &email_address)) |
| 196 return; | 206 return; |
| 197 | 207 |
| 198 base::string16 display_name; | 208 base::string16 display_name; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 return; | 266 return; |
| 257 | 267 |
| 258 g_browser_process->profile_manager()->ScheduleProfileForDeletion( | 268 g_browser_process->profile_manager()->ScheduleProfileForDeletion( |
| 259 profile_path, | 269 profile_path, |
| 260 base::Bind(&OpenNewWindowForProfile, desktop_type_)); | 270 base::Bind(&OpenNewWindowForProfile, desktop_type_)); |
| 261 ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::PROFILE_DELETED); | 271 ProfileMetrics::LogProfileDeleteUser(ProfileMetrics::PROFILE_DELETED); |
| 262 } | 272 } |
| 263 | 273 |
| 264 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { | 274 void UserManagerScreenHandler::HandleLaunchGuest(const base::ListValue* args) { |
| 265 profiles::SwitchToGuestProfile(desktop_type_, | 275 profiles::SwitchToGuestProfile(desktop_type_, |
| 266 base::Bind(&chrome::HideUserManager)); | 276 base::Bind(&OnSwitchToProfileComplete)); |
| 267 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST); | 277 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_GUEST); |
| 268 } | 278 } |
| 269 | 279 |
| 270 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { | 280 void UserManagerScreenHandler::HandleLaunchUser(const base::ListValue* args) { |
| 271 base::string16 email_address; | 281 base::string16 email_address; |
| 272 base::string16 display_name; | 282 base::string16 display_name; |
| 273 | 283 |
| 274 if (!args->GetString(0, &email_address) || | 284 if (!args->GetString(0, &email_address) || |
| 275 !args->GetString(1, &display_name)) { | 285 !args->GetString(1, &display_name)) { |
| 276 NOTREACHED(); | 286 NOTREACHED(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 293 // we have to validate in (secure) C++ code that it really is a profile | 303 // 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. | 304 // not needing authentication. If it is, just ignore the "launch" request. |
| 295 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) | 305 if (info_cache.ProfileIsSigninRequiredAtIndex(profile_index)) |
| 296 return; | 306 return; |
| 297 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); | 307 ProfileMetrics::LogProfileAuthResult(ProfileMetrics::AUTH_UNNECESSARY); |
| 298 | 308 |
| 299 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); | 309 base::FilePath path = info_cache.GetPathOfProfileAtIndex(profile_index); |
| 300 profiles::SwitchToProfile(path, | 310 profiles::SwitchToProfile(path, |
| 301 desktop_type_, | 311 desktop_type_, |
| 302 false, /* reuse any existing windows */ | 312 false, /* reuse any existing windows */ |
| 303 base::Bind(&chrome::HideUserManager), | 313 base::Bind(&OnSwitchToProfileComplete), |
| 304 ProfileMetrics::SWITCH_PROFILE_MANAGER); | 314 ProfileMetrics::SWITCH_PROFILE_MANAGER); |
| 305 } | 315 } |
| 306 | 316 |
| 307 void UserManagerScreenHandler::OnClientLoginSuccess( | 317 void UserManagerScreenHandler::OnClientLoginSuccess( |
| 308 const ClientLoginResult& result) { | 318 const ClientLoginResult& result) { |
| 309 chrome::SetLocalAuthCredentials(authenticating_profile_index_, | 319 chrome::SetLocalAuthCredentials(authenticating_profile_index_, |
| 310 password_attempt_); | 320 password_attempt_); |
| 311 ReportAuthenticationResult(true, ProfileMetrics::AUTH_ONLINE); | 321 ReportAuthenticationResult(true, ProfileMetrics::AUTH_ONLINE); |
| 312 } | 322 } |
| 313 | 323 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 password_attempt_.clear(); | 475 password_attempt_.clear(); |
| 466 | 476 |
| 467 if (success) { | 477 if (success) { |
| 468 ProfileInfoCache& info_cache = | 478 ProfileInfoCache& info_cache = |
| 469 g_browser_process->profile_manager()->GetProfileInfoCache(); | 479 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 470 info_cache.SetProfileSigninRequiredAtIndex( | 480 info_cache.SetProfileSigninRequiredAtIndex( |
| 471 authenticating_profile_index_, false); | 481 authenticating_profile_index_, false); |
| 472 base::FilePath path = info_cache.GetPathOfProfileAtIndex( | 482 base::FilePath path = info_cache.GetPathOfProfileAtIndex( |
| 473 authenticating_profile_index_); | 483 authenticating_profile_index_); |
| 474 profiles::SwitchToProfile(path, desktop_type_, true, | 484 profiles::SwitchToProfile(path, desktop_type_, true, |
| 475 base::Bind(&chrome::HideUserManager), | 485 base::Bind(&OnSwitchToProfileComplete), |
| 476 ProfileMetrics::SWITCH_PROFILE_UNLOCK); | 486 ProfileMetrics::SWITCH_PROFILE_UNLOCK); |
| 477 } else { | 487 } else { |
| 478 web_ui()->CallJavascriptFunction( | 488 web_ui()->CallJavascriptFunction( |
| 479 "cr.ui.Oobe.showSignInError", | 489 "cr.ui.Oobe.showSignInError", |
| 480 base::FundamentalValue(0), | 490 base::FundamentalValue(0), |
| 481 base::StringValue( | 491 base::StringValue( |
| 482 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), | 492 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_AUTHENTICATING)), |
| 483 base::StringValue(""), | 493 base::StringValue(""), |
| 484 base::FundamentalValue(0)); | 494 base::FundamentalValue(0)); |
| 485 } | 495 } |
| 486 } | 496 } |
| OLD | NEW |