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 #ifndef COMPONENTS_PROXIMITY_AUTH_BLE_PROXIMITY_AUTH_BLE_SYSTEM_H_ | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLE_PROXIMITY_AUTH_BLE_SYSTEM_H_ |
6 #define COMPONENTS_PROXIMITY_AUTH_BLE_PROXIMITY_AUTH_BLE_SYSTEM_H_ | 6 #define COMPONENTS_PROXIMITY_AUTH_BLE_PROXIMITY_AUTH_BLE_SYSTEM_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "components/proximity_auth/connection_observer.h" | 14 #include "components/proximity_auth/connection_observer.h" |
15 #include "components/proximity_auth/cryptauth/cryptauth_client.h" | 15 #include "components/proximity_auth/cryptauth/cryptauth_client.h" |
16 #include "components/proximity_auth/screenlock_bridge.h" | 16 #include "components/proximity_auth/screenlock_bridge.h" |
17 | 17 |
18 namespace content { | |
19 class BrowserContext; | |
20 } | |
21 | |
22 namespace device { | 18 namespace device { |
23 class BluetoothGattConnection; | 19 class BluetoothGattConnection; |
24 } | 20 } |
25 | 21 |
26 namespace proximity_auth { | 22 namespace proximity_auth { |
27 | 23 |
28 class BluetoothLowEnergyConnection; | 24 class BluetoothLowEnergyConnection; |
29 class BluetoothLowEnergyConnectionFinder; | 25 class BluetoothLowEnergyConnectionFinder; |
30 class Connection; | 26 class Connection; |
31 class ConnectionFinder; | 27 class ConnectionFinder; |
| 28 class ProximityAuthClient; |
32 | 29 |
33 // This is the main entry point to start Proximity Auth over Bluetooth Low | 30 // This is the main entry point to start Proximity Auth over Bluetooth Low |
34 // Energy. This is the underlying system for the Smart Lock features. It will | 31 // Energy. This is the underlying system for the Smart Lock features. It will |
35 // discover Bluetooth Low Energy phones and unlock the lock screen if the phone | 32 // discover Bluetooth Low Energy phones and unlock the lock screen if the phone |
36 // passes an authorization and authentication protocol. | 33 // passes an authorization and authentication protocol. |
37 class ProximityAuthBleSystem : public ScreenlockBridge::Observer, | 34 class ProximityAuthBleSystem : public ScreenlockBridge::Observer, |
38 public ConnectionObserver { | 35 public ConnectionObserver { |
39 public: | 36 public: |
40 ProximityAuthBleSystem( | 37 ProximityAuthBleSystem( |
41 ScreenlockBridge* screenlock_bridge, | 38 ScreenlockBridge* screenlock_bridge, |
42 content::BrowserContext* browser_context, | 39 ProximityAuthClient* proximity_auth_client, |
43 scoped_ptr<CryptAuthClientFactory> cryptauth_client_factory); | 40 scoped_ptr<CryptAuthClientFactory> cryptauth_client_factory); |
44 ~ProximityAuthBleSystem() override; | 41 ~ProximityAuthBleSystem() override; |
45 | 42 |
46 // ScreenlockBridge::Observer: | 43 // ScreenlockBridge::Observer: |
47 void OnScreenDidLock( | 44 void OnScreenDidLock( |
48 ScreenlockBridge::LockHandler::ScreenType screen_type) override; | 45 ScreenlockBridge::LockHandler::ScreenType screen_type) override; |
49 void OnScreenDidUnlock( | 46 void OnScreenDidUnlock( |
50 ScreenlockBridge::LockHandler::ScreenType screen_type) override; | 47 ScreenlockBridge::LockHandler::ScreenType screen_type) override; |
51 void OnFocusedUserChanged(const std::string& user_id) override; | 48 void OnFocusedUserChanged(const std::string& user_id) override; |
52 | 49 |
53 // proximity_auth::ConnectionObserver: | 50 // proximity_auth::ConnectionObserver: |
54 void OnConnectionStatusChanged(Connection* connection, | 51 void OnConnectionStatusChanged(Connection* connection, |
55 Connection::Status old_status, | 52 Connection::Status old_status, |
56 Connection::Status new_status) override; | 53 Connection::Status new_status) override; |
57 void OnMessageReceived(const Connection& connection, | 54 void OnMessageReceived(const Connection& connection, |
58 const WireMessage& message) override; | 55 const WireMessage& message) override; |
59 | 56 |
60 protected: | 57 protected: |
61 class ScreenlockBridgeAdapter { | 58 class ScreenlockBridgeAdapter { |
62 public: | 59 public: |
63 ScreenlockBridgeAdapter(ScreenlockBridge* screenlock_bridge); | 60 ScreenlockBridgeAdapter(ScreenlockBridge* screenlock_bridge); |
64 virtual ~ScreenlockBridgeAdapter(); | 61 virtual ~ScreenlockBridgeAdapter(); |
65 | 62 |
66 virtual void AddObserver(ScreenlockBridge::Observer* observer); | 63 virtual void AddObserver(ScreenlockBridge::Observer* observer); |
67 virtual void RemoveObserver(ScreenlockBridge::Observer* observer); | 64 virtual void RemoveObserver(ScreenlockBridge::Observer* observer); |
68 virtual void Unlock(content::BrowserContext* browser_context); | 65 virtual void Unlock(ProximityAuthClient* client); |
69 | 66 |
70 protected: | 67 protected: |
71 ScreenlockBridgeAdapter(); | 68 ScreenlockBridgeAdapter(); |
72 | 69 |
73 private: | 70 private: |
74 // Not owned. Must outlive this object. | 71 // Not owned. Must outlive this object. |
75 ScreenlockBridge* screenlock_bridge_; | 72 ScreenlockBridge* screenlock_bridge_; |
76 }; | 73 }; |
77 | 74 |
78 // Used for testing. | 75 // Used for testing. |
79 ProximityAuthBleSystem(ScreenlockBridgeAdapter* screenlock_bridge, | 76 ProximityAuthBleSystem(scoped_ptr<ScreenlockBridgeAdapter> screenlock_bridge, |
80 content::BrowserContext* browser_context); | 77 ProximityAuthClient* proximity_auth_client); |
81 | 78 |
82 // Virtual for testing. | 79 // Virtual for testing. |
83 virtual ConnectionFinder* CreateConnectionFinder(); | 80 virtual ConnectionFinder* CreateConnectionFinder(); |
84 | 81 |
85 private: | 82 private: |
86 // Fetches the the public keys of devices that can be used as unlock keys. | 83 // Fetches the the public keys of devices that can be used as unlock keys. |
87 void GetUnlockKeys(); | 84 void GetUnlockKeys(); |
88 | 85 |
89 // Callbacks for cryptauth::CryptAuthClient::GetMyDevices. | 86 // Callbacks for cryptauth::CryptAuthClient::GetMyDevices. |
90 void OnGetMyDevices(const cryptauth::GetMyDevicesResponse& response); | 87 void OnGetMyDevices(const cryptauth::GetMyDevicesResponse& response); |
91 void OnGetMyDevicesError(const std::string& error); | 88 void OnGetMyDevicesError(const std::string& error); |
92 | 89 |
93 // Handler for a new connection found event. | 90 // Handler for a new connection found event. |
94 void OnConnectionFound(scoped_ptr<Connection> connection); | 91 void OnConnectionFound(scoped_ptr<Connection> connection); |
95 | 92 |
96 // Start (recurrently) polling every |polling_interval_| ms for the screen | 93 // Start (recurrently) polling every |polling_interval_| ms for the screen |
97 // state of the remote device. | 94 // state of the remote device. |
98 void StartPollingScreenState(); | 95 void StartPollingScreenState(); |
99 | 96 |
100 // Stop polling for screen state of the remote device, if currently active. | 97 // Stop polling for screen state of the remote device, if currently active. |
101 void StopPollingScreenState(); | 98 void StopPollingScreenState(); |
102 | 99 |
103 scoped_ptr<ScreenlockBridgeAdapter> screenlock_bridge_; | 100 scoped_ptr<ScreenlockBridgeAdapter> screenlock_bridge_; |
104 | 101 |
105 content::BrowserContext* | 102 // Not owned. Must outlive this object. |
106 browser_context_; // Not owned. Must outlive this object. | 103 ProximityAuthClient* proximity_auth_client_; |
107 | 104 |
108 // Creates CryptAuth client instances to make API calls. | 105 // Creates CryptAuth client instances to make API calls. |
109 scoped_ptr<CryptAuthClientFactory> cryptauth_client_factory_; | 106 scoped_ptr<CryptAuthClientFactory> cryptauth_client_factory_; |
110 | 107 |
111 // We only support one concurrent API call. | 108 // We only support one concurrent API call. |
112 scoped_ptr<CryptAuthClient> cryptauth_client_; | 109 scoped_ptr<CryptAuthClient> cryptauth_client_; |
113 | 110 |
114 // Maps devices public keys to the device friendly name. | 111 // Maps devices public keys to the device friendly name. |
115 std::map<std::string, std::string> unlock_keys_; | 112 std::map<std::string, std::string> unlock_keys_; |
116 | 113 |
117 scoped_ptr<ConnectionFinder> connection_finder_; | 114 scoped_ptr<ConnectionFinder> connection_finder_; |
118 | 115 |
119 scoped_ptr<Connection> connection_; | 116 scoped_ptr<Connection> connection_; |
120 | 117 |
121 const base::TimeDelta polling_interval_; | 118 const base::TimeDelta polling_interval_; |
122 | 119 |
123 bool is_polling_screen_state_; | 120 bool is_polling_screen_state_; |
124 | 121 |
125 base::WeakPtrFactory<ProximityAuthBleSystem> weak_ptr_factory_; | 122 base::WeakPtrFactory<ProximityAuthBleSystem> weak_ptr_factory_; |
126 | 123 |
127 DISALLOW_COPY_AND_ASSIGN(ProximityAuthBleSystem); | 124 DISALLOW_COPY_AND_ASSIGN(ProximityAuthBleSystem); |
128 }; | 125 }; |
129 | 126 |
130 } // namespace proximity_auth | 127 } // namespace proximity_auth |
131 | 128 |
132 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_PROXIMITY_AUTH_BLE_SYSTEM_H_ | 129 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_PROXIMITY_AUTH_BLE_SYSTEM_H_ |
OLD | NEW |