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

Side by Side Diff: chromeos/components/tether/ble_connection_manager.h

Issue 2800883003: [CrOS Tether] Update SecureChannel and BleConnectionManager to use CryptAuthService instead of a Del (Closed)
Patch Set: Added BleConnectionManager refactor as well. Created 3 years, 8 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
« no previous file with comments | « no previous file | chromeos/components/tether/ble_connection_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 CHROMEOS_COMPONENTS_TETHER_BLE_CONNECTION_MANAGER_H_ 5 #ifndef CHROMEOS_COMPONENTS_TETHER_BLE_CONNECTION_MANAGER_H_
6 #define CHROMEOS_COMPONENTS_TETHER_BLE_CONNECTION_MANAGER_H_ 6 #define CHROMEOS_COMPONENTS_TETHER_BLE_CONNECTION_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/timer/timer.h" 15 #include "base/timer/timer.h"
16 #include "chromeos/components/tether/ble_advertisement_device_queue.h" 16 #include "chromeos/components/tether/ble_advertisement_device_queue.h"
17 #include "chromeos/components/tether/ble_advertiser.h" 17 #include "chromeos/components/tether/ble_advertiser.h"
18 #include "chromeos/components/tether/ble_scanner.h" 18 #include "chromeos/components/tether/ble_scanner.h"
19 #include "chromeos/components/tether/proto/tether.pb.h" 19 #include "chromeos/components/tether/proto/tether.pb.h"
20 #include "components/cryptauth/remote_device.h" 20 #include "components/cryptauth/remote_device.h"
21 #include "components/cryptauth/secure_channel.h" 21 #include "components/cryptauth/secure_channel.h"
22 22
23 namespace cryptauth { 23 namespace cryptauth {
24 class BluetoothThrottler; 24 class BluetoothThrottler;
25 class CryptAuthService;
25 } // namespace cryptauth 26 } // namespace cryptauth
26 27
27 namespace chromeos { 28 namespace chromeos {
28 29
29 namespace tether { 30 namespace tether {
30 31
31 // Manages connections to remote devices. When a device is registered, 32 // Manages connections to remote devices. When a device is registered,
32 // BleConnectionManager intiates a connection to that device. If the connection 33 // BleConnectionManager intiates a connection to that device. If the connection
33 // succeeds and authenticates successfully, messages can be sent/received 34 // succeeds and authenticates successfully, messages can be sent/received
34 // to/from the device. If the connection does not succeed, BleConnectionManager 35 // to/from the device. If the connection does not succeed, BleConnectionManager
(...skipping 23 matching lines...) Expand all
58 public: 59 public:
59 virtual void OnSecureChannelStatusChanged( 60 virtual void OnSecureChannelStatusChanged(
60 const cryptauth::RemoteDevice& remote_device, 61 const cryptauth::RemoteDevice& remote_device,
61 const cryptauth::SecureChannel::Status& old_status, 62 const cryptauth::SecureChannel::Status& old_status,
62 const cryptauth::SecureChannel::Status& new_status) = 0; 63 const cryptauth::SecureChannel::Status& new_status) = 0;
63 64
64 virtual void OnMessageReceived(const cryptauth::RemoteDevice& remote_device, 65 virtual void OnMessageReceived(const cryptauth::RemoteDevice& remote_device,
65 const std::string& payload) = 0; 66 const std::string& payload) = 0;
66 }; 67 };
67 68
68 class Delegate {
69 public:
70 virtual std::unique_ptr<cryptauth::SecureChannel::Delegate>
71 CreateSecureChannelDelegate() = 0;
72 };
73
74 BleConnectionManager( 69 BleConnectionManager(
75 std::unique_ptr<Delegate> delegate, 70 cryptauth::CryptAuthService* cryptauth_service,
76 scoped_refptr<device::BluetoothAdapter> adapter, 71 scoped_refptr<device::BluetoothAdapter> adapter,
77 const LocalDeviceDataProvider* local_device_data_provider, 72 const LocalDeviceDataProvider* local_device_data_provider,
78 const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher, 73 const cryptauth::RemoteBeaconSeedFetcher* remote_beacon_seed_fetcher,
79 cryptauth::BluetoothThrottler* bluetooth_throttler); 74 cryptauth::BluetoothThrottler* bluetooth_throttler);
80 virtual ~BleConnectionManager(); 75 virtual ~BleConnectionManager();
81 76
82 // Registers |remote_device| for |connection_reason|. Once registered, this 77 // Registers |remote_device| for |connection_reason|. Once registered, this
83 // instance will continue to attempt to connect and authenticate to that 78 // instance will continue to attempt to connect and authenticate to that
84 // device until the device is unregistered. 79 // device until the device is unregistered.
85 virtual void RegisterRemoteDevice( 80 virtual void RegisterRemoteDevice(
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 168
174 base::WeakPtrFactory<ConnectionMetadata> weak_ptr_factory_; 169 base::WeakPtrFactory<ConnectionMetadata> weak_ptr_factory_;
175 }; 170 };
176 171
177 class TimerFactory { 172 class TimerFactory {
178 public: 173 public:
179 virtual std::unique_ptr<base::Timer> CreateTimer(); 174 virtual std::unique_ptr<base::Timer> CreateTimer();
180 }; 175 };
181 176
182 BleConnectionManager( 177 BleConnectionManager(
183 std::unique_ptr<Delegate> delegate, 178 cryptauth::CryptAuthService* cryptauth_service,
184 scoped_refptr<device::BluetoothAdapter> adapter, 179 scoped_refptr<device::BluetoothAdapter> adapter,
185 std::unique_ptr<BleScanner> ble_scanner, 180 std::unique_ptr<BleScanner> ble_scanner,
186 std::unique_ptr<BleAdvertiser> ble_advertiser, 181 std::unique_ptr<BleAdvertiser> ble_advertiser,
187 std::unique_ptr<BleAdvertisementDeviceQueue> device_queue, 182 std::unique_ptr<BleAdvertisementDeviceQueue> device_queue,
188 std::unique_ptr<TimerFactory> timer_factory, 183 std::unique_ptr<TimerFactory> timer_factory,
189 cryptauth::BluetoothThrottler* bluetooth_throttler); 184 cryptauth::BluetoothThrottler* bluetooth_throttler);
190 185
191 std::shared_ptr<ConnectionMetadata> GetConnectionMetadata( 186 std::shared_ptr<ConnectionMetadata> GetConnectionMetadata(
192 const cryptauth::RemoteDevice& remote_device) const; 187 const cryptauth::RemoteDevice& remote_device) const;
193 std::shared_ptr<ConnectionMetadata> AddMetadataForDevice( 188 std::shared_ptr<ConnectionMetadata> AddMetadataForDevice(
194 const cryptauth::RemoteDevice& remote_device); 189 const cryptauth::RemoteDevice& remote_device);
195 190
196 void UpdateConnectionAttempts(); 191 void UpdateConnectionAttempts();
197 void UpdateAdvertisementQueue(); 192 void UpdateAdvertisementQueue();
198 193
199 void StartConnectionAttempt(const cryptauth::RemoteDevice& remote_device); 194 void StartConnectionAttempt(const cryptauth::RemoteDevice& remote_device);
200 void StopConnectionAttemptAndMoveToEndOfQueue( 195 void StopConnectionAttemptAndMoveToEndOfQueue(
201 const cryptauth::RemoteDevice& remote_device); 196 const cryptauth::RemoteDevice& remote_device);
202 197
203 void OnConnectionAttemptTimeout(const cryptauth::RemoteDevice& remote_device); 198 void OnConnectionAttemptTimeout(const cryptauth::RemoteDevice& remote_device);
204 void OnSecureChannelStatusChanged( 199 void OnSecureChannelStatusChanged(
205 const cryptauth::RemoteDevice& remote_device, 200 const cryptauth::RemoteDevice& remote_device,
206 const cryptauth::SecureChannel::Status& old_status, 201 const cryptauth::SecureChannel::Status& old_status,
207 const cryptauth::SecureChannel::Status& new_status); 202 const cryptauth::SecureChannel::Status& new_status);
208 203
209 std::unique_ptr<Delegate> delegate_; 204 cryptauth::CryptAuthService* cryptauth_service_;
210 scoped_refptr<device::BluetoothAdapter> adapter_; 205 scoped_refptr<device::BluetoothAdapter> adapter_;
211 std::unique_ptr<BleScanner> ble_scanner_; 206 std::unique_ptr<BleScanner> ble_scanner_;
212 std::unique_ptr<BleAdvertiser> ble_advertiser_; 207 std::unique_ptr<BleAdvertiser> ble_advertiser_;
213 std::unique_ptr<BleAdvertisementDeviceQueue> device_queue_; 208 std::unique_ptr<BleAdvertisementDeviceQueue> device_queue_;
214 std::unique_ptr<TimerFactory> timer_factory_; 209 std::unique_ptr<TimerFactory> timer_factory_;
215 cryptauth::BluetoothThrottler* bluetooth_throttler_; 210 cryptauth::BluetoothThrottler* bluetooth_throttler_;
216 211
217 bool has_registered_observer_; 212 bool has_registered_observer_;
218 std::map<cryptauth::RemoteDevice, std::shared_ptr<ConnectionMetadata>> 213 std::map<cryptauth::RemoteDevice, std::shared_ptr<ConnectionMetadata>>
219 device_to_metadata_map_; 214 device_to_metadata_map_;
220 215
221 base::ObserverList<Observer> observer_list_; 216 base::ObserverList<Observer> observer_list_;
222 base::WeakPtrFactory<BleConnectionManager> weak_ptr_factory_; 217 base::WeakPtrFactory<BleConnectionManager> weak_ptr_factory_;
223 218
224 DISALLOW_COPY_AND_ASSIGN(BleConnectionManager); 219 DISALLOW_COPY_AND_ASSIGN(BleConnectionManager);
225 }; 220 };
226 221
227 } // namespace tether 222 } // namespace tether
228 223
229 } // namespace chromeos 224 } // namespace chromeos
230 225
231 #endif // CHROMEOS_COMPONENTS_TETHER_BLE_CONNECTION_MANAGER_H_ 226 #endif // CHROMEOS_COMPONENTS_TETHER_BLE_CONNECTION_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | chromeos/components/tether/ble_connection_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698