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/cryptauth/proto/cryptauth_api.pb.h" | 17 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" |
18 #include "components/proximity_auth/logging/logging.h" | 18 #include "components/proximity_auth/logging/logging.h" |
| 19 #include "components/proximity_auth/proximity_auth_client.h" |
19 #include "components/proximity_auth/remote_device.h" | 20 #include "components/proximity_auth/remote_device.h" |
20 #include "device/bluetooth/bluetooth_device.h" | 21 #include "device/bluetooth/bluetooth_device.h" |
21 #include "device/bluetooth/bluetooth_gatt_connection.h" | 22 #include "device/bluetooth/bluetooth_gatt_connection.h" |
22 | 23 |
23 namespace proximity_auth { | 24 namespace proximity_auth { |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 // The UUID of the Bluetooth Low Energy service. | 28 // The UUID of the Bluetooth Low Energy service. |
28 const char kSmartLockServiceUUID[] = "b3b7e28e-a000-3e17-bd86-6e97b9e28c11"; | 29 const char kSmartLockServiceUUID[] = "b3b7e28e-a000-3e17-bd86-6e97b9e28c11"; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 ScreenlockBridge::Observer* observer) { | 64 ScreenlockBridge::Observer* observer) { |
64 screenlock_bridge_->AddObserver(observer); | 65 screenlock_bridge_->AddObserver(observer); |
65 } | 66 } |
66 | 67 |
67 void ProximityAuthBleSystem::ScreenlockBridgeAdapter::RemoveObserver( | 68 void ProximityAuthBleSystem::ScreenlockBridgeAdapter::RemoveObserver( |
68 ScreenlockBridge::Observer* observer) { | 69 ScreenlockBridge::Observer* observer) { |
69 screenlock_bridge_->RemoveObserver(observer); | 70 screenlock_bridge_->RemoveObserver(observer); |
70 } | 71 } |
71 | 72 |
72 void ProximityAuthBleSystem::ScreenlockBridgeAdapter::Unlock( | 73 void ProximityAuthBleSystem::ScreenlockBridgeAdapter::Unlock( |
73 content::BrowserContext* browser_context) { | 74 ProximityAuthClient* client) { |
74 screenlock_bridge_->Unlock(browser_context); | 75 screenlock_bridge_->Unlock(client->GetAuthenticatedUsername()); |
75 } | 76 } |
76 | 77 |
77 ProximityAuthBleSystem::ProximityAuthBleSystem( | 78 ProximityAuthBleSystem::ProximityAuthBleSystem( |
78 ScreenlockBridge* screenlock_bridge, | 79 ScreenlockBridge* screenlock_bridge, |
79 content::BrowserContext* browser_context, | 80 ProximityAuthClient* proximity_auth_client, |
80 scoped_ptr<CryptAuthClientFactory> cryptauth_client_factory) | 81 scoped_ptr<CryptAuthClientFactory> cryptauth_client_factory) |
81 : screenlock_bridge_(new ProximityAuthBleSystem::ScreenlockBridgeAdapter( | 82 : screenlock_bridge_(new ProximityAuthBleSystem::ScreenlockBridgeAdapter( |
82 screenlock_bridge)), | 83 screenlock_bridge)), |
83 browser_context_(browser_context), | 84 proximity_auth_client_(proximity_auth_client), |
84 cryptauth_client_factory_(cryptauth_client_factory.Pass()), | 85 cryptauth_client_factory_(cryptauth_client_factory.Pass()), |
85 is_polling_screen_state_(false), | 86 is_polling_screen_state_(false), |
86 weak_ptr_factory_(this) { | 87 weak_ptr_factory_(this) { |
87 PA_LOG(INFO) << "Starting Proximity Auth over Bluetooth Low Energy."; | 88 PA_LOG(INFO) << "Starting Proximity Auth over Bluetooth Low Energy."; |
88 screenlock_bridge_->AddObserver(this); | 89 screenlock_bridge_->AddObserver(this); |
89 } | 90 } |
90 | 91 |
91 ProximityAuthBleSystem::ProximityAuthBleSystem( | 92 ProximityAuthBleSystem::ProximityAuthBleSystem( |
92 ScreenlockBridgeAdapter* screenlock_bridge, | 93 scoped_ptr<ScreenlockBridgeAdapter> screenlock_bridge, |
93 content::BrowserContext* browser_context) | 94 ProximityAuthClient* proximity_auth_client) |
94 : screenlock_bridge_(screenlock_bridge), | 95 : screenlock_bridge_(screenlock_bridge.Pass()), |
95 browser_context_(browser_context), | 96 proximity_auth_client_(proximity_auth_client), |
96 is_polling_screen_state_(false), | 97 is_polling_screen_state_(false), |
97 weak_ptr_factory_(this) { | 98 weak_ptr_factory_(this) { |
98 PA_LOG(INFO) << "Starting Proximity Auth over Bluetooth Low Energy."; | 99 PA_LOG(INFO) << "Starting Proximity Auth over Bluetooth Low Energy."; |
99 screenlock_bridge_->AddObserver(this); | 100 screenlock_bridge_->AddObserver(this); |
100 } | 101 } |
101 | 102 |
102 ProximityAuthBleSystem::~ProximityAuthBleSystem() { | 103 ProximityAuthBleSystem::~ProximityAuthBleSystem() { |
103 PA_LOG(INFO) << "Stopping Proximity over Bluetooth Low Energy."; | 104 PA_LOG(INFO) << "Stopping Proximity over Bluetooth Low Energy."; |
104 screenlock_bridge_->RemoveObserver(this); | 105 screenlock_bridge_->RemoveObserver(this); |
105 if (connection_) | 106 if (connection_) |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 // TODO(sacomoto): change this when WireMessage is fully implemented. | 204 // TODO(sacomoto): change this when WireMessage is fully implemented. |
204 PA_LOG(INFO) << "Message received: " << message.payload(); | 205 PA_LOG(INFO) << "Message received: " << message.payload(); |
205 | 206 |
206 // Unlock the screen when the remote device sends an unlock signal. | 207 // Unlock the screen when the remote device sends an unlock signal. |
207 // | 208 // |
208 // Note that this magically unlocks Chrome (no user interaction is needed). | 209 // Note that this magically unlocks Chrome (no user interaction is needed). |
209 // This user experience for this operation will be greately improved once | 210 // This user experience for this operation will be greately improved once |
210 // the Proximity Auth Unlock Manager migration to C++ is done. | 211 // the Proximity Auth Unlock Manager migration to C++ is done. |
211 if (message.payload() == kScreenUnlocked) { | 212 if (message.payload() == kScreenUnlocked) { |
212 PA_LOG(INFO) << "Device unlocked. Unlock."; | 213 PA_LOG(INFO) << "Device unlocked. Unlock."; |
213 screenlock_bridge_->Unlock(browser_context_); | 214 screenlock_bridge_->Unlock(proximity_auth_client_); |
214 } | 215 } |
215 } | 216 } |
216 | 217 |
217 void ProximityAuthBleSystem::OnConnectionFound( | 218 void ProximityAuthBleSystem::OnConnectionFound( |
218 scoped_ptr<Connection> connection) { | 219 scoped_ptr<Connection> connection) { |
219 PA_LOG(INFO) << "Connection found."; | 220 PA_LOG(INFO) << "Connection found."; |
220 | 221 |
221 connection_ = connection.Pass(); | 222 connection_ = connection.Pass(); |
222 if (connection_) { | 223 if (connection_) { |
223 connection_->AddObserver(this); | 224 connection_->AddObserver(this); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 weak_ptr_factory_.GetWeakPtr()), | 266 weak_ptr_factory_.GetWeakPtr()), |
266 base::TimeDelta::FromSeconds(kPollingIntervalSeconds)); | 267 base::TimeDelta::FromSeconds(kPollingIntervalSeconds)); |
267 } | 268 } |
268 } | 269 } |
269 | 270 |
270 void ProximityAuthBleSystem::StopPollingScreenState() { | 271 void ProximityAuthBleSystem::StopPollingScreenState() { |
271 is_polling_screen_state_ = false; | 272 is_polling_screen_state_ = false; |
272 } | 273 } |
273 | 274 |
274 } // namespace proximity_auth | 275 } // namespace proximity_auth |
OLD | NEW |