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