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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "apps/app_lifetime_monitor.h" | 9 #include "apps/app_lifetime_monitor.h" |
10 #include "apps/app_lifetime_monitor_factory.h" | 10 #include "apps/app_lifetime_monitor_factory.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 #endif | 100 #endif |
101 } | 101 } |
102 | 102 |
103 class EasyUnlockService::BluetoothDetector | 103 class EasyUnlockService::BluetoothDetector |
104 : public device::BluetoothAdapter::Observer, | 104 : public device::BluetoothAdapter::Observer, |
105 public apps::AppLifetimeMonitor::Observer { | 105 public apps::AppLifetimeMonitor::Observer { |
106 public: | 106 public: |
107 explicit BluetoothDetector(EasyUnlockService* service) | 107 explicit BluetoothDetector(EasyUnlockService* service) |
108 : service_(service), | 108 : service_(service), |
109 weak_ptr_factory_(this) { | 109 weak_ptr_factory_(this) { |
110 apps::AppLifetimeMonitorFactory::GetForProfile(service_->profile()) | 110 apps::AppLifetimeMonitorFactory::GetForBrowserContext(service_->profile()) |
111 ->AddObserver(this); | 111 ->AddObserver(this); |
112 } | 112 } |
113 | 113 |
114 ~BluetoothDetector() override { | 114 ~BluetoothDetector() override { |
115 if (adapter_.get()) | 115 if (adapter_.get()) |
116 adapter_->RemoveObserver(this); | 116 adapter_->RemoveObserver(this); |
117 apps::AppLifetimeMonitorFactory::GetForProfile(service_->profile()) | 117 apps::AppLifetimeMonitorFactory::GetForBrowserContext(service_->profile()) |
118 ->RemoveObserver(this); | 118 ->RemoveObserver(this); |
119 } | 119 } |
120 | 120 |
121 void Initialize() { | 121 void Initialize() { |
122 if (!device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) | 122 if (!device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) |
123 return; | 123 return; |
124 | 124 |
125 device::BluetoothAdapterFactory::GetAdapter( | 125 device::BluetoothAdapterFactory::GetAdapter( |
126 base::Bind(&BluetoothDetector::OnAdapterInitialized, | 126 base::Bind(&BluetoothDetector::OnAdapterInitialized, |
127 weak_ptr_factory_.GetWeakPtr())); | 127 weak_ptr_factory_.GetWeakPtr())); |
(...skipping 14 matching lines...) Expand all Loading... |
142 service_->OnBluetoothAdapterPresentChanged(); | 142 service_->OnBluetoothAdapterPresentChanged(); |
143 | 143 |
144 // TODO(tengs): At the moment, there is no way for Bluetooth discoverability | 144 // TODO(tengs): At the moment, there is no way for Bluetooth discoverability |
145 // to be turned on except through the Easy Unlock setup. If we step on any | 145 // to be turned on except through the Easy Unlock setup. If we step on any |
146 // toes in the future then we need to revisit this guard. | 146 // toes in the future then we need to revisit this guard. |
147 if (adapter_->IsDiscoverable()) | 147 if (adapter_->IsDiscoverable()) |
148 TurnOffBluetoothDiscoverability(); | 148 TurnOffBluetoothDiscoverability(); |
149 } | 149 } |
150 | 150 |
151 // apps::AppLifetimeMonitor::Observer: | 151 // apps::AppLifetimeMonitor::Observer: |
152 void OnAppDeactivated(Profile* profile, const std::string& app_id) override { | 152 void OnAppDeactivated(content::BrowserContext* context, |
| 153 const std::string& app_id) override { |
153 // TODO(tengs): Refactor the lifetime management to EasyUnlockAppManager. | 154 // TODO(tengs): Refactor the lifetime management to EasyUnlockAppManager. |
154 if (app_id == extension_misc::kEasyUnlockAppId) | 155 if (app_id == extension_misc::kEasyUnlockAppId) |
155 TurnOffBluetoothDiscoverability(); | 156 TurnOffBluetoothDiscoverability(); |
156 } | 157 } |
157 | 158 |
158 void OnAppStop(Profile* profile, const std::string& app_id) override { | 159 void OnAppStop(content::BrowserContext* context, |
| 160 const std::string& app_id) override { |
159 // TODO(tengs): Refactor the lifetime management to EasyUnlockAppManager. | 161 // TODO(tengs): Refactor the lifetime management to EasyUnlockAppManager. |
160 if (app_id == extension_misc::kEasyUnlockAppId) | 162 if (app_id == extension_misc::kEasyUnlockAppId) |
161 TurnOffBluetoothDiscoverability(); | 163 TurnOffBluetoothDiscoverability(); |
162 } | 164 } |
163 | 165 |
164 void TurnOffBluetoothDiscoverability() { | 166 void TurnOffBluetoothDiscoverability() { |
165 if (adapter_) { | 167 if (adapter_) { |
166 adapter_->SetDiscoverable( | 168 adapter_->SetDiscoverable( |
167 false, base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); | 169 false, base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); |
168 } | 170 } |
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 | 885 |
884 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt | 886 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt |
885 // failed. | 887 // failed. |
886 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) | 888 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) |
887 ->PrepareTpmKey(true /* check_private_key */, | 889 ->PrepareTpmKey(true /* check_private_key */, |
888 base::Closure()); | 890 base::Closure()); |
889 #endif // defined(OS_CHROMEOS) | 891 #endif // defined(OS_CHROMEOS) |
890 | 892 |
891 tpm_key_checked_ = true; | 893 tpm_key_checked_ = true; |
892 } | 894 } |
OLD | NEW |