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

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: Incoporate pathset 3 comments 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 10 matching lines...) Expand all
21 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_factory.h" 21 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_factory.h"
22 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_storage.h" 22 #include "chrome/browser/chromeos/login/quick_unlock/quick_unlock_storage.h"
23 #include "chrome/browser/chromeos/login/reauth_stats.h" 23 #include "chrome/browser/chromeos/login/reauth_stats.h"
24 #include "chrome/browser/chromeos/login/ui/login_display_host.h" 24 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
25 #include "chrome/browser/chromeos/login/ui/views/user_board_view.h" 25 #include "chrome/browser/chromeos/login/ui/views/user_board_view.h"
26 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" 26 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
27 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" 27 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h"
28 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 28 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
29 #include "chrome/browser/chromeos/profiles/profile_helper.h" 29 #include "chrome/browser/chromeos/profiles/profile_helper.h"
30 #include "chrome/browser/signin/easy_unlock_service.h" 30 #include "chrome/browser/signin/easy_unlock_service.h"
31 #include "chrome/browser/ui/ash/lock_screen_client.h"
31 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" 32 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h"
32 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" 33 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
33 #include "chrome/grit/generated_resources.h" 34 #include "chrome/grit/generated_resources.h"
34 #include "chromeos/chromeos_switches.h" 35 #include "chromeos/chromeos_switches.h"
35 #include "chromeos/cryptohome/cryptohome_parameters.h" 36 #include "chromeos/cryptohome/cryptohome_parameters.h"
36 #include "chromeos/dbus/cryptohome_client.h" 37 #include "chromeos/dbus/cryptohome_client.h"
37 #include "chromeos/dbus/dbus_method_call_status.h" 38 #include "chromeos/dbus/dbus_method_call_status.h"
38 #include "chromeos/dbus/dbus_thread_manager.h" 39 #include "chromeos/dbus/dbus_thread_manager.h"
39 #include "components/arc/arc_util.h" 40 #include "components/arc/arc_util.h"
40 #include "components/prefs/pref_service.h" 41 #include "components/prefs/pref_service.h"
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 users_to_send.erase(users_to_send.begin() + kMaxUsers); 476 users_to_send.erase(users_to_send.begin() + kMaxUsers);
476 } else if (users_to_send.size() < kMaxUsers) { 477 } else if (users_to_send.size() < kMaxUsers) {
477 users_to_send.push_back(*it); 478 users_to_send.push_back(*it);
478 } 479 }
479 } 480 }
480 } 481 }
481 return users_to_send; 482 return users_to_send;
482 } 483 }
483 484
484 void UserSelectionScreen::SendUserList() { 485 void UserSelectionScreen::SendUserList() {
485 base::ListValue users_list; 486 std::unique_ptr<base::ListValue> users_list = PrepareUserList();
486 487 handler_->LoadUsers(users_to_send_, *users_list);
xiyuan 2017/06/05 17:30:40 Can we clean up LoadUsers API to only take the Lis
xiaoyinh(OOO Sep 11-29) 2017/06/05 17:48:31 I think this parameter (user_manager::UserList& us
jdufault 2017/06/05 19:31:14 Yes, we need it for pin sign-in.
xiyuan 2017/06/05 20:04:27 Okay. Ignore this comment then.
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 } 488 }
543 489
544 void UserSelectionScreen::HandleGetUsers() { 490 void UserSelectionScreen::HandleGetUsers() {
545 SendUserList(); 491 SendUserList();
546 } 492 }
547 493
548 void UserSelectionScreen::CheckUserStatus(const AccountId& account_id) { 494 void UserSelectionScreen::CheckUserStatus(const AccountId& account_id) {
549 // No checks on lock screen. 495 // No checks on lock screen.
550 if (ScreenLocker::default_screen_locker()) 496 if (ScreenLocker::default_screen_locker())
551 return; 497 return;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 } 559 }
614 560
615 void UserSelectionScreen::ShowBannerMessage(const base::string16& message) { 561 void UserSelectionScreen::ShowBannerMessage(const base::string16& message) {
616 view_->ShowBannerMessage(message); 562 view_->ShowBannerMessage(message);
617 } 563 }
618 564
619 void UserSelectionScreen::ShowUserPodCustomIcon( 565 void UserSelectionScreen::ShowUserPodCustomIcon(
620 const AccountId& account_id, 566 const AccountId& account_id,
621 const proximity_auth::ScreenlockBridge::UserPodCustomIconOptions& 567 const proximity_auth::ScreenlockBridge::UserPodCustomIconOptions&
622 icon_options) { 568 icon_options) {
623 std::unique_ptr<base::DictionaryValue> icon = 569 view_->ShowUserPodCustomIcon(account_id, icon_options);
624 icon_options.ToDictionaryValue();
625 if (!icon || icon->empty())
626 return;
627 view_->ShowUserPodCustomIcon(account_id, *icon);
628 } 570 }
629 571
630 void UserSelectionScreen::HideUserPodCustomIcon(const AccountId& account_id) { 572 void UserSelectionScreen::HideUserPodCustomIcon(const AccountId& account_id) {
631 view_->HideUserPodCustomIcon(account_id); 573 view_->HideUserPodCustomIcon(account_id);
632 } 574 }
633 575
634 void UserSelectionScreen::EnableInput() { 576 void UserSelectionScreen::EnableInput() {
635 // If Easy Unlock fails to unlock the screen, re-enable the password input. 577 // 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 578 // This is only necessary on the lock screen, because the error handling for
637 // the sign-in screen uses a different code path. 579 // the sign-in screen uses a different code path.
638 if (ScreenLocker::default_screen_locker()) 580 if (ScreenLocker::default_screen_locker())
639 ScreenLocker::default_screen_locker()->EnableInput(); 581 ScreenLocker::default_screen_locker()->EnableInput();
640 } 582 }
641 583
642 void UserSelectionScreen::Unlock(const AccountId& account_id) { 584 void UserSelectionScreen::Unlock(const AccountId& account_id) {
643 DCHECK_EQ(GetScreenType(), LOCK_SCREEN); 585 DCHECK_EQ(GetScreenType(), LOCK_SCREEN);
644 ScreenLocker::Hide(); 586 ScreenLocker::Hide();
645 } 587 }
646 588
647 void UserSelectionScreen::AttemptEasySignin(const AccountId& account_id, 589 void UserSelectionScreen::AttemptEasySignin(const AccountId& account_id,
648 const std::string& secret, 590 const std::string& secret,
649 const std::string& key_label) { 591 const std::string& key_label) {
650 DCHECK_EQ(GetScreenType(), SIGNIN_SCREEN); 592 DCHECK_EQ(GetScreenType(), SIGNIN_SCREEN);
651 593
652 UserContext user_context(account_id); 594 UserContext user_context(account_id);
653 user_context.SetAuthFlow(UserContext::AUTH_FLOW_EASY_UNLOCK); 595 user_context.SetAuthFlow(UserContext::AUTH_FLOW_EASY_UNLOCK);
654 user_context.SetKey(Key(secret)); 596 user_context.SetKey(Key(secret));
655 user_context.GetKey()->SetLabel(key_label); 597 user_context.GetKey()->SetLabel(key_label);
656 598
657 login_display_delegate_->Login(user_context, SigninSpecifics()); 599 // login display delegate not exist in views-based lock screen.
600 if (login_display_delegate_)
601 login_display_delegate_->Login(user_context, SigninSpecifics());
658 } 602 }
659 603
660 void UserSelectionScreen::Show() {} 604 void UserSelectionScreen::Show() {}
661 605
662 void UserSelectionScreen::Hide() {} 606 void UserSelectionScreen::Hide() {}
663 607
664 void UserSelectionScreen::HardLockPod(const AccountId& account_id) { 608 void UserSelectionScreen::HardLockPod(const AccountId& account_id) {
665 view_->SetAuthType(account_id, OFFLINE_PASSWORD, base::string16()); 609 view_->SetAuthType(account_id, OFFLINE_PASSWORD, base::string16());
666 EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id); 610 EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id);
667 if (!service) 611 if (!service)
668 return; 612 return;
669 service->SetHardlockState(EasyUnlockScreenlockStateHandler::USER_HARDLOCK); 613 service->SetHardlockState(EasyUnlockScreenlockStateHandler::USER_HARDLOCK);
670 } 614 }
671 615
672 void UserSelectionScreen::AttemptEasyUnlock(const AccountId& account_id) { 616 void UserSelectionScreen::AttemptEasyUnlock(const AccountId& account_id) {
673 EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id); 617 EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id);
674 if (!service) 618 if (!service)
675 return; 619 return;
676 service->AttemptAuth(account_id); 620 service->AttemptAuth(account_id);
677 } 621 }
678 622
679 void UserSelectionScreen::RecordClickOnLockIcon(const AccountId& account_id) { 623 void UserSelectionScreen::RecordClickOnLockIcon(const AccountId& account_id) {
680 EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id); 624 EasyUnlockService* service = GetEasyUnlockServiceForUser(account_id);
681 if (!service) 625 if (!service)
682 return; 626 return;
683 service->RecordClickOnLockIcon(); 627 service->RecordClickOnLockIcon();
684 } 628 }
685 629
630 std::unique_ptr<base::ListValue> UserSelectionScreen::PrepareUserList() {
631 std::unique_ptr<base::ListValue> users_list(new base::ListValue());
jdufault 2017/06/03 01:00:45 nit: prefer MakeUnique
xiaoyinh(OOO Sep 11-29) 2017/06/06 16:36:05 Done.
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