| 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_BLUETOOTH_LOW_ENERGY_CONNECTION_H_ | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_H_ |
| 6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_H_ | 6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <memory> |
| 11 #include <queue> | 12 #include <queue> |
| 12 #include <string> | 13 #include <string> |
| 13 | 14 |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" | |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "components/proximity_auth/ble/bluetooth_low_energy_characteristics_fin
der.h" | 19 #include "components/proximity_auth/ble/bluetooth_low_energy_characteristics_fin
der.h" |
| 20 #include "components/proximity_auth/ble/fake_wire_message.h" | 20 #include "components/proximity_auth/ble/fake_wire_message.h" |
| 21 #include "components/proximity_auth/ble/remote_attribute.h" | 21 #include "components/proximity_auth/ble/remote_attribute.h" |
| 22 #include "components/proximity_auth/connection.h" | 22 #include "components/proximity_auth/connection.h" |
| 23 #include "device/bluetooth/bluetooth_adapter.h" | 23 #include "device/bluetooth/bluetooth_adapter.h" |
| 24 #include "device/bluetooth/bluetooth_device.h" | 24 #include "device/bluetooth/bluetooth_device.h" |
| 25 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | 25 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
| 26 #include "device/bluetooth/bluetooth_gatt_notify_session.h" | 26 #include "device/bluetooth/bluetooth_gatt_notify_session.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 void SetTaskRunnerForTesting(scoped_refptr<base::TaskRunner> task_runner); | 110 void SetTaskRunnerForTesting(scoped_refptr<base::TaskRunner> task_runner); |
| 111 | 111 |
| 112 // Virtual for testing. | 112 // Virtual for testing. |
| 113 virtual BluetoothLowEnergyCharacteristicsFinder* CreateCharacteristicsFinder( | 113 virtual BluetoothLowEnergyCharacteristicsFinder* CreateCharacteristicsFinder( |
| 114 const BluetoothLowEnergyCharacteristicsFinder::SuccessCallback& | 114 const BluetoothLowEnergyCharacteristicsFinder::SuccessCallback& |
| 115 success_callback, | 115 success_callback, |
| 116 const BluetoothLowEnergyCharacteristicsFinder::ErrorCallback& | 116 const BluetoothLowEnergyCharacteristicsFinder::ErrorCallback& |
| 117 error_callback); | 117 error_callback); |
| 118 | 118 |
| 119 // proximity_auth::Connection: | 119 // proximity_auth::Connection: |
| 120 void SendMessageImpl(scoped_ptr<WireMessage> message) override; | 120 void SendMessageImpl(std::unique_ptr<WireMessage> message) override; |
| 121 | 121 |
| 122 // device::BluetoothAdapter::Observer: | 122 // device::BluetoothAdapter::Observer: |
| 123 void DeviceChanged(device::BluetoothAdapter* adapter, | 123 void DeviceChanged(device::BluetoothAdapter* adapter, |
| 124 device::BluetoothDevice* device) override; | 124 device::BluetoothDevice* device) override; |
| 125 void DeviceRemoved(device::BluetoothAdapter* adapter, | 125 void DeviceRemoved(device::BluetoothAdapter* adapter, |
| 126 device::BluetoothDevice* device) override; | 126 device::BluetoothDevice* device) override; |
| 127 void GattCharacteristicValueChanged( | 127 void GattCharacteristicValueChanged( |
| 128 device::BluetoothAdapter* adapter, | 128 device::BluetoothAdapter* adapter, |
| 129 device::BluetoothGattCharacteristic* characteristic, | 129 device::BluetoothGattCharacteristic* characteristic, |
| 130 const std::vector<uint8_t>& value) override; | 130 const std::vector<uint8_t>& value) override; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 144 std::vector<uint8_t> value; | 144 std::vector<uint8_t> value; |
| 145 bool is_last_write_for_wire_message; | 145 bool is_last_write_for_wire_message; |
| 146 int number_of_failed_attempts; | 146 int number_of_failed_attempts; |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 // Creates the GATT connection with |remote_device|. | 149 // Creates the GATT connection with |remote_device|. |
| 150 void CreateGattConnection(); | 150 void CreateGattConnection(); |
| 151 | 151 |
| 152 // Called when a GATT connection is created. | 152 // Called when a GATT connection is created. |
| 153 void OnGattConnectionCreated( | 153 void OnGattConnectionCreated( |
| 154 scoped_ptr<device::BluetoothGattConnection> gatt_connection); | 154 std::unique_ptr<device::BluetoothGattConnection> gatt_connection); |
| 155 | 155 |
| 156 // Callback called when there is an error creating the GATT connection. | 156 // Callback called when there is an error creating the GATT connection. |
| 157 void OnCreateGattConnectionError( | 157 void OnCreateGattConnectionError( |
| 158 device::BluetoothDevice::ConnectErrorCode error_code); | 158 device::BluetoothDevice::ConnectErrorCode error_code); |
| 159 | 159 |
| 160 // Callback called when |to_peripheral_char_| and |from_peripheral_char_| were | 160 // Callback called when |to_peripheral_char_| and |from_peripheral_char_| were |
| 161 // found. | 161 // found. |
| 162 void OnCharacteristicsFound(const RemoteAttribute& service, | 162 void OnCharacteristicsFound(const RemoteAttribute& service, |
| 163 const RemoteAttribute& to_peripheral_char, | 163 const RemoteAttribute& to_peripheral_char, |
| 164 const RemoteAttribute& from_peripheral_char); | 164 const RemoteAttribute& from_peripheral_char); |
| 165 | 165 |
| 166 // Callback called there was an error finding the characteristics. | 166 // Callback called there was an error finding the characteristics. |
| 167 void OnCharacteristicsFinderError( | 167 void OnCharacteristicsFinderError( |
| 168 const RemoteAttribute& to_peripheral_char, | 168 const RemoteAttribute& to_peripheral_char, |
| 169 const RemoteAttribute& from_peripheral_char); | 169 const RemoteAttribute& from_peripheral_char); |
| 170 | 170 |
| 171 // Starts a notify session for |from_peripheral_char_| when ready | 171 // Starts a notify session for |from_peripheral_char_| when ready |
| 172 // (SubStatus::CHARACTERISTICS_FOUND). | 172 // (SubStatus::CHARACTERISTICS_FOUND). |
| 173 void StartNotifySession(); | 173 void StartNotifySession(); |
| 174 | 174 |
| 175 // Called when a notification session is successfully started for | 175 // Called when a notification session is successfully started for |
| 176 // |from_peripheral_char_| characteristic. | 176 // |from_peripheral_char_| characteristic. |
| 177 void OnNotifySessionStarted( | 177 void OnNotifySessionStarted( |
| 178 scoped_ptr<device::BluetoothGattNotifySession> notify_session); | 178 std::unique_ptr<device::BluetoothGattNotifySession> notify_session); |
| 179 | 179 |
| 180 // Called when there is an error starting a notification session for | 180 // Called when there is an error starting a notification session for |
| 181 // |from_peripheral_char_| characteristic. | 181 // |from_peripheral_char_| characteristic. |
| 182 void OnNotifySessionError(device::BluetoothGattService::GattErrorCode); | 182 void OnNotifySessionError(device::BluetoothGattService::GattErrorCode); |
| 183 | 183 |
| 184 // Stops |notify_session_|. | 184 // Stops |notify_session_|. |
| 185 void StopNotifySession(); | 185 void StopNotifySession(); |
| 186 | 186 |
| 187 // Sends an invite to connect signal to the peripheral if when ready | 187 // Sends an invite to connect signal to the peripheral if when ready |
| 188 // (SubStatus::NOTIFY_SESSION_READY). | 188 // (SubStatus::NOTIFY_SESSION_READY). |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 // Characteristic used to receive data from the remote device. | 256 // Characteristic used to receive data from the remote device. |
| 257 RemoteAttribute from_peripheral_char_; | 257 RemoteAttribute from_peripheral_char_; |
| 258 | 258 |
| 259 // Throttles repeated connection attempts to the same device. This is a | 259 // Throttles repeated connection attempts to the same device. This is a |
| 260 // workaround for crbug.com/508919. Not owned, must outlive this instance. | 260 // workaround for crbug.com/508919. Not owned, must outlive this instance. |
| 261 BluetoothThrottler* bluetooth_throttler_; | 261 BluetoothThrottler* bluetooth_throttler_; |
| 262 | 262 |
| 263 scoped_refptr<base::TaskRunner> task_runner_; | 263 scoped_refptr<base::TaskRunner> task_runner_; |
| 264 | 264 |
| 265 // The GATT connection with the remote device. | 265 // The GATT connection with the remote device. |
| 266 scoped_ptr<device::BluetoothGattConnection> gatt_connection_; | 266 std::unique_ptr<device::BluetoothGattConnection> gatt_connection_; |
| 267 | 267 |
| 268 // The characteristics finder for remote device. | 268 // The characteristics finder for remote device. |
| 269 scoped_ptr<BluetoothLowEnergyCharacteristicsFinder> characteristic_finder_; | 269 std::unique_ptr<BluetoothLowEnergyCharacteristicsFinder> |
| 270 characteristic_finder_; |
| 270 | 271 |
| 271 // The notify session for |from_peripheral_char|. | 272 // The notify session for |from_peripheral_char|. |
| 272 scoped_ptr<device::BluetoothGattNotifySession> notify_session_; | 273 std::unique_ptr<device::BluetoothGattNotifySession> notify_session_; |
| 273 | 274 |
| 274 // Internal connection status | 275 // Internal connection status |
| 275 SubStatus sub_status_; | 276 SubStatus sub_status_; |
| 276 | 277 |
| 277 // Indicates a receiving operation is in progress. This is set after a | 278 // Indicates a receiving operation is in progress. This is set after a |
| 278 // ControlSignal::kSendSignal was received from the remote device. | 279 // ControlSignal::kSendSignal was received from the remote device. |
| 279 bool receiving_bytes_; | 280 bool receiving_bytes_; |
| 280 | 281 |
| 281 // Total number of bytes expected for the current receive operation. | 282 // Total number of bytes expected for the current receive operation. |
| 282 std::size_t expected_number_of_incoming_bytes_; | 283 std::size_t expected_number_of_incoming_bytes_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 304 base::TimeTicks start_time_; | 305 base::TimeTicks start_time_; |
| 305 | 306 |
| 306 base::WeakPtrFactory<BluetoothLowEnergyConnection> weak_ptr_factory_; | 307 base::WeakPtrFactory<BluetoothLowEnergyConnection> weak_ptr_factory_; |
| 307 | 308 |
| 308 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnection); | 309 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnection); |
| 309 }; | 310 }; |
| 310 | 311 |
| 311 } // namespace proximity_auth | 312 } // namespace proximity_auth |
| 312 | 313 |
| 313 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_H_ | 314 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_H_ |
| OLD | NEW |