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_BLUETOOTH_LOW_ENERGY_CONNECTION_FINDER_H | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_FINDER_H |
6 #define COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_FINDER_H | 6 #define COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_FINDER_H |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 21 matching lines...) Expand all Loading... |
32 // the expected EID for the current or nearby time intervals. | 32 // the expected EID for the current or nearby time intervals. |
33 class BluetoothLowEnergyConnectionFinder | 33 class BluetoothLowEnergyConnectionFinder |
34 : public cryptauth::ConnectionFinder, | 34 : public cryptauth::ConnectionFinder, |
35 public cryptauth::ConnectionObserver, | 35 public cryptauth::ConnectionObserver, |
36 public device::BluetoothAdapter::Observer { | 36 public device::BluetoothAdapter::Observer { |
37 public: | 37 public: |
38 // Finds (and connects) to a Bluetooth low energy device, based on the EID | 38 // Finds (and connects) to a Bluetooth low energy device, based on the EID |
39 // advertised by the remote device. | 39 // advertised by the remote device. |
40 // | 40 // |
41 // |remote_device|: The BLE remote device. | 41 // |remote_device|: The BLE remote device. |
| 42 // |beacon_seeds|: The BeaconSeeds for the |remote_device. |
42 // |bluetooth_throttler|: The reconnection throttler. | 43 // |bluetooth_throttler|: The reconnection throttler. |
43 BluetoothLowEnergyConnectionFinder( | 44 BluetoothLowEnergyConnectionFinder( |
44 const cryptauth::RemoteDevice remote_device, | 45 const cryptauth::RemoteDevice remote_device, |
| 46 const std::vector<cryptauth::BeaconSeed>& beacon_seeds, |
45 cryptauth::BluetoothThrottler* bluetooth_throttler); | 47 cryptauth::BluetoothThrottler* bluetooth_throttler); |
46 | 48 |
47 ~BluetoothLowEnergyConnectionFinder() override; | 49 ~BluetoothLowEnergyConnectionFinder() override; |
48 | 50 |
49 // Finds a connection to the remote device. | 51 // Finds a connection to the remote device. |
50 void Find(const cryptauth::ConnectionFinder::ConnectionCallback& | 52 void Find(const cryptauth::ConnectionFinder::ConnectionCallback& |
51 connection_callback) override; | 53 connection_callback) override; |
52 | 54 |
53 // cryptauth::ConnectionObserver: | 55 // cryptauth::ConnectionObserver: |
54 void OnConnectionStatusChanged( | 56 void OnConnectionStatusChanged( |
55 cryptauth::Connection* connection, | 57 cryptauth::Connection* connection, |
56 cryptauth::Connection::Status old_status, | 58 cryptauth::Connection::Status old_status, |
57 cryptauth::Connection::Status new_status) override; | 59 cryptauth::Connection::Status new_status) override; |
58 | 60 |
59 // device::BluetoothAdapter::Observer: | 61 // device::BluetoothAdapter::Observer: |
60 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, | 62 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, |
61 bool powered) override; | 63 bool powered) override; |
62 void DeviceAdded(device::BluetoothAdapter* adapter, | 64 void DeviceAdded(device::BluetoothAdapter* adapter, |
63 device::BluetoothDevice* device) override; | 65 device::BluetoothDevice* device) override; |
64 void DeviceChanged(device::BluetoothAdapter* adapter, | 66 void DeviceChanged(device::BluetoothAdapter* adapter, |
65 device::BluetoothDevice* device) override; | 67 device::BluetoothDevice* device) override; |
66 | 68 |
67 protected: | 69 protected: |
68 BluetoothLowEnergyConnectionFinder( | 70 BluetoothLowEnergyConnectionFinder( |
69 const cryptauth::RemoteDevice remote_device, | 71 const cryptauth::RemoteDevice remote_device, |
70 const std::string& service_uuid, | 72 const std::string& service_uuid, |
| 73 const std::vector<cryptauth::BeaconSeed>& beacon_seeds, |
71 std::unique_ptr<cryptauth::BackgroundEidGenerator> eid_generator, | 74 std::unique_ptr<cryptauth::BackgroundEidGenerator> eid_generator, |
72 cryptauth::BluetoothThrottler* bluetooth_throttler); | 75 cryptauth::BluetoothThrottler* bluetooth_throttler); |
73 | 76 |
74 // Creates a proximity_auth::Connection with the device given by | 77 // Creates a proximity_auth::Connection with the device given by |
75 // |device_address|. Exposed for testing. | 78 // |device_address|. Exposed for testing. |
76 virtual std::unique_ptr<cryptauth::Connection> CreateConnection( | 79 virtual std::unique_ptr<cryptauth::Connection> CreateConnection( |
77 const std::string& device_address); | 80 const std::string& device_address); |
78 | 81 |
79 // Checks if |device| is advertising the right EID. | 82 // Checks if |device| is advertising the right EID. |
80 virtual bool IsRightDevice(device::BluetoothDevice* device); | 83 virtual bool IsRightDevice(device::BluetoothDevice* device); |
(...skipping 27 matching lines...) Expand all Loading... |
108 void InvokeCallbackAsync(); | 111 void InvokeCallbackAsync(); |
109 | 112 |
110 // The remote BLE device being searched. It maybe empty, in this case the | 113 // The remote BLE device being searched. It maybe empty, in this case the |
111 // remote device should advertise |remote_service_uuid_| and | 114 // remote device should advertise |remote_service_uuid_| and |
112 // |advertised_name_|. | 115 // |advertised_name_|. |
113 cryptauth::RemoteDevice remote_device_; | 116 cryptauth::RemoteDevice remote_device_; |
114 | 117 |
115 // The UUID of the service used by the Weave socket. | 118 // The UUID of the service used by the Weave socket. |
116 std::string service_uuid_; | 119 std::string service_uuid_; |
117 | 120 |
| 121 // The BeaconSeeds of the |remote_device|. |
| 122 std::vector<cryptauth::BeaconSeed> beacon_seeds_; |
| 123 |
118 // Generates the expected EIDs that may be advertised by |remote_device_|. If | 124 // Generates the expected EIDs that may be advertised by |remote_device_|. If |
119 // an EID matches, we know its a device we should connect to. | 125 // an EID matches, we know its a device we should connect to. |
120 std::unique_ptr<cryptauth::BackgroundEidGenerator> eid_generator_; | 126 std::unique_ptr<cryptauth::BackgroundEidGenerator> eid_generator_; |
121 | 127 |
122 // Throttles repeated connection attempts to the same device. This is a | 128 // Throttles repeated connection attempts to the same device. This is a |
123 // workaround for crbug.com/508919. Not owned, must outlive this instance. | 129 // workaround for crbug.com/508919. Not owned, must outlive this instance. |
124 cryptauth::BluetoothThrottler* bluetooth_throttler_; | 130 cryptauth::BluetoothThrottler* bluetooth_throttler_; |
125 | 131 |
126 // The Bluetooth adapter over which the Bluetooth connection will be made. | 132 // The Bluetooth adapter over which the Bluetooth connection will be made. |
127 scoped_refptr<device::BluetoothAdapter> adapter_; | 133 scoped_refptr<device::BluetoothAdapter> adapter_; |
128 | 134 |
129 // The discovery session associated to this object. | 135 // The discovery session associated to this object. |
130 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; | 136 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session_; |
131 | 137 |
132 // The connection with |remote_device|. | 138 // The connection with |remote_device|. |
133 std::unique_ptr<cryptauth::Connection> connection_; | 139 std::unique_ptr<cryptauth::Connection> connection_; |
134 | 140 |
135 // Callback called when the connection is established. | 141 // Callback called when the connection is established. |
136 cryptauth::ConnectionFinder::ConnectionCallback connection_callback_; | 142 cryptauth::ConnectionFinder::ConnectionCallback connection_callback_; |
137 | 143 |
138 base::WeakPtrFactory<BluetoothLowEnergyConnectionFinder> weak_ptr_factory_; | 144 base::WeakPtrFactory<BluetoothLowEnergyConnectionFinder> weak_ptr_factory_; |
139 | 145 |
140 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnectionFinder); | 146 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnectionFinder); |
141 }; | 147 }; |
142 | 148 |
143 } // namespace proximity_auth | 149 } // namespace proximity_auth |
144 | 150 |
145 #endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_FINDER_H | 151 #endif // COMPONENTS_PROXIMITY_AUTH_BLUETOOTH_LOW_ENERGY_CONNECTION_FINDER_H |
OLD | NEW |