| 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_WEAVE_CLIENT_CONNECTI
ON_H_ | 5 #ifndef COMPONENTS_CRYPTAUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_CLIENT_CONNECTION_H_ |
| 6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_CLIENT_CONNECTI
ON_H_ | 6 #define COMPONENTS_CRYPTAUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_CLIENT_CONNECTION_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <queue> | 13 #include <queue> |
| 14 #include <string> | 14 #include <string> |
| 15 | 15 |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "components/proximity_auth/ble/bluetooth_low_energy_characteristics_fin
der.h" | 20 #include "components/cryptauth/ble/bluetooth_low_energy_characteristics_finder.h
" |
| 21 #include "components/proximity_auth/ble/bluetooth_low_energy_weave_packet_genera
tor.h" | 21 #include "components/cryptauth/ble/bluetooth_low_energy_weave_packet_generator.h
" |
| 22 #include "components/proximity_auth/ble/bluetooth_low_energy_weave_packet_receiv
er.h" | 22 #include "components/cryptauth/ble/bluetooth_low_energy_weave_packet_receiver.h" |
| 23 #include "components/proximity_auth/ble/fake_wire_message.h" | 23 #include "components/cryptauth/ble/fake_wire_message.h" |
| 24 #include "components/proximity_auth/ble/remote_attribute.h" | 24 #include "components/cryptauth/ble/remote_attribute.h" |
| 25 #include "components/proximity_auth/connection.h" | 25 #include "components/cryptauth/bluetooth_throttler.h" |
| 26 #include "components/cryptauth/connection.h" |
| 26 #include "device/bluetooth/bluetooth_adapter.h" | 27 #include "device/bluetooth/bluetooth_adapter.h" |
| 27 #include "device/bluetooth/bluetooth_device.h" | 28 #include "device/bluetooth/bluetooth_device.h" |
| 28 #include "device/bluetooth/bluetooth_gatt_notify_session.h" | 29 #include "device/bluetooth/bluetooth_gatt_notify_session.h" |
| 29 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" | 30 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
| 30 #include "device/bluetooth/bluetooth_uuid.h" | 31 #include "device/bluetooth/bluetooth_uuid.h" |
| 31 | 32 |
| 32 namespace base { | 33 namespace base { |
| 33 class TaskRunner; | 34 class TaskRunner; |
| 34 } | 35 } |
| 35 | 36 |
| 36 namespace proximity_auth { | 37 namespace cryptauth { |
| 37 class BluetoothThrottler; | |
| 38 | 38 |
| 39 namespace weave { | 39 namespace weave { |
| 40 // Creates GATT connection on top of the BLE connection and act as a Client. | 40 // Creates GATT connection on top of the BLE connection and act as a Client. |
| 41 // uWeave communication follows the flow: | 41 // uWeave communication follows the flow: |
| 42 // Client | Server | 42 // Client | Server |
| 43 // ---------------------------------|-------------------------------- | 43 // ---------------------------------|-------------------------------- |
| 44 // send connection request | | 44 // send connection request | |
| 45 // | receive connection request | 45 // | receive connection request |
| 46 // | send connection response | 46 // | send connection response |
| 47 // receive connection response | | 47 // receive connection response | |
| (...skipping 14 matching lines...) Expand all Loading... |
| 62 | 62 |
| 63 protected: | 63 protected: |
| 64 // Exposed for testing. | 64 // Exposed for testing. |
| 65 virtual std::unique_ptr<BluetoothLowEnergyWeaveClientConnection> | 65 virtual std::unique_ptr<BluetoothLowEnergyWeaveClientConnection> |
| 66 BuildInstance(); | 66 BuildInstance(); |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 static Factory* factory_instance_; | 69 static Factory* factory_instance_; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 // The sub-state of a proximity_auth::BluetoothLowEnergyWeaveClientConnection | 72 // The sub-state of a cryptauth::BluetoothLowEnergyWeaveClientConnection |
| 73 // extends the IN_PROGRESS state of proximity_auth::Connection::Status. | 73 // extends the IN_PROGRESS state of cryptauth::Connection::Status. |
| 74 enum SubStatus { | 74 enum SubStatus { |
| 75 DISCONNECTED, | 75 DISCONNECTED, |
| 76 WAITING_GATT_CONNECTION, | 76 WAITING_GATT_CONNECTION, |
| 77 WAITING_CHARACTERISTICS, | 77 WAITING_CHARACTERISTICS, |
| 78 CHARACTERISTICS_FOUND, | 78 CHARACTERISTICS_FOUND, |
| 79 WAITING_NOTIFY_SESSION, | 79 WAITING_NOTIFY_SESSION, |
| 80 NOTIFY_SESSION_READY, | 80 NOTIFY_SESSION_READY, |
| 81 WAITING_CONNECTION_RESPONSE, | 81 WAITING_CONNECTION_RESPONSE, |
| 82 CONNECTED, | 82 CONNECTED, |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 // Constructs a Bluetooth low energy connection to the service with | 85 // Constructs a Bluetooth low energy connection to the service with |
| 86 // |remote_service_| on the |remote_device|. The |adapter| must be already | 86 // |remote_service_| on the |remote_device|. The |adapter| must be already |
| 87 // initialized and ready. The GATT connection may alreaady be established and | 87 // initialized and ready. The GATT connection may alreaady be established and |
| 88 // pass through |gatt_connection|. A subsequent call to Connect() must be | 88 // pass through |gatt_connection|. A subsequent call to Connect() must be |
| 89 // made. | 89 // made. |
| 90 BluetoothLowEnergyWeaveClientConnection( | 90 BluetoothLowEnergyWeaveClientConnection( |
| 91 const cryptauth::RemoteDevice& remote_device, | 91 const cryptauth::RemoteDevice& remote_device, |
| 92 scoped_refptr<device::BluetoothAdapter> adapter, | 92 scoped_refptr<device::BluetoothAdapter> adapter, |
| 93 const device::BluetoothUUID remote_service_uuid, | 93 const device::BluetoothUUID remote_service_uuid, |
| 94 BluetoothThrottler* bluetooth_throttler, | 94 BluetoothThrottler* bluetooth_throttler, |
| 95 int max_number_of_write_attempts); | 95 int max_number_of_write_attempts); |
| 96 | 96 |
| 97 ~BluetoothLowEnergyWeaveClientConnection() override; | 97 ~BluetoothLowEnergyWeaveClientConnection() override; |
| 98 | 98 |
| 99 // proximity_auth::Connection: | 99 // namespace cryptauth::Connection: |
| 100 void Connect() override; | 100 void Connect() override; |
| 101 void Disconnect() override; | 101 void Disconnect() override; |
| 102 std::string GetDeviceAddress() override; | 102 std::string GetDeviceAddress() override; |
| 103 | 103 |
| 104 protected: | 104 protected: |
| 105 // Exposed for testing. | 105 // Exposed for testing. |
| 106 void DestroyConnection(); | 106 void DestroyConnection(); |
| 107 | 107 |
| 108 // Exposed for testing. | 108 // Exposed for testing. |
| 109 SubStatus sub_status() { return sub_status_; } | 109 SubStatus sub_status() { return sub_status_; } |
| 110 | 110 |
| 111 // Sets |task_runner_| for testing. | 111 // Sets |task_runner_| for testing. |
| 112 void SetTaskRunnerForTesting(scoped_refptr<base::TaskRunner> task_runner); | 112 void SetTaskRunnerForTesting(scoped_refptr<base::TaskRunner> task_runner); |
| 113 | 113 |
| 114 // Virtual for testing. | 114 // Virtual for testing. |
| 115 virtual BluetoothLowEnergyCharacteristicsFinder* CreateCharacteristicsFinder( | 115 virtual BluetoothLowEnergyCharacteristicsFinder* CreateCharacteristicsFinder( |
| 116 const BluetoothLowEnergyCharacteristicsFinder::SuccessCallback& | 116 const BluetoothLowEnergyCharacteristicsFinder::SuccessCallback& |
| 117 success_callback, | 117 success_callback, |
| 118 const BluetoothLowEnergyCharacteristicsFinder::ErrorCallback& | 118 const BluetoothLowEnergyCharacteristicsFinder::ErrorCallback& |
| 119 error_callback); | 119 error_callback); |
| 120 | 120 |
| 121 // proximity_auth::Connection: | 121 // namespace cryptauth::Connection: |
| 122 void SendMessageImpl(std::unique_ptr<WireMessage> message) override; | 122 void SendMessageImpl(std::unique_ptr<WireMessage> message) override; |
| 123 | 123 |
| 124 // device::BluetoothAdapter::Observer: | 124 // device::BluetoothAdapter::Observer: |
| 125 void DeviceChanged(device::BluetoothAdapter* adapter, | 125 void DeviceChanged(device::BluetoothAdapter* adapter, |
| 126 device::BluetoothDevice* device) override; | 126 device::BluetoothDevice* device) override; |
| 127 void DeviceRemoved(device::BluetoothAdapter* adapter, | 127 void DeviceRemoved(device::BluetoothAdapter* adapter, |
| 128 device::BluetoothDevice* device) override; | 128 device::BluetoothDevice* device) override; |
| 129 void GattCharacteristicValueChanged( | 129 void GattCharacteristicValueChanged( |
| 130 device::BluetoothAdapter* adapter, | 130 device::BluetoothAdapter* adapter, |
| 131 device::BluetoothRemoteGattCharacteristic* characteristic, | 131 device::BluetoothRemoteGattCharacteristic* characteristic, |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 base::TimeTicks start_time_; | 304 base::TimeTicks start_time_; |
| 305 | 305 |
| 306 base::WeakPtrFactory<BluetoothLowEnergyWeaveClientConnection> | 306 base::WeakPtrFactory<BluetoothLowEnergyWeaveClientConnection> |
| 307 weak_ptr_factory_; | 307 weak_ptr_factory_; |
| 308 | 308 |
| 309 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyWeaveClientConnection); | 309 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyWeaveClientConnection); |
| 310 }; | 310 }; |
| 311 | 311 |
| 312 } // namespace weave | 312 } // namespace weave |
| 313 | 313 |
| 314 } // namespace proximity_auth | 314 } // namespace cryptauth |
| 315 | 315 |
| 316 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_CLIENT_CONNE
CTION_H_ | 316 #endif // COMPONENTS_CRYPTAUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_CLIENT_CONNECTION
_H_ |
| OLD | NEW |