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

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

Issue 2903353003: Adding mojo calls for easy unlock service (Closed)
Patch Set: comments and rebase Created 3 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 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 users_to_send.erase(users_to_send.begin() + kMaxUsers); 475 users_to_send.erase(users_to_send.begin() + kMaxUsers);
476 } else if (users_to_send.size() < kMaxUsers) { 476 } else if (users_to_send.size() < kMaxUsers) {
477 users_to_send.push_back(*it); 477 users_to_send.push_back(*it);
478 } 478 }
479 } 479 }
480 } 480 }
481 return users_to_send; 481 return users_to_send;
482 } 482 }
483 483
484 void UserSelectionScreen::SendUserList() { 484 void UserSelectionScreen::SendUserList() {
485 base::ListValue users_list; 485 std::unique_ptr<base::ListValue> users_list = PrepareUserList();
486 486 handler_->LoadUsers(users_to_send_, *users_list);
487 // TODO(nkostylev): Move to a separate method in UserManager.
488 // http://crbug.com/230852
489 bool single_user = users_.size() == 1;
490 bool is_signin_to_add = LoginDisplayHost::default_host() &&
491 user_manager::UserManager::Get()->IsUserLoggedIn();
492 std::string owner_email;
493 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner,
494 &owner_email);
495 const AccountId owner = user_manager::known_user::GetAccountId(
496 owner_email, std::string() /* id */, AccountType::UNKNOWN);
497
498 policy::BrowserPolicyConnectorChromeOS* connector =
499 g_browser_process->platform_part()->browser_policy_connector_chromeos();
500 bool is_enterprise_managed = connector->IsEnterpriseManaged();
501
502 const user_manager::UserList users_to_send =
503 PrepareUserListForSending(users_, owner, is_signin_to_add);
504
505 user_auth_type_map_.clear();
506
507 const std::vector<std::string> kEmptyRecommendedLocales;
508 for (user_manager::UserList::const_iterator it = users_to_send.begin();
509 it != users_to_send.end();
510 ++it) {
511 const AccountId& account_id = (*it)->GetAccountId();
512 bool is_owner = (account_id == owner);
513 const bool is_public_account =
514 ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT);
515 const AuthType initial_auth_type =
516 is_public_account ? EXPAND_THEN_USER_CLICK
517 : (ShouldForceOnlineSignIn(*it) ? ONLINE_SIGN_IN
518 : OFFLINE_PASSWORD);
519 user_auth_type_map_[account_id] = initial_auth_type;
520
521 auto user_dict = base::MakeUnique<base::DictionaryValue>();
522 const std::vector<std::string>* public_session_recommended_locales =
523 public_session_recommended_locales_.find(account_id) ==
524 public_session_recommended_locales_.end()
525 ? &kEmptyRecommendedLocales
526 : &public_session_recommended_locales_[account_id];
527 FillUserDictionary(*it, is_owner, is_signin_to_add, initial_auth_type,
528 public_session_recommended_locales, user_dict.get());
529 bool signed_in = (*it)->is_logged_in();
530
531 // Single user check here is necessary because owner info might not be
532 // available when running into login screen on first boot.
533 // See http://crosbug.com/12723
534 bool can_remove_user =
535 ((!single_user || is_enterprise_managed) && account_id.is_valid() &&
536 !is_owner && !is_public_account && !signed_in && !is_signin_to_add);
537 user_dict->SetBoolean(kKeyCanRemove, can_remove_user);
538 users_list.Append(std::move(user_dict));
539 }
540
541 handler_->LoadUsers(users_to_send, users_list);
542 } 487 }
543 488
544 void UserSelectionScreen::HandleGetUsers() { 489 void UserSelectionScreen::HandleGetUsers() {
545 SendUserList(); 490 SendUserList();
546 } 491 }
547 492
548 void UserSelectionScreen::CheckUserStatus(const AccountId& account_id) { 493 void UserSelectionScreen::CheckUserStatus(const AccountId& account_id) {
549 // No checks on lock screen. 494 // No checks on lock screen.
550 if (ScreenLocker::default_screen_locker()) 495 if (ScreenLocker::default_screen_locker())
551 return; 496 return;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 } 558 }
614 559
615 void UserSelectionScreen::ShowBannerMessage(const base::string16& message) { 560 void UserSelectionScreen::ShowBannerMessage(const base::string16& message) {
616 view_->ShowBannerMessage(message); 561 view_->ShowBannerMessage(message);
617 } 562 }
618 563
619 void UserSelectionScreen::ShowUserPodCustomIcon( 564 void UserSelectionScreen::ShowUserPodCustomIcon(
620 const AccountId& account_id, 565 const AccountId& account_id,
621 const proximity_auth::ScreenlockBridge::UserPodCustomIconOptions& 566 const proximity_auth::ScreenlockBridge::UserPodCustomIconOptions&
622 icon_options) { 567 icon_options) {
623 std::unique_ptr<base::DictionaryValue> icon = 568 view_->ShowUserPodCustomIcon(account_id, icon_options);
624 icon_options.ToDictionaryValue();
625 if (!icon || icon->empty())
626 return;
627 view_->ShowUserPodCustomIcon(account_id, *icon);
628 } 569 }
629 570
630 void UserSelectionScreen::HideUserPodCustomIcon(const AccountId& account_id) { 571 void UserSelectionScreen::HideUserPodCustomIcon(const AccountId& account_id) {
631 view_->HideUserPodCustomIcon(account_id); 572 view_->HideUserPodCustomIcon(account_id);
632 } 573 }
633 574
634 void UserSelectionScreen::EnableInput() { 575 void UserSelectionScreen::EnableInput() {
635 // If Easy Unlock fails to unlock the screen, re-enable the password input. 576 // If Easy Unlock fails to unlock the screen, re-enable the password input.
636 // This is only necessary on the lock screen, because the error handling for 577 // This is only necessary on the lock screen, because the error handling for
637 // the sign-in screen uses a different code path. 578 // the sign-in screen uses a different code path.
638 if (ScreenLocker::default_screen_locker()) 579 if (ScreenLocker::default_screen_locker())
639 ScreenLocker::default_screen_locker()->EnableInput(); 580 ScreenLocker::default_screen_locker()->EnableInput();
640 } 581 }
641 582
642 void UserSelectionScreen::Unlock(const AccountId& account_id) { 583 void UserSelectionScreen::Unlock(const AccountId& account_id) {
643 DCHECK_EQ(GetScreenType(), LOCK_SCREEN); 584 DCHECK_EQ(GetScreenType(), LOCK_SCREEN);
644 ScreenLocker::Hide(); 585 ScreenLocker::Hide();
645 } 586 }
646 587
647 void UserSelectionScreen::AttemptEasySignin(const AccountId& account_id, 588 void UserSelectionScreen::AttemptEasySignin(const AccountId& account_id,
648 const std::string& secret, 589 const std::string& secret,
649 const std::string& key_label) { 590 const std::string& key_label) {
650 DCHECK_EQ(GetScreenType(), SIGNIN_SCREEN); 591 DCHECK_EQ(GetScreenType(), SIGNIN_SCREEN);
651 592
652 UserContext user_context(account_id); 593 UserContext user_context(account_id);
653 user_context.SetAuthFlow(UserContext::AUTH_FLOW_EASY_UNLOCK); 594 user_context.SetAuthFlow(UserContext::AUTH_FLOW_EASY_UNLOCK);
654 user_context.SetKey(Key(secret)); 595 user_context.SetKey(Key(secret));
655 user_context.GetKey()->SetLabel(key_label); 596 user_context.GetKey()->SetLabel(key_label);
656 597
657 login_display_delegate_->Login(user_context, SigninSpecifics()); 598 // login display delegate not exist in views-based lock screen.
599 if (login_display_delegate_)
600 login_display_delegate_->Login(user_context, SigninSpecifics());
658 } 601 }
659 602
660 void UserSelectionScreen::Show() {} 603 void UserSelectionScreen::Show() {}
661 604
662 void UserSelectionScreen::Hide() {} 605 void UserSelectionScreen::Hide() {}
663 606
664 void UserSelectionScreen::HardLockPod(const AccountId& account_id) { 607 void UserSelectionScreen::HardLockPod(const AccountId& account_id) {
665 view_->SetAuthType(account_id, OFFLINE_PASSWORD, base::string16()); 608 view_->SetAuthType(account_id, OFFLINE_PASSWORD, base::string16());
666 EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id); 609 EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id);
667 if (!service) 610 if (!service)
668 return; 611 return;
669 service->SetHardlockState(EasyUnlockScreenlockStateHandler::USER_HARDLOCK); 612 service->SetHardlockState(EasyUnlockScreenlockStateHandler::USER_HARDLOCK);
670 } 613 }
671 614
672 void UserSelectionScreen::AttemptEasyUnlock(const AccountId& account_id) { 615 void UserSelectionScreen::AttemptEasyUnlock(const AccountId& account_id) {
673 EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id); 616 EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id);
674 if (!service) 617 if (!service)
675 return; 618 return;
676 service->AttemptAuth(account_id); 619 service->AttemptAuth(account_id);
677 } 620 }
678 621
679 void UserSelectionScreen::RecordClickOnLockIcon(const AccountId& account_id) { 622 void UserSelectionScreen::RecordClickOnLockIcon(const AccountId& account_id) {
680 EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id); 623 EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id);
681 if (!service) 624 if (!service)
682 return; 625 return;
683 service->RecordClickOnLockIcon(); 626 service->RecordClickOnLockIcon();
684 } 627 }
685 628
629 std::unique_ptr<base::ListValue> UserSelectionScreen::PrepareUserList() {
630 std::unique_ptr<base::ListValue> users_list =
631 base::MakeUnique<base::ListValue>();
632
633 // TODO(nkostylev): Move to a separate method in UserManager.
634 // http://crbug.com/230852
635 bool single_user = users_.size() == 1;
636 bool is_signin_to_add = LoginDisplayHost::default_host() &&
637 user_manager::UserManager::Get()->IsUserLoggedIn();
638 std::string owner_email;
639 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner,
640 &owner_email);
641 const AccountId owner = user_manager::known_user::GetAccountId(
642 owner_email, std::string() /* id */, AccountType::UNKNOWN);
643
644 policy::BrowserPolicyConnectorChromeOS* connector =
645 g_browser_process->platform_part()->browser_policy_connector_chromeos();
646 bool is_enterprise_managed = connector->IsEnterpriseManaged();
647
648 users_to_send_ = PrepareUserListForSending(users_, owner, is_signin_to_add);
649
650 user_auth_type_map_.clear();
651
652 const std::vector<std::string> kEmptyRecommendedLocales;
653 for (user_manager::UserList::const_iterator it = users_to_send_.begin();
654 it != users_to_send_.end(); ++it) {
655 const AccountId& account_id = (*it)->GetAccountId();
656 bool is_owner = (account_id == owner);
657 const bool is_public_account =
658 ((*it)->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT);
659 const AuthType initial_auth_type =
660 is_public_account ? EXPAND_THEN_USER_CLICK
661 : (ShouldForceOnlineSignIn(*it) ? ONLINE_SIGN_IN
662 : OFFLINE_PASSWORD);
663 user_auth_type_map_[account_id] = initial_auth_type;
664
665 auto user_dict = base::MakeUnique<base::DictionaryValue>();
666 const std::vector<std::string>* public_session_recommended_locales =
667 public_session_recommended_locales_.find(account_id) ==
668 public_session_recommended_locales_.end()
669 ? &kEmptyRecommendedLocales
670 : &public_session_recommended_locales_[account_id];
671 FillUserDictionary(*it, is_owner, is_signin_to_add, initial_auth_type,
672 public_session_recommended_locales, user_dict.get());
673 bool signed_in = (*it)->is_logged_in();
674
675 // Single user check here is necessary because owner info might not be
676 // available when running into login screen on first boot.
677 // See http://crosbug.com/12723
678 bool can_remove_user =
679 ((!single_user || is_enterprise_managed) && account_id.is_valid() &&
680 !is_owner && !is_public_account && !signed_in && !is_signin_to_add);
681 user_dict->SetBoolean(kKeyCanRemove, can_remove_user);
682 users_list->Append(std::move(user_dict));
683 }
684
685 return users_list;
686 }
687
686 EasyUnlockService* UserSelectionScreen::GetEasyUnlockServiceForUser( 688 EasyUnlockService* UserSelectionScreen::GetEasyUnlockServiceForUser(
687 const AccountId& account_id) const { 689 const AccountId& account_id) const {
688 if (GetScreenType() == OTHER_SCREEN) 690 if (GetScreenType() == OTHER_SCREEN)
689 return nullptr; 691 return nullptr;
690 692
691 const user_manager::User* unlock_user = nullptr; 693 const user_manager::User* unlock_user = nullptr;
692 for (const user_manager::User* user : users_) { 694 for (const user_manager::User* user : users_) {
693 if (user->GetAccountId() == account_id) { 695 if (user->GetAccountId() == account_id) {
694 unlock_user = user; 696 unlock_user = user;
695 break; 697 break;
696 } 698 }
697 } 699 }
698 if (!unlock_user) 700 if (!unlock_user)
699 return nullptr; 701 return nullptr;
700 702
701 ProfileHelper* profile_helper = ProfileHelper::Get(); 703 ProfileHelper* profile_helper = ProfileHelper::Get();
702 Profile* profile = profile_helper->GetProfileByUser(unlock_user); 704 Profile* profile = profile_helper->GetProfileByUser(unlock_user);
703 705
704 // The user profile should exist if and only if this is the lock screen. 706 // The user profile should exist if and only if this is the lock screen.
705 DCHECK_EQ(!!profile, GetScreenType() == LOCK_SCREEN); 707 DCHECK_EQ(!!profile, GetScreenType() == LOCK_SCREEN);
706 708
707 if (!profile) 709 if (!profile)
708 profile = profile_helper->GetSigninProfile(); 710 profile = profile_helper->GetSigninProfile();
709 711
710 return EasyUnlockService::Get(profile); 712 return EasyUnlockService::Get(profile);
711 } 713 }
712 714
713 } // namespace chromeos 715 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698