OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/proximity_auth/ble/proximity_auth_ble_system.h" | 5 #include "components/proximity_auth/ble/proximity_auth_ble_system.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
11 #include "components/proximity_auth/ble/bluetooth_low_energy_connection.h" | 11 #include "components/proximity_auth/ble/bluetooth_low_energy_connection.h" |
12 #include "components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h
" | 12 #include "components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h
" |
13 #include "components/proximity_auth/ble/fake_wire_message.h" | 13 #include "components/proximity_auth/ble/fake_wire_message.h" |
14 #include "components/proximity_auth/connection.h" | 14 #include "components/proximity_auth/connection.h" |
15 #include "components/proximity_auth/cryptauth/base64url.h" | 15 #include "components/proximity_auth/cryptauth/base64url.h" |
16 #include "components/proximity_auth/cryptauth/cryptauth_client.h" | 16 #include "components/proximity_auth/cryptauth/cryptauth_client.h" |
| 17 #include "components/proximity_auth/proximity_auth_client.h" |
17 #include "components/proximity_auth/remote_device.h" | 18 #include "components/proximity_auth/remote_device.h" |
18 #include "device/bluetooth/bluetooth_device.h" | 19 #include "device/bluetooth/bluetooth_device.h" |
19 #include "device/bluetooth/bluetooth_gatt_connection.h" | 20 #include "device/bluetooth/bluetooth_gatt_connection.h" |
20 | 21 |
21 namespace proximity_auth { | 22 namespace proximity_auth { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 // The UUID of the Bluetooth Low Energy service. | 26 // The UUID of the Bluetooth Low Energy service. |
26 const char kSmartLockServiceUUID[] = "b3b7e28e-a000-3e17-bd86-6e97b9e28c11"; | 27 const char kSmartLockServiceUUID[] = "b3b7e28e-a000-3e17-bd86-6e97b9e28c11"; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 ScreenlockBridge::Observer* observer) { | 62 ScreenlockBridge::Observer* observer) { |
62 screenlock_bridge_->AddObserver(observer); | 63 screenlock_bridge_->AddObserver(observer); |
63 } | 64 } |
64 | 65 |
65 void ProximityAuthBleSystem::ScreenlockBridgeAdapter::RemoveObserver( | 66 void ProximityAuthBleSystem::ScreenlockBridgeAdapter::RemoveObserver( |
66 ScreenlockBridge::Observer* observer) { | 67 ScreenlockBridge::Observer* observer) { |
67 screenlock_bridge_->RemoveObserver(observer); | 68 screenlock_bridge_->RemoveObserver(observer); |
68 } | 69 } |
69 | 70 |
70 void ProximityAuthBleSystem::ScreenlockBridgeAdapter::Unlock( | 71 void ProximityAuthBleSystem::ScreenlockBridgeAdapter::Unlock( |
71 content::BrowserContext* browser_context) { | 72 ProximityAuthClient* client) { |
72 screenlock_bridge_->Unlock(browser_context); | 73 screenlock_bridge_->Unlock(client->GetAuthenticatedUsername()); |
73 } | 74 } |
74 | 75 |
75 ProximityAuthBleSystem::ProximityAuthBleSystem( | 76 ProximityAuthBleSystem::ProximityAuthBleSystem( |
76 ScreenlockBridge* screenlock_bridge, | 77 ScreenlockBridge* screenlock_bridge, |
77 content::BrowserContext* browser_context, | 78 ProximityAuthClient* proximity_auth_client, |
78 scoped_ptr<CryptAuthClientFactory> cryptauth_client_factory) | 79 scoped_ptr<CryptAuthClientFactory> cryptauth_client_factory) |
79 : screenlock_bridge_(new ProximityAuthBleSystem::ScreenlockBridgeAdapter( | 80 : screenlock_bridge_(new ProximityAuthBleSystem::ScreenlockBridgeAdapter( |
80 screenlock_bridge)), | 81 screenlock_bridge)), |
81 browser_context_(browser_context), | 82 proximity_auth_client_(proximity_auth_client), |
82 cryptauth_client_factory_(cryptauth_client_factory.Pass()), | 83 cryptauth_client_factory_(cryptauth_client_factory.Pass()), |
83 is_polling_screen_state_(false), | 84 is_polling_screen_state_(false), |
84 weak_ptr_factory_(this) { | 85 weak_ptr_factory_(this) { |
85 VLOG(1) << "Starting Proximity Auth over Bluetooth Low Energy."; | 86 VLOG(1) << "Starting Proximity Auth over Bluetooth Low Energy."; |
86 screenlock_bridge_->AddObserver(this); | 87 screenlock_bridge_->AddObserver(this); |
87 } | 88 } |
88 | 89 |
89 ProximityAuthBleSystem::ProximityAuthBleSystem( | 90 ProximityAuthBleSystem::ProximityAuthBleSystem( |
90 ScreenlockBridgeAdapter* screenlock_bridge, | 91 scoped_ptr<ScreenlockBridgeAdapter> screenlock_bridge, |
91 content::BrowserContext* browser_context) | 92 ProximityAuthClient* proximity_auth_client) |
92 : screenlock_bridge_(screenlock_bridge), | 93 : screenlock_bridge_(screenlock_bridge.Pass()), |
93 browser_context_(browser_context), | 94 proximity_auth_client_(proximity_auth_client), |
94 is_polling_screen_state_(false), | 95 is_polling_screen_state_(false), |
95 weak_ptr_factory_(this) { | 96 weak_ptr_factory_(this) { |
96 VLOG(1) << "Starting Proximity Auth over Bluetooth Low Energy."; | 97 VLOG(1) << "Starting Proximity Auth over Bluetooth Low Energy."; |
97 screenlock_bridge_->AddObserver(this); | 98 screenlock_bridge_->AddObserver(this); |
98 } | 99 } |
99 | 100 |
100 ProximityAuthBleSystem::~ProximityAuthBleSystem() { | 101 ProximityAuthBleSystem::~ProximityAuthBleSystem() { |
101 VLOG(1) << "Stopping Proximity over Bluetooth Low Energy."; | 102 VLOG(1) << "Stopping Proximity over Bluetooth Low Energy."; |
102 screenlock_bridge_->RemoveObserver(this); | 103 screenlock_bridge_->RemoveObserver(this); |
103 if (connection_) | 104 if (connection_) |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 const WireMessage& message) { | 200 const WireMessage& message) { |
200 VLOG(1) << "Message received: " << message.payload(); | 201 VLOG(1) << "Message received: " << message.payload(); |
201 | 202 |
202 // Unlock the screen when the remote device sends an unlock signal. | 203 // Unlock the screen when the remote device sends an unlock signal. |
203 // | 204 // |
204 // Note that this magically unlocks Chrome (no user interaction is needed). | 205 // Note that this magically unlocks Chrome (no user interaction is needed). |
205 // This user experience for this operation will be greately improved once | 206 // This user experience for this operation will be greately improved once |
206 // the Proximity Auth Unlock Manager migration to C++ is done. | 207 // the Proximity Auth Unlock Manager migration to C++ is done. |
207 if (message.payload() == kScreenUnlocked) { | 208 if (message.payload() == kScreenUnlocked) { |
208 VLOG(1) << "Device unlocked. Unlock."; | 209 VLOG(1) << "Device unlocked. Unlock."; |
209 screenlock_bridge_->Unlock(browser_context_); | 210 screenlock_bridge_->Unlock(proximity_auth_client_); |
210 } | 211 } |
211 } | 212 } |
212 | 213 |
213 void ProximityAuthBleSystem::OnConnectionFound( | 214 void ProximityAuthBleSystem::OnConnectionFound( |
214 scoped_ptr<Connection> connection) { | 215 scoped_ptr<Connection> connection) { |
215 VLOG(1) << "Connection found."; | 216 VLOG(1) << "Connection found."; |
216 | 217 |
217 connection_ = connection.Pass(); | 218 connection_ = connection.Pass(); |
218 if (connection_) { | 219 if (connection_) { |
219 connection_->AddObserver(this); | 220 connection_->AddObserver(this); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 weak_ptr_factory_.GetWeakPtr()), | 262 weak_ptr_factory_.GetWeakPtr()), |
262 base::TimeDelta::FromSeconds(kPollingIntervalSeconds)); | 263 base::TimeDelta::FromSeconds(kPollingIntervalSeconds)); |
263 } | 264 } |
264 } | 265 } |
265 | 266 |
266 void ProximityAuthBleSystem::StopPollingScreenState() { | 267 void ProximityAuthBleSystem::StopPollingScreenState() { |
267 is_polling_screen_state_ = false; | 268 is_polling_screen_state_ = false; |
268 } | 269 } |
269 | 270 |
270 } // namespace proximity_auth | 271 } // namespace proximity_auth |
OLD | NEW |