| 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" |
| 8 #include "apps/app_lifetime_monitor_factory.h" |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 9 #include "base/guid.h" | 11 #include "base/guid.h" |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 11 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/prefs/pref_registry_simple.h" | 14 #include "base/prefs/pref_registry_simple.h" |
| 13 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 14 #include "base/prefs/scoped_user_pref_update.h" | 16 #include "base/prefs/scoped_user_pref_update.h" |
| 15 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 16 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 17 #include "base/values.h" | 19 #include "base/values.h" |
| 18 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/signin/easy_unlock_app_manager.h" | 22 #include "chrome/browser/signin/easy_unlock_app_manager.h" |
| 21 #include "chrome/browser/signin/easy_unlock_auth_attempt.h" | 23 #include "chrome/browser/signin/easy_unlock_auth_attempt.h" |
| 22 #include "chrome/browser/signin/easy_unlock_service_factory.h" | 24 #include "chrome/browser/signin/easy_unlock_service_factory.h" |
| 23 #include "chrome/browser/signin/easy_unlock_service_observer.h" | 25 #include "chrome/browser/signin/easy_unlock_service_observer.h" |
| 24 #include "chrome/browser/signin/screenlock_bridge.h" | 26 #include "chrome/browser/signin/screenlock_bridge.h" |
| 25 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/extensions/extension_constants.h" |
| 26 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 27 #include "components/pref_registry/pref_registry_syncable.h" | 30 #include "components/pref_registry/pref_registry_syncable.h" |
| 28 #include "components/proximity_auth/switches.h" | 31 #include "components/proximity_auth/switches.h" |
| 29 #include "components/user_manager/user.h" | 32 #include "components/user_manager/user.h" |
| 30 #include "device/bluetooth/bluetooth_adapter.h" | 33 #include "device/bluetooth/bluetooth_adapter.h" |
| 31 #include "device/bluetooth/bluetooth_adapter_factory.h" | 34 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 32 | 35 |
| 33 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
| 34 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" | 37 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" |
| 35 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager.
h" | 38 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager.
h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 #endif | 77 #endif |
| 75 } | 78 } |
| 76 | 79 |
| 77 // static | 80 // static |
| 78 bool EasyUnlockService::IsSignInEnabled() { | 81 bool EasyUnlockService::IsSignInEnabled() { |
| 79 return !base::CommandLine::ForCurrentProcess()->HasSwitch( | 82 return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 80 proximity_auth::switches::kDisableEasyUnlock); | 83 proximity_auth::switches::kDisableEasyUnlock); |
| 81 } | 84 } |
| 82 | 85 |
| 83 class EasyUnlockService::BluetoothDetector | 86 class EasyUnlockService::BluetoothDetector |
| 84 : public device::BluetoothAdapter::Observer { | 87 : public device::BluetoothAdapter::Observer, |
| 88 public apps::AppLifetimeMonitor::Observer { |
| 85 public: | 89 public: |
| 86 explicit BluetoothDetector(EasyUnlockService* service) | 90 explicit BluetoothDetector(EasyUnlockService* service) |
| 87 : service_(service), | 91 : service_(service), |
| 88 weak_ptr_factory_(this) { | 92 weak_ptr_factory_(this) { |
| 89 } | 93 } |
| 90 | 94 |
| 91 ~BluetoothDetector() override { | 95 ~BluetoothDetector() override { |
| 92 if (adapter_.get()) | 96 if (adapter_.get()) |
| 93 adapter_->RemoveObserver(this); | 97 adapter_->RemoveObserver(this); |
| 94 } | 98 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 108 void AdapterPresentChanged(device::BluetoothAdapter* adapter, | 112 void AdapterPresentChanged(device::BluetoothAdapter* adapter, |
| 109 bool present) override { | 113 bool present) override { |
| 110 service_->OnBluetoothAdapterPresentChanged(); | 114 service_->OnBluetoothAdapterPresentChanged(); |
| 111 } | 115 } |
| 112 | 116 |
| 113 private: | 117 private: |
| 114 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter) { | 118 void OnAdapterInitialized(scoped_refptr<device::BluetoothAdapter> adapter) { |
| 115 adapter_ = adapter; | 119 adapter_ = adapter; |
| 116 adapter_->AddObserver(this); | 120 adapter_->AddObserver(this); |
| 117 service_->OnBluetoothAdapterPresentChanged(); | 121 service_->OnBluetoothAdapterPresentChanged(); |
| 122 |
| 123 // TODO(tengs): At the moment, there is no way for Bluetooth discoverability |
| 124 // to be turned on except through the Easy Unlock setup. If we step on any |
| 125 // toes in the future then we need to revisit this guard. |
| 126 if (adapter_->IsDiscoverable()) |
| 127 TurnOffBluetoothDiscoverability(); |
| 128 } |
| 129 |
| 130 // apps::AppLifetimeMonitor::Observer: |
| 131 void OnAppDeactivated(Profile* profile, const std::string& app_id) override { |
| 132 // TODO(tengs): Refactor the lifetime management to EasyUnlockAppManager. |
| 133 if (app_id == extension_misc::kEasyUnlockAppId) |
| 134 TurnOffBluetoothDiscoverability(); |
| 135 } |
| 136 |
| 137 void OnAppStop(Profile* profile, const std::string& app_id) override { |
| 138 // TODO(tengs): Refactor the lifetime management to EasyUnlockAppManager. |
| 139 if (app_id == extension_misc::kEasyUnlockAppId) |
| 140 TurnOffBluetoothDiscoverability(); |
| 141 } |
| 142 |
| 143 void TurnOffBluetoothDiscoverability() { |
| 144 if (adapter_) { |
| 145 adapter_->SetDiscoverable( |
| 146 false, base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); |
| 147 } |
| 118 } | 148 } |
| 119 | 149 |
| 120 // Owner of this class and should out-live this class. | 150 // Owner of this class and should out-live this class. |
| 121 EasyUnlockService* service_; | 151 EasyUnlockService* service_; |
| 122 scoped_refptr<device::BluetoothAdapter> adapter_; | 152 scoped_refptr<device::BluetoothAdapter> adapter_; |
| 123 base::WeakPtrFactory<BluetoothDetector> weak_ptr_factory_; | 153 base::WeakPtrFactory<BluetoothDetector> weak_ptr_factory_; |
| 124 | 154 |
| 125 DISALLOW_COPY_AND_ASSIGN(BluetoothDetector); | 155 DISALLOW_COPY_AND_ASSIGN(BluetoothDetector); |
| 126 }; | 156 }; |
| 127 | 157 |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 | 795 |
| 766 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt | 796 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt |
| 767 // failed. | 797 // failed. |
| 768 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) | 798 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) |
| 769 ->PrepareTpmKey(true /* check_private_key */, | 799 ->PrepareTpmKey(true /* check_private_key */, |
| 770 base::Closure()); | 800 base::Closure()); |
| 771 #endif // defined(OS_CHROMEOS) | 801 #endif // defined(OS_CHROMEOS) |
| 772 | 802 |
| 773 tpm_key_checked_ = true; | 803 tpm_key_checked_ = true; |
| 774 } | 804 } |
| OLD | NEW |