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/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h
" |
10 #include "components/proximity_auth/connection.h" | 10 #include "components/proximity_auth/connection.h" |
11 #include "device/bluetooth/bluetooth_device.h" | 11 #include "device/bluetooth/bluetooth_device.h" |
12 | 12 #include "device/bluetooth/bluetooth_gatt_connection.h" |
13 #include "components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h
" | |
14 | 13 |
15 namespace proximity_auth { | 14 namespace proximity_auth { |
16 | 15 |
| 16 namespace { |
| 17 |
| 18 // The UUID of the Bluetooth Low Energy service. |
17 const char kSmartLockServiceUUID[] = "b3b7e28e-a000-3e17-bd86-6e97b9e28c11"; | 19 const char kSmartLockServiceUUID[] = "b3b7e28e-a000-3e17-bd86-6e97b9e28c11"; |
18 | 20 |
19 void ConnectionCallback( | 21 } // namespace |
20 scoped_ptr<device::BluetoothGattConnection> connection) { | |
21 VLOG(1) << "Connection established"; | |
22 } | |
23 | 22 |
24 ProximityAuthBleSystem::ProximityAuthBleSystem() { | 23 ProximityAuthBleSystem::ProximityAuthBleSystem( |
| 24 ScreenlockBridge* screenlock_bridge, |
| 25 content::BrowserContext* browser_context) |
| 26 : screenlock_bridge_(screenlock_bridge), |
| 27 browser_context_(browser_context), |
| 28 weak_ptr_factory_(this) { |
| 29 DCHECK(screenlock_bridge_); |
| 30 DCHECK(browser_context_); |
25 VLOG(1) << "Starting Proximity Auth over Bluetooth Low Energy."; | 31 VLOG(1) << "Starting Proximity Auth over Bluetooth Low Energy."; |
26 connection_finder_ = scoped_ptr<BluetoothLowEnergyConnectionFinder>( | 32 screenlock_bridge_->AddObserver(this); |
27 new BluetoothLowEnergyConnectionFinder(kSmartLockServiceUUID)); | |
28 connection_finder_->Find(base::Bind(&ConnectionCallback)); | |
29 } | 33 } |
30 | 34 |
31 ProximityAuthBleSystem::~ProximityAuthBleSystem() { | 35 ProximityAuthBleSystem::~ProximityAuthBleSystem() { |
32 VLOG(1) << "Stopping Proximity over Bluetooth Low Energy."; | 36 VLOG(1) << "Stopping Proximity over Bluetooth Low Energy."; |
| 37 screenlock_bridge_->RemoveObserver(this); |
| 38 } |
| 39 |
| 40 void ProximityAuthBleSystem::OnScreenDidLock( |
| 41 ScreenlockBridge::LockHandler::ScreenType screen_type) { |
| 42 VLOG(1) << "OnScreenDidLock: " << screen_type; |
| 43 switch (screen_type) { |
| 44 case ScreenlockBridge::LockHandler::SIGNIN_SCREEN: |
| 45 connection_finder_.reset(); |
| 46 break; |
| 47 case ScreenlockBridge::LockHandler::LOCK_SCREEN: |
| 48 DCHECK(!connection_finder_); |
| 49 connection_finder_.reset( |
| 50 new BluetoothLowEnergyConnectionFinder(kSmartLockServiceUUID)); |
| 51 connection_finder_->Find( |
| 52 base::Bind(&ProximityAuthBleSystem::OnConnectionFound, |
| 53 weak_ptr_factory_.GetWeakPtr())); |
| 54 break; |
| 55 case ScreenlockBridge::LockHandler::OTHER_SCREEN: |
| 56 connection_finder_.reset(); |
| 57 break; |
| 58 } |
| 59 }; |
| 60 |
| 61 void ProximityAuthBleSystem::OnScreenDidUnlock( |
| 62 ScreenlockBridge::LockHandler::ScreenType screen_type) { |
| 63 VLOG(1) << "OnScreenDidUnlock: " << screen_type; |
33 connection_finder_.reset(); | 64 connection_finder_.reset(); |
| 65 }; |
| 66 |
| 67 void ProximityAuthBleSystem::OnFocusedUserChanged(const std::string& user_id) { |
| 68 VLOG(1) << "OnFocusedUserChanged: " << user_id; |
| 69 }; |
| 70 |
| 71 void ProximityAuthBleSystem::OnConnectionFound( |
| 72 scoped_ptr<device::BluetoothGattConnection> connection) { |
| 73 // Unlock the screen when a connection is found. |
| 74 // |
| 75 // Note that this magically unlocks Chrome (no user interaction is needed). |
| 76 // This user experience for this operation will be greately improved once |
| 77 // the Proximity Auth Unlock Manager migration to C++ is done. |
| 78 screenlock_bridge_->Unlock(browser_context_); |
34 } | 79 } |
35 | 80 |
36 } // namespace proximity_auth | 81 } // namespace proximity_auth |
OLD | NEW |