Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: components/proximity_auth/ble/proximity_auth_ble_system.cc

Issue 1116963002: Bluetooth low energy connection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/proximity_auth/ble/bluetooth_low_energy_connection.h"
9 #include "components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h " 10 #include "components/proximity_auth/ble/bluetooth_low_energy_connection_finder.h "
10 #include "components/proximity_auth/connection.h" 11 #include "components/proximity_auth/connection.h"
12 #include "components/proximity_auth/remote_device.h"
11 #include "device/bluetooth/bluetooth_device.h" 13 #include "device/bluetooth/bluetooth_device.h"
12 #include "device/bluetooth/bluetooth_gatt_connection.h" 14 #include "device/bluetooth/bluetooth_gatt_connection.h"
13 15
14 namespace proximity_auth { 16 namespace proximity_auth {
15 17
16 namespace { 18 namespace {
17 19
18 // The UUID of the Bluetooth Low Energy service. 20 // The UUID of the Bluetooth Low Energy service.
19 const char kSmartLockServiceUUID[] = "b3b7e28e-a000-3e17-bd86-6e97b9e28c11"; 21 const char kSmartLockServiceUUID[] = "b3b7e28e-a000-3e17-bd86-6e97b9e28c11";
20 22
23 // The UUID of the characteristic used to send data to the peripheral.
24 const char kToPeripheralCharUUID[] = "977c6674-1239-4e72-993b-502369b8bb5a";
25
26 // The UUID of the characteristic used to receive data from the peripheral.
27 const char kFromPeripheralCharUUID[] = "f4b904a2-a030-43b3-98a8-221c536c03cb";
28
21 } // namespace 29 } // namespace
22 30
23 ProximityAuthBleSystem::ProximityAuthBleSystem( 31 ProximityAuthBleSystem::ProximityAuthBleSystem(
24 ScreenlockBridge* screenlock_bridge, 32 ScreenlockBridge* screenlock_bridge,
25 content::BrowserContext* browser_context) 33 content::BrowserContext* browser_context)
26 : screenlock_bridge_(screenlock_bridge), 34 : screenlock_bridge_(screenlock_bridge),
27 browser_context_(browser_context), 35 browser_context_(browser_context),
28 weak_ptr_factory_(this) { 36 weak_ptr_factory_(this) {
29 DCHECK(screenlock_bridge_); 37 DCHECK(screenlock_bridge_);
30 DCHECK(browser_context_); 38 DCHECK(browser_context_);
31 VLOG(1) << "Starting Proximity Auth over Bluetooth Low Energy."; 39 VLOG(1) << "Starting Proximity Auth over Bluetooth Low Energy.";
32 screenlock_bridge_->AddObserver(this); 40 screenlock_bridge_->AddObserver(this);
33 } 41 }
34 42
35 ProximityAuthBleSystem::~ProximityAuthBleSystem() { 43 ProximityAuthBleSystem::~ProximityAuthBleSystem() {
36 VLOG(1) << "Stopping Proximity over Bluetooth Low Energy."; 44 VLOG(1) << "Stopping Proximity over Bluetooth Low Energy.";
37 screenlock_bridge_->RemoveObserver(this); 45 screenlock_bridge_->RemoveObserver(this);
38 } 46 }
39 47
40 void ProximityAuthBleSystem::OnScreenDidLock( 48 void ProximityAuthBleSystem::OnScreenDidLock(
41 ScreenlockBridge::LockHandler::ScreenType screen_type) { 49 ScreenlockBridge::LockHandler::ScreenType screen_type) {
42 VLOG(1) << "OnScreenDidLock: " << screen_type; 50 VLOG(1) << "OnScreenDidLock: " << screen_type;
43 switch (screen_type) { 51 switch (screen_type) {
44 case ScreenlockBridge::LockHandler::SIGNIN_SCREEN: 52 case ScreenlockBridge::LockHandler::SIGNIN_SCREEN:
45 connection_finder_.reset(); 53 connection_finder_.reset();
46 break; 54 break;
47 case ScreenlockBridge::LockHandler::LOCK_SCREEN: 55 case ScreenlockBridge::LockHandler::LOCK_SCREEN:
48 DCHECK(!connection_finder_); 56 DCHECK(!connection_finder_);
49 connection_finder_.reset( 57 connection_finder_.reset(new BluetoothLowEnergyConnectionFinder(
50 new BluetoothLowEnergyConnectionFinder(kSmartLockServiceUUID)); 58 kSmartLockServiceUUID, kToPeripheralCharUUID,
59 kFromPeripheralCharUUID));
51 connection_finder_->Find( 60 connection_finder_->Find(
52 base::Bind(&ProximityAuthBleSystem::OnConnectionFound, 61 base::Bind(&ProximityAuthBleSystem::OnConnectionFound,
53 weak_ptr_factory_.GetWeakPtr())); 62 weak_ptr_factory_.GetWeakPtr()));
54 break; 63 break;
55 case ScreenlockBridge::LockHandler::OTHER_SCREEN: 64 case ScreenlockBridge::LockHandler::OTHER_SCREEN:
56 connection_finder_.reset(); 65 connection_finder_.reset();
57 break; 66 break;
58 } 67 }
59 }; 68 };
60 69
61 void ProximityAuthBleSystem::OnScreenDidUnlock( 70 void ProximityAuthBleSystem::OnScreenDidUnlock(
62 ScreenlockBridge::LockHandler::ScreenType screen_type) { 71 ScreenlockBridge::LockHandler::ScreenType screen_type) {
63 VLOG(1) << "OnScreenDidUnlock: " << screen_type; 72 VLOG(1) << "OnScreenDidUnlock: " << screen_type;
73 connection_->Disconnect();
74 connection_.reset();
64 connection_finder_.reset(); 75 connection_finder_.reset();
65 }; 76 };
66 77
67 void ProximityAuthBleSystem::OnFocusedUserChanged(const std::string& user_id) { 78 void ProximityAuthBleSystem::OnFocusedUserChanged(const std::string& user_id) {
68 VLOG(1) << "OnFocusedUserChanged: " << user_id; 79 VLOG(1) << "OnFocusedUserChanged: " << user_id;
69 }; 80 };
70 81
71 void ProximityAuthBleSystem::OnConnectionFound( 82 void ProximityAuthBleSystem::OnConnectionFound(
72 scoped_ptr<device::BluetoothGattConnection> connection) { 83 scoped_ptr<Connection> connection) {
73 VLOG(1) << "Connection found. Unlock."; 84 VLOG(1) << "Connection found. Unlock.";
74 85
75 // Close the connection as it it no longer needed. 86 connection_ = connection.Pass();
76 connection_finder_->CloseConnection(connection.Pass());
77 87
78 // Unlock the screen when a connection is found. 88 // Unlock the screen when a connection is found.
79 // 89 //
80 // Note that this magically unlocks Chrome (no user interaction is needed). 90 // Note that this magically unlocks Chrome (no user interaction is needed).
81 // This user experience for this operation will be greately improved once 91 // This user experience for this operation will be greately improved once
82 // the Proximity Auth Unlock Manager migration to C++ is done. 92 // the Proximity Auth Unlock Manager migration to C++ is done.
83 screenlock_bridge_->Unlock(browser_context_); 93 screenlock_bridge_->Unlock(browser_context_);
84 } 94 }
85 95
86 } // namespace proximity_auth 96 } // namespace proximity_auth
OLDNEW
« no previous file with comments | « components/proximity_auth/ble/proximity_auth_ble_system.h ('k') | components/proximity_auth/connection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698