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

Side by Side Diff: chrome/browser/chromeos/login/screens/user_selection_screen.cc

Issue 1463753002: ChromeOS: This CL fixes bug in UserManager::GetKnownUserAccountId . (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after review. Created 5 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/chromeos/login/screens/user_selection_screen.h" 5 #include "chrome/browser/chromeos/login/screens/user_selection_screen.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // At this point the reason for invalid token should be already set. If not, 239 // At this point the reason for invalid token should be already set. If not,
240 // this might be a leftover from an old version. 240 // this might be a leftover from an old version.
241 if (token_status == user_manager::User::OAUTH2_TOKEN_STATUS_INVALID) 241 if (token_status == user_manager::User::OAUTH2_TOKEN_STATUS_INVALID)
242 RecordReauthReason(user->GetAccountId(), ReauthReason::OTHER); 242 RecordReauthReason(user->GetAccountId(), ReauthReason::OTHER);
243 243
244 return user->force_online_signin() || 244 return user->force_online_signin() ||
245 (token_status == user_manager::User::OAUTH2_TOKEN_STATUS_INVALID) || 245 (token_status == user_manager::User::OAUTH2_TOKEN_STATUS_INVALID) ||
246 (token_status == user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN); 246 (token_status == user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN);
247 } 247 }
248 248
249 // static
250 AccountId UserSelectionScreen::GetAccountIdOfKnownUser(
251 const std::string& user_id) {
252 if (user_id.empty())
253 return EmptyAccountId();
254
255 const AccountId initial_account_id = AccountId::FromUserEmail(user_id);
256
257 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
258 if (!user_manager)
259 return initial_account_id;
260
261 AccountId known_account_id(EmptyAccountId());
262 if (user_manager->GetKnownUserAccountId(initial_account_id,
263 &known_account_id))
264 return known_account_id;
265
266 return initial_account_id;
267 }
268
269 void UserSelectionScreen::SetHandler(LoginDisplayWebUIHandler* handler) { 249 void UserSelectionScreen::SetHandler(LoginDisplayWebUIHandler* handler) {
270 handler_ = handler; 250 handler_ = handler;
271 } 251 }
272 252
273 void UserSelectionScreen::SetView(UserBoardView* view) { 253 void UserSelectionScreen::SetView(UserBoardView* view) {
274 view_ = view; 254 view_ = view;
275 } 255 }
276 256
277 void UserSelectionScreen::Init(const user_manager::UserList& users, 257 void UserSelectionScreen::Init(const user_manager::UserList& users,
278 bool show_guest) { 258 bool show_guest) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 base::ListValue users_list; 342 base::ListValue users_list;
363 343
364 // TODO(nkostylev): Move to a separate method in UserManager. 344 // TODO(nkostylev): Move to a separate method in UserManager.
365 // http://crbug.com/230852 345 // http://crbug.com/230852
366 bool single_user = users_.size() == 1; 346 bool single_user = users_.size() == 1;
367 bool is_signin_to_add = LoginDisplayHostImpl::default_host() && 347 bool is_signin_to_add = LoginDisplayHostImpl::default_host() &&
368 user_manager::UserManager::Get()->IsUserLoggedIn(); 348 user_manager::UserManager::Get()->IsUserLoggedIn();
369 std::string owner_email; 349 std::string owner_email;
370 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, 350 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner,
371 &owner_email); 351 &owner_email);
372 const AccountId owner(GetAccountIdOfKnownUser(owner_email)); 352 const AccountId owner = user_manager::UserManager::GetKnownUserAccountId(
353 owner_email, std::string());
373 354
374 policy::BrowserPolicyConnectorChromeOS* connector = 355 policy::BrowserPolicyConnectorChromeOS* connector =
375 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 356 g_browser_process->platform_part()->browser_policy_connector_chromeos();
376 bool is_enterprise_managed = connector->IsEnterpriseManaged(); 357 bool is_enterprise_managed = connector->IsEnterpriseManaged();
377 358
378 const user_manager::UserList users_to_send = 359 const user_manager::UserList users_to_send =
379 PrepareUserListForSending(users_, owner, is_signin_to_add); 360 PrepareUserListForSending(users_, owner, is_signin_to_add);
380 361
381 user_auth_type_map_.clear(); 362 user_auth_type_map_.clear();
382 363
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 token_handle_util_->MarkHandleInvalid(account_id); 431 token_handle_util_->MarkHandleInvalid(account_id);
451 SetAuthType(account_id.GetUserEmail(), ONLINE_SIGN_IN, base::string16()); 432 SetAuthType(account_id.GetUserEmail(), ONLINE_SIGN_IN, base::string16());
452 } 433 }
453 } 434 }
454 435
455 // EasyUnlock stuff 436 // EasyUnlock stuff
456 437
457 void UserSelectionScreen::SetAuthType(const std::string& user_id, 438 void UserSelectionScreen::SetAuthType(const std::string& user_id,
458 AuthType auth_type, 439 AuthType auth_type,
459 const base::string16& initial_value) { 440 const base::string16& initial_value) {
460 const AccountId& account_id = GetAccountIdOfKnownUser(user_id); 441 const AccountId& account_id =
442 user_manager::UserManager::GetKnownUserAccountId(user_id, std::string());
461 if (GetAuthType(account_id.GetUserEmail()) == FORCE_OFFLINE_PASSWORD) 443 if (GetAuthType(account_id.GetUserEmail()) == FORCE_OFFLINE_PASSWORD)
462 return; 444 return;
463 DCHECK(GetAuthType(account_id.GetUserEmail()) != FORCE_OFFLINE_PASSWORD || 445 DCHECK(GetAuthType(account_id.GetUserEmail()) != FORCE_OFFLINE_PASSWORD ||
464 auth_type == FORCE_OFFLINE_PASSWORD); 446 auth_type == FORCE_OFFLINE_PASSWORD);
465 user_auth_type_map_[account_id] = auth_type; 447 user_auth_type_map_[account_id] = auth_type;
466 view_->SetAuthType(account_id, auth_type, initial_value); 448 view_->SetAuthType(account_id, auth_type, initial_value);
467 } 449 }
468 450
469 proximity_auth::ScreenlockBridge::LockHandler::AuthType 451 proximity_auth::ScreenlockBridge::LockHandler::AuthType
470 UserSelectionScreen::GetAuthType(const std::string& username) const { 452 UserSelectionScreen::GetAuthType(const std::string& username) const {
471 const AccountId& account_id = GetAccountIdOfKnownUser(username); 453 const AccountId& account_id =
454 user_manager::UserManager::GetKnownUserAccountId(username, std::string());
472 if (user_auth_type_map_.find(account_id) == user_auth_type_map_.end()) 455 if (user_auth_type_map_.find(account_id) == user_auth_type_map_.end())
473 return OFFLINE_PASSWORD; 456 return OFFLINE_PASSWORD;
474 return user_auth_type_map_.find(account_id)->second; 457 return user_auth_type_map_.find(account_id)->second;
475 } 458 }
476 459
477 proximity_auth::ScreenlockBridge::LockHandler::ScreenType 460 proximity_auth::ScreenlockBridge::LockHandler::ScreenType
478 UserSelectionScreen::GetScreenType() const { 461 UserSelectionScreen::GetScreenType() const {
479 if (display_type_ == OobeUI::kLockDisplay) 462 if (display_type_ == OobeUI::kLockDisplay)
480 return LOCK_SCREEN; 463 return LOCK_SCREEN;
481 464
482 if (display_type_ == OobeUI::kLoginDisplay) 465 if (display_type_ == OobeUI::kLoginDisplay)
483 return SIGNIN_SCREEN; 466 return SIGNIN_SCREEN;
484 467
485 return OTHER_SCREEN; 468 return OTHER_SCREEN;
486 } 469 }
487 470
488 void UserSelectionScreen::ShowBannerMessage(const base::string16& message) { 471 void UserSelectionScreen::ShowBannerMessage(const base::string16& message) {
489 view_->ShowBannerMessage(message); 472 view_->ShowBannerMessage(message);
490 } 473 }
491 474
492 void UserSelectionScreen::ShowUserPodCustomIcon( 475 void UserSelectionScreen::ShowUserPodCustomIcon(
493 const std::string& user_id, 476 const std::string& user_id,
494 const proximity_auth::ScreenlockBridge::UserPodCustomIconOptions& 477 const proximity_auth::ScreenlockBridge::UserPodCustomIconOptions&
495 icon_options) { 478 icon_options) {
496 scoped_ptr<base::DictionaryValue> icon = icon_options.ToDictionaryValue(); 479 scoped_ptr<base::DictionaryValue> icon = icon_options.ToDictionaryValue();
497 if (!icon || icon->empty()) 480 if (!icon || icon->empty())
498 return; 481 return;
499 const AccountId account_id = GetAccountIdOfKnownUser(user_id); 482 const AccountId account_id =
483 user_manager::UserManager::GetKnownUserAccountId(user_id, std::string());
500 view_->ShowUserPodCustomIcon(account_id, *icon); 484 view_->ShowUserPodCustomIcon(account_id, *icon);
501 } 485 }
502 486
503 void UserSelectionScreen::HideUserPodCustomIcon(const std::string& user_id) { 487 void UserSelectionScreen::HideUserPodCustomIcon(const std::string& user_id) {
504 const AccountId account_id = GetAccountIdOfKnownUser(user_id); 488 const AccountId account_id =
489 user_manager::UserManager::GetKnownUserAccountId(user_id, std::string());
505 view_->HideUserPodCustomIcon(account_id); 490 view_->HideUserPodCustomIcon(account_id);
506 } 491 }
507 492
508 void UserSelectionScreen::EnableInput() { 493 void UserSelectionScreen::EnableInput() {
509 // If Easy Unlock fails to unlock the screen, re-enable the password input. 494 // If Easy Unlock fails to unlock the screen, re-enable the password input.
510 // This is only necessary on the lock screen, because the error handling for 495 // This is only necessary on the lock screen, because the error handling for
511 // the sign-in screen uses a different code path. 496 // the sign-in screen uses a different code path.
512 if (ScreenLocker::default_screen_locker()) 497 if (ScreenLocker::default_screen_locker())
513 ScreenLocker::default_screen_locker()->EnableInput(); 498 ScreenLocker::default_screen_locker()->EnableInput();
514 } 499 }
515 500
516 void UserSelectionScreen::Unlock(const std::string& user_email) { 501 void UserSelectionScreen::Unlock(const std::string& user_email) {
517 DCHECK_EQ(GetScreenType(), LOCK_SCREEN); 502 DCHECK_EQ(GetScreenType(), LOCK_SCREEN);
518 ScreenLocker::Hide(); 503 ScreenLocker::Hide();
519 } 504 }
520 505
521 void UserSelectionScreen::AttemptEasySignin(const std::string& user_id, 506 void UserSelectionScreen::AttemptEasySignin(const std::string& user_id,
522 const std::string& secret, 507 const std::string& secret,
523 const std::string& key_label) { 508 const std::string& key_label) {
524 DCHECK_EQ(GetScreenType(), SIGNIN_SCREEN); 509 DCHECK_EQ(GetScreenType(), SIGNIN_SCREEN);
525 510
526 UserContext user_context(GetAccountIdOfKnownUser(user_id)); 511 UserContext user_context(
512 user_manager::UserManager::GetKnownUserAccountId(user_id, std::string()));
527 user_context.SetAuthFlow(UserContext::AUTH_FLOW_EASY_UNLOCK); 513 user_context.SetAuthFlow(UserContext::AUTH_FLOW_EASY_UNLOCK);
528 user_context.SetKey(Key(secret)); 514 user_context.SetKey(Key(secret));
529 user_context.GetKey()->SetLabel(key_label); 515 user_context.GetKey()->SetLabel(key_label);
530 516
531 login_display_delegate_->Login(user_context, SigninSpecifics()); 517 login_display_delegate_->Login(user_context, SigninSpecifics());
532 } 518 }
533 519
534 void UserSelectionScreen::HardLockPod(const AccountId& account_id) { 520 void UserSelectionScreen::HardLockPod(const AccountId& account_id) {
535 view_->SetAuthType(account_id, OFFLINE_PASSWORD, base::string16()); 521 view_->SetAuthType(account_id, OFFLINE_PASSWORD, base::string16());
536 EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id); 522 EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 // The user profile should exist if and only if this is the lock screen. 560 // The user profile should exist if and only if this is the lock screen.
575 DCHECK_EQ(!!profile, GetScreenType() == LOCK_SCREEN); 561 DCHECK_EQ(!!profile, GetScreenType() == LOCK_SCREEN);
576 562
577 if (!profile) 563 if (!profile)
578 profile = profile_helper->GetSigninProfile(); 564 profile = profile_helper->GetSigninProfile();
579 565
580 return EasyUnlockService::Get(profile); 566 return EasyUnlockService::Get(profile);
581 } 567 }
582 568
583 } // namespace chromeos 569 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698