OLD | NEW |
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" |
11 #include "base/guid.h" | 11 #include "base/guid.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
14 #include "base/prefs/pref_registry_simple.h" | 14 #include "base/prefs/pref_registry_simple.h" |
15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
16 #include "base/prefs/scoped_user_pref_update.h" | 16 #include "base/prefs/scoped_user_pref_update.h" |
17 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
18 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
21 #include "base/version.h" | 21 #include "base/version.h" |
22 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/services/gcm/gcm_profile_service.h" | |
25 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | |
26 #include "chrome/browser/signin/chrome_proximity_auth_client.h" | 24 #include "chrome/browser/signin/chrome_proximity_auth_client.h" |
27 #include "chrome/browser/signin/easy_unlock_app_manager.h" | 25 #include "chrome/browser/signin/easy_unlock_app_manager.h" |
28 #include "chrome/browser/signin/easy_unlock_service_factory.h" | 26 #include "chrome/browser/signin/easy_unlock_service_factory.h" |
29 #include "chrome/browser/signin/easy_unlock_service_observer.h" | 27 #include "chrome/browser/signin/easy_unlock_service_observer.h" |
30 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 28 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
31 #include "chrome/browser/signin/signin_manager_factory.h" | 29 #include "chrome/browser/signin/signin_manager_factory.h" |
32 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
33 #include "chrome/common/extensions/extension_constants.h" | 31 #include "chrome/common/extensions/extension_constants.h" |
34 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
35 #include "components/pref_registry/pref_registry_syncable.h" | 33 #include "components/pref_registry/pref_registry_syncable.h" |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 } | 644 } |
647 | 645 |
648 void EasyUnlockService::AddObserver(EasyUnlockServiceObserver* observer) { | 646 void EasyUnlockService::AddObserver(EasyUnlockServiceObserver* observer) { |
649 observers_.AddObserver(observer); | 647 observers_.AddObserver(observer); |
650 } | 648 } |
651 | 649 |
652 void EasyUnlockService::RemoveObserver(EasyUnlockServiceObserver* observer) { | 650 void EasyUnlockService::RemoveObserver(EasyUnlockServiceObserver* observer) { |
653 observers_.RemoveObserver(observer); | 651 observers_.RemoveObserver(observer); |
654 } | 652 } |
655 | 653 |
656 PrefService* EasyUnlockService::GetPrefService() { | |
657 return profile()->GetPrefs(); | |
658 } | |
659 | |
660 scoped_ptr<proximity_auth::SecureMessageDelegate> | |
661 EasyUnlockService::CreateSecureMessageDelegate() { | |
662 #if defined(OS_CHROMEOS) | |
663 return make_scoped_ptr(new chromeos::SecureMessageDelegateChromeOS()); | |
664 #else | |
665 return nullptr; | |
666 #endif | |
667 } | |
668 | |
669 scoped_ptr<proximity_auth::CryptAuthClientFactory> | |
670 EasyUnlockService::CreateCryptAuthClientFactory() { | |
671 return make_scoped_ptr(new proximity_auth::CryptAuthClientFactoryImpl( | |
672 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()), | |
673 SigninManagerFactory::GetForProfile(profile()) | |
674 ->GetAuthenticatedAccountId(), | |
675 profile()->GetRequestContext(), GetDeviceClassifier())); | |
676 } | |
677 | |
678 cryptauth::DeviceClassifier EasyUnlockService::GetDeviceClassifier() { | |
679 cryptauth::DeviceClassifier device_classifier; | |
680 | |
681 #if defined(OS_CHROMEOS) | |
682 int32 major_version, minor_version, bugfix_version; | |
683 // TODO(tengs): base::OperatingSystemVersionNumbers only works for ChromeOS. | |
684 // We need to get different numbers for other platforms. | |
685 base::SysInfo::OperatingSystemVersionNumbers(&major_version, &minor_version, | |
686 &bugfix_version); | |
687 device_classifier.set_device_os_version_code(major_version); | |
688 device_classifier.set_device_type(cryptauth::CHROME); | |
689 #endif | |
690 | |
691 const std::vector<uint32_t>& version_components = | |
692 base::Version(version_info::GetVersionNumber()).components(); | |
693 if (version_components.size() > 0) | |
694 device_classifier.set_device_software_version_code(version_components[0]); | |
695 | |
696 device_classifier.set_device_software_package(version_info::GetProductName()); | |
697 return device_classifier; | |
698 } | |
699 | |
700 std::string EasyUnlockService::GetAccountId() { | |
701 return SigninManagerFactory::GetForProfile(profile()) | |
702 ->GetAuthenticatedAccountId(); | |
703 } | |
704 | |
705 gcm::GCMDriver* EasyUnlockService::GetGCMDriver() { | |
706 gcm::GCMProfileService* gcm_profile_service = | |
707 gcm::GCMProfileServiceFactory::GetForProfile(profile_); | |
708 return gcm_profile_service->driver(); | |
709 } | |
710 | |
711 void EasyUnlockService::Shutdown() { | 654 void EasyUnlockService::Shutdown() { |
712 if (shut_down_) | 655 if (shut_down_) |
713 return; | 656 return; |
714 shut_down_ = true; | 657 shut_down_ = true; |
715 | 658 |
716 ShutdownInternal(); | 659 ShutdownInternal(); |
717 | 660 |
718 ResetScreenlockState(); | 661 ResetScreenlockState(); |
719 bluetooth_detector_.reset(); | 662 bluetooth_detector_.reset(); |
720 #if defined(OS_CHROMEOS) | 663 #if defined(OS_CHROMEOS) |
(...skipping 16 matching lines...) Expand all Loading... |
737 app_manager_->LoadApp(); | 680 app_manager_->LoadApp(); |
738 NotifyUserUpdated(); | 681 NotifyUserUpdated(); |
739 | 682 |
740 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 683 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
741 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery) && | 684 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery) && |
742 GetType() == EasyUnlockService::TYPE_REGULAR && | 685 GetType() == EasyUnlockService::TYPE_REGULAR && |
743 !proximity_auth_ble_system_) { | 686 !proximity_auth_ble_system_) { |
744 proximity_auth_ble_system_.reset( | 687 proximity_auth_ble_system_.reset( |
745 new proximity_auth::ProximityAuthBleSystem( | 688 new proximity_auth::ProximityAuthBleSystem( |
746 proximity_auth::ScreenlockBridge::Get(), &proximity_auth_client_, | 689 proximity_auth::ScreenlockBridge::Get(), &proximity_auth_client_, |
747 CreateCryptAuthClientFactory(), profile_->GetPrefs())); | 690 proximity_auth_client_.CreateCryptAuthClientFactory(), |
| 691 profile_->GetPrefs())); |
748 } | 692 } |
749 | 693 |
750 #if defined(OS_CHROMEOS) | 694 #if defined(OS_CHROMEOS) |
751 if (!power_monitor_) | 695 if (!power_monitor_) |
752 power_monitor_.reset(new PowerMonitor(this)); | 696 power_monitor_.reset(new PowerMonitor(this)); |
753 #endif | 697 #endif |
754 } else { | 698 } else { |
755 bool bluetooth_waking_up = false; | 699 bool bluetooth_waking_up = false; |
756 #if defined(OS_CHROMEOS) | 700 #if defined(OS_CHROMEOS) |
757 // If the service is not allowed due to bluetooth not being detected just | 701 // If the service is not allowed due to bluetooth not being detected just |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 | 902 |
959 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt | 903 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt |
960 // failed. | 904 // failed. |
961 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) | 905 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) |
962 ->PrepareTpmKey(true /* check_private_key */, | 906 ->PrepareTpmKey(true /* check_private_key */, |
963 base::Closure()); | 907 base::Closure()); |
964 #endif // defined(OS_CHROMEOS) | 908 #endif // defined(OS_CHROMEOS) |
965 | 909 |
966 tpm_key_checked_ = true; | 910 tpm_key_checked_ = true; |
967 } | 911 } |
OLD | NEW |