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

Side by Side Diff: chrome/browser/signin/easy_unlock_service.cc

Issue 1372283002: Hook up ProximityAuthSystem in EasyUnlockService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth_connection
Patch Set: remove log Created 5 years, 2 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/signin/easy_unlock_service.h" 5 #include "chrome/browser/signin/easy_unlock_service.h"
6 6
7 #include "apps/app_lifetime_monitor.h" 7 #include "apps/app_lifetime_monitor.h"
8 #include "apps/app_lifetime_monitor_factory.h" 8 #include "apps/app_lifetime_monitor_factory.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/browser/signin/chrome_proximity_auth_client.h" 24 #include "chrome/browser/signin/chrome_proximity_auth_client.h"
25 #include "chrome/browser/signin/easy_unlock_app_manager.h" 25 #include "chrome/browser/signin/easy_unlock_app_manager.h"
26 #include "chrome/browser/signin/easy_unlock_service_factory.h" 26 #include "chrome/browser/signin/easy_unlock_service_factory.h"
27 #include "chrome/browser/signin/easy_unlock_service_observer.h" 27 #include "chrome/browser/signin/easy_unlock_service_observer.h"
28 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 28 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
29 #include "chrome/browser/signin/signin_manager_factory.h" 29 #include "chrome/browser/signin/signin_manager_factory.h"
30 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
31 #include "chrome/common/extensions/extension_constants.h" 31 #include "chrome/common/extensions/extension_constants.h"
32 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
33 #include "components/pref_registry/pref_registry_syncable.h" 33 #include "components/pref_registry/pref_registry_syncable.h"
34 #include "components/proximity_auth/ble/proximity_auth_ble_system.h"
35 #include "components/proximity_auth/cryptauth/cryptauth_client_impl.h" 34 #include "components/proximity_auth/cryptauth/cryptauth_client_impl.h"
36 #include "components/proximity_auth/cryptauth/cryptauth_device_manager.h" 35 #include "components/proximity_auth/cryptauth/cryptauth_device_manager.h"
37 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h" 36 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h"
38 #include "components/proximity_auth/cryptauth/secure_message_delegate.h" 37 #include "components/proximity_auth/cryptauth/secure_message_delegate.h"
38 #include "components/proximity_auth/logging/logging.h"
39 #include "components/proximity_auth/proximity_auth_pref_manager.h" 39 #include "components/proximity_auth/proximity_auth_pref_manager.h"
40 #include "components/proximity_auth/proximity_auth_system.h"
40 #include "components/proximity_auth/screenlock_bridge.h" 41 #include "components/proximity_auth/screenlock_bridge.h"
41 #include "components/proximity_auth/switches.h" 42 #include "components/proximity_auth/switches.h"
42 #include "components/signin/core/browser/profile_oauth2_token_service.h" 43 #include "components/signin/core/browser/profile_oauth2_token_service.h"
43 #include "components/signin/core/browser/signin_manager.h" 44 #include "components/signin/core/browser/signin_manager.h"
44 #include "components/user_manager/user.h" 45 #include "components/user_manager/user.h"
45 #include "components/version_info/version_info.h" 46 #include "components/version_info/version_info.h"
46 #include "device/bluetooth/bluetooth_adapter.h" 47 #include "device/bluetooth/bluetooth_adapter.h"
47 #include "device/bluetooth/bluetooth_adapter_factory.h" 48 #include "device/bluetooth/bluetooth_adapter_factory.h"
48 49
49 #if defined(OS_CHROMEOS) 50 #if defined(OS_CHROMEOS)
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 registry->RegisterDictionaryPref(prefs::kEasyUnlockPairing, 278 registry->RegisterDictionaryPref(prefs::kEasyUnlockPairing,
278 new base::DictionaryValue()); 279 new base::DictionaryValue());
279 registry->RegisterBooleanPref( 280 registry->RegisterBooleanPref(
280 prefs::kEasyUnlockProximityRequired, 281 prefs::kEasyUnlockProximityRequired,
281 false, 282 false,
282 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 283 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
283 284
284 proximity_auth::CryptAuthGCMManager::RegisterPrefs(registry); 285 proximity_auth::CryptAuthGCMManager::RegisterPrefs(registry);
285 proximity_auth::CryptAuthDeviceManager::RegisterPrefs(registry); 286 proximity_auth::CryptAuthDeviceManager::RegisterPrefs(registry);
286 proximity_auth::CryptAuthEnrollmentManager::RegisterPrefs(registry); 287 proximity_auth::CryptAuthEnrollmentManager::RegisterPrefs(registry);
287 proximity_auth::ProximityAuthPrefManager::RegisterPrefs(registry);
288 288
289 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 289 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
290 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery)) 290 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery))
291 proximity_auth::ProximityAuthBleSystem::RegisterPrefs(registry); 291 proximity_auth::ProximityAuthPrefManager::RegisterPrefs(registry);
292 } 292 }
293 293
294 // static 294 // static
295 void EasyUnlockService::RegisterPrefs(PrefRegistrySimple* registry) { 295 void EasyUnlockService::RegisterPrefs(PrefRegistrySimple* registry) {
296 registry->RegisterStringPref(prefs::kEasyUnlockDeviceId, std::string()); 296 registry->RegisterStringPref(prefs::kEasyUnlockDeviceId, std::string());
297 registry->RegisterDictionaryPref(prefs::kEasyUnlockHardlockState); 297 registry->RegisterDictionaryPref(prefs::kEasyUnlockHardlockState);
298 registry->RegisterDictionaryPref(prefs::kEasyUnlockLocalStateUserPrefs); 298 registry->RegisterDictionaryPref(prefs::kEasyUnlockLocalStateUserPrefs);
299 #if defined(OS_CHROMEOS) 299 #if defined(OS_CHROMEOS)
300 EasyUnlockTpmKeyManager::RegisterLocalStatePrefs(registry); 300 EasyUnlockTpmKeyManager::RegisterLocalStatePrefs(registry);
301 #endif 301 #endif
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 return; 520 return;
521 } 521 }
522 522
523 CHECK_EQ(GetUserEmail(), user_id); 523 CHECK_EQ(GetUserEmail(), user_id);
524 524
525 auth_attempt_.reset(new EasyUnlockAuthAttempt(app_manager_.get(), user_id, 525 auth_attempt_.reset(new EasyUnlockAuthAttempt(app_manager_.get(), user_id,
526 auth_attempt_type, callback)); 526 auth_attempt_type, callback));
527 if (!auth_attempt_->Start()) 527 if (!auth_attempt_->Start())
528 auth_attempt_.reset(); 528 auth_attempt_.reset();
529 529
530 // TODO(tengs): We notify ProximityAuthBleSystem whenever unlock attempts are 530 // TODO(tengs): We notify ProximityAuthSystem whenever unlock attempts are
531 // attempted. However, we ideally should refactor the auth attempt logic to 531 // attempted. However, we ideally should refactor the auth attempt logic to
532 // the proximity_auth component. 532 // the proximity_auth component.
533 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 533 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
534 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery) && 534 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery) &&
535 auth_attempt_type == EasyUnlockAuthAttempt::TYPE_UNLOCK && 535 auth_attempt_type == EasyUnlockAuthAttempt::TYPE_UNLOCK &&
536 proximity_auth_ble_system_) { 536 proximity_auth_system_) {
537 proximity_auth_ble_system_->OnAuthAttempted(user_id); 537 proximity_auth_system_->OnAuthAttempted(user_id);
538 } 538 }
539 } 539 }
540 540
541 void EasyUnlockService::FinalizeUnlock(bool success) { 541 void EasyUnlockService::FinalizeUnlock(bool success) {
542 if (!auth_attempt_.get()) 542 if (!auth_attempt_.get())
543 return; 543 return;
544 544
545 this->OnWillFinalizeUnlock(success); 545 this->OnWillFinalizeUnlock(success);
546 auth_attempt_->FinalizeUnlock(GetUserEmail(), success); 546 auth_attempt_->FinalizeUnlock(GetUserEmail(), success);
547 auth_attempt_.reset(); 547 auth_attempt_.reset();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 644
645 void EasyUnlockService::Shutdown() { 645 void EasyUnlockService::Shutdown() {
646 if (shut_down_) 646 if (shut_down_)
647 return; 647 return;
648 shut_down_ = true; 648 shut_down_ = true;
649 649
650 ShutdownInternal(); 650 ShutdownInternal();
651 651
652 ResetScreenlockState(); 652 ResetScreenlockState();
653 bluetooth_detector_.reset(); 653 bluetooth_detector_.reset();
654 proximity_auth_system_.reset();
654 #if defined(OS_CHROMEOS) 655 #if defined(OS_CHROMEOS)
655 power_monitor_.reset(); 656 power_monitor_.reset();
656 #endif 657 #endif
657 658
658 weak_ptr_factory_.InvalidateWeakPtrs(); 659 weak_ptr_factory_.InvalidateWeakPtrs();
659 } 660 }
660 661
661 void EasyUnlockService::ReloadAppAndLockScreen() { 662 void EasyUnlockService::ReloadAppAndLockScreen() {
662 // Make sure lock screen state set by the extension gets reset. 663 // Make sure lock screen state set by the extension gets reset.
663 ResetScreenlockState(); 664 ResetScreenlockState();
664 app_manager_->ReloadApp(); 665 app_manager_->ReloadApp();
665 NotifyUserUpdated(); 666 NotifyUserUpdated();
666 } 667 }
667 668
668 void EasyUnlockService::UpdateAppState() { 669 void EasyUnlockService::UpdateAppState() {
669 if (IsAllowed()) { 670 if (IsAllowed()) {
670 EnsureTpmKeyPresentIfNeeded(); 671 EnsureTpmKeyPresentIfNeeded();
671 app_manager_->LoadApp(); 672 app_manager_->LoadApp();
672 NotifyUserUpdated(); 673 NotifyUserUpdated();
673 674
674 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
675 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery) &&
676 GetType() == EasyUnlockService::TYPE_REGULAR &&
677 !proximity_auth_ble_system_) {
678 proximity_auth_ble_system_.reset(
679 new proximity_auth::ProximityAuthBleSystem(
680 proximity_auth::ScreenlockBridge::Get(), &proximity_auth_client_,
681 profile_->GetPrefs()));
682 }
683
684 #if defined(OS_CHROMEOS) 675 #if defined(OS_CHROMEOS)
685 if (!power_monitor_) 676 if (!power_monitor_)
686 power_monitor_.reset(new PowerMonitor(this)); 677 power_monitor_.reset(new PowerMonitor(this));
687 #endif 678 #endif
688 } else { 679 } else {
689 bool bluetooth_waking_up = false; 680 bool bluetooth_waking_up = false;
690 #if defined(OS_CHROMEOS) 681 #if defined(OS_CHROMEOS)
691 // If the service is not allowed due to bluetooth not being detected just 682 // If the service is not allowed due to bluetooth not being detected just
692 // after system suspend is done, give bluetooth more time to be detected 683 // after system suspend is done, give bluetooth more time to be detected
693 // before disabling the app (and resetting screenlock state). 684 // before disabling the app (and resetting screenlock state).
694 bluetooth_waking_up = 685 bluetooth_waking_up =
695 power_monitor_.get() && power_monitor_->waking_up() && 686 power_monitor_.get() && power_monitor_->waking_up() &&
696 !bluetooth_detector_->IsPresent(); 687 !bluetooth_detector_->IsPresent();
697 #endif 688 #endif
698 689
699 if (!bluetooth_waking_up) { 690 if (!bluetooth_waking_up) {
700 app_manager_->DisableAppIfLoaded(); 691 app_manager_->DisableAppIfLoaded();
701 ResetScreenlockState(); 692 ResetScreenlockState();
702 proximity_auth_ble_system_.reset(); 693 proximity_auth_system_.reset();
703 #if defined(OS_CHROMEOS) 694 #if defined(OS_CHROMEOS)
704 power_monitor_.reset(); 695 power_monitor_.reset();
705 #endif 696 #endif
706 } 697 }
707 } 698 }
708 } 699 }
709 700
710 void EasyUnlockService::DisableAppWithoutResettingScreenlockState() { 701 void EasyUnlockService::DisableAppWithoutResettingScreenlockState() {
711 app_manager_->DisableAppIfLoaded(); 702 app_manager_->DisableAppIfLoaded();
712 } 703 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 return PASSWORD_ENTRY_PHONE_LOCKED_AND_TX_POWER_TOO_HIGH; 825 return PASSWORD_ENTRY_PHONE_LOCKED_AND_TX_POWER_TOO_HIGH;
835 case ScreenlockState::AUTHENTICATED: 826 case ScreenlockState::AUTHENTICATED:
836 return PASSWORD_ENTRY_WITH_AUTHENTICATED_PHONE; 827 return PASSWORD_ENTRY_WITH_AUTHENTICATED_PHONE;
837 } 828 }
838 } 829 }
839 830
840 NOTREACHED(); 831 NOTREACHED();
841 return EASY_UNLOCK_AUTH_EVENT_COUNT; 832 return EASY_UNLOCK_AUTH_EVENT_COUNT;
842 } 833 }
843 834
835 void EasyUnlockService::OnRemoteDeviceChanged(
836 const proximity_auth::RemoteDevice* remote_device) {
837 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
838 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery))
839 return;
840
841 if (remote_device) {
842 PA_LOG(INFO) << "Remote device changed, recreating ProximityAuthSystem.";
843 proximity_auth_system_.reset(new proximity_auth::ProximityAuthSystem(
844 *remote_device, proximity_auth_client()));
845 proximity_auth_system_->Start();
846 } else {
847 PA_LOG(INFO) << "Remote device removed, destroying ProximityAuthSystem.";
848 proximity_auth_system_.reset();
849 }
850 }
851
844 #if defined(OS_CHROMEOS) 852 #if defined(OS_CHROMEOS)
845 void EasyUnlockService::OnCryptohomeKeysFetchedForChecking( 853 void EasyUnlockService::OnCryptohomeKeysFetchedForChecking(
846 const std::string& user_id, 854 const std::string& user_id,
847 const std::set<std::string> paired_devices, 855 const std::set<std::string> paired_devices,
848 bool success, 856 bool success,
849 const chromeos::EasyUnlockDeviceKeyDataList& key_data_list) { 857 const chromeos::EasyUnlockDeviceKeyDataList& key_data_list) {
850 DCHECK(!user_id.empty() && !paired_devices.empty()); 858 DCHECK(!user_id.empty() && !paired_devices.empty());
851 859
852 if (!success) { 860 if (!success) {
853 SetHardlockStateForUser(user_id, 861 SetHardlockStateForUser(user_id,
(...skipping 13 matching lines...) Expand all
867 ? EasyUnlockScreenlockStateHandler::PAIRING_ADDED 875 ? EasyUnlockScreenlockStateHandler::PAIRING_ADDED
868 : EasyUnlockScreenlockStateHandler::PAIRING_CHANGED); 876 : EasyUnlockScreenlockStateHandler::PAIRING_CHANGED);
869 } 877 }
870 } 878 }
871 #endif 879 #endif
872 880
873 void EasyUnlockService::PrepareForSuspend() { 881 void EasyUnlockService::PrepareForSuspend() {
874 app_manager_->DisableAppIfLoaded(); 882 app_manager_->DisableAppIfLoaded();
875 if (screenlock_state_handler_ && screenlock_state_handler_->IsActive()) 883 if (screenlock_state_handler_ && screenlock_state_handler_->IsActive())
876 UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING); 884 UpdateScreenlockState(ScreenlockState::BLUETOOTH_CONNECTING);
885 if (proximity_auth_system_)
886 proximity_auth_system_->OnSuspend();
887 }
888
889 void EasyUnlockService::OnSuspendDone() {
890 if (proximity_auth_system_)
891 proximity_auth_system_->OnSuspendDone();
877 } 892 }
878 893
879 void EasyUnlockService::EnsureTpmKeyPresentIfNeeded() { 894 void EasyUnlockService::EnsureTpmKeyPresentIfNeeded() {
880 if (tpm_key_checked_ || GetType() != TYPE_REGULAR || GetUserEmail().empty() || 895 if (tpm_key_checked_ || GetType() != TYPE_REGULAR || GetUserEmail().empty() ||
881 GetHardlockState() == EasyUnlockScreenlockStateHandler::NO_PAIRING) { 896 GetHardlockState() == EasyUnlockScreenlockStateHandler::NO_PAIRING) {
882 return; 897 return;
883 } 898 }
884 899
885 #if defined(OS_CHROMEOS) 900 #if defined(OS_CHROMEOS)
886 // If this is called before the session is started, the chances are Chrome 901 // If this is called before the session is started, the chances are Chrome
887 // is restarting in order to apply user flags. Don't check TPM keys in this 902 // is restarting in order to apply user flags. Don't check TPM keys in this
888 // case. 903 // case.
889 if (!user_manager::UserManager::Get() || 904 if (!user_manager::UserManager::Get() ||
890 !user_manager::UserManager::Get()->IsSessionStarted()) 905 !user_manager::UserManager::Get()->IsSessionStarted())
891 return; 906 return;
892 907
893 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt 908 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt
894 // failed. 909 // failed.
895 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) 910 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_)
896 ->PrepareTpmKey(true /* check_private_key */, 911 ->PrepareTpmKey(true /* check_private_key */,
897 base::Closure()); 912 base::Closure());
898 #endif // defined(OS_CHROMEOS) 913 #endif // defined(OS_CHROMEOS)
899 914
900 tpm_key_checked_ = true; 915 tpm_key_checked_ = true;
901 } 916 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/easy_unlock_service.h ('k') | chrome/browser/signin/easy_unlock_service_regular.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698