Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | |
|
Tim Song
2016/07/22 23:21:40
no new line.
jingxuy
2016/07/22 23:25:59
Done.
| |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 2 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 4 // found in the LICENSE file. |
| 4 | 5 |
| 5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_H_ | 6 #ifndef COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_CLIENT_CONNECTI ON_H_ |
| 6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_H_ | 7 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_CLIENT_CONNECTI ON_H_ |
| 7 | 8 |
| 8 #include <stddef.h> | 9 #include <stddef.h> |
| 9 #include <stdint.h> | 10 #include <stdint.h> |
| 10 | 11 |
| 12 #include <map> | |
| 11 #include <memory> | 13 #include <memory> |
| 12 #include <queue> | 14 #include <queue> |
| 13 #include <string> | 15 #include <string> |
| 14 | 16 |
| 15 #include "base/macros.h" | 17 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 18 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 19 #include "components/proximity_auth/ble/bluetooth_low_energy_characteristics_fin der.h" | 21 #include "components/proximity_auth/ble/bluetooth_low_energy_characteristics_fin der.h" |
| 22 #include "components/proximity_auth/ble/bluetooth_low_energy_weave_packet_genera tor.h" | |
| 23 #include "components/proximity_auth/ble/bluetooth_low_energy_weave_packet_receiv er.h" | |
| 20 #include "components/proximity_auth/ble/fake_wire_message.h" | 24 #include "components/proximity_auth/ble/fake_wire_message.h" |
| 21 #include "components/proximity_auth/ble/remote_attribute.h" | 25 #include "components/proximity_auth/ble/remote_attribute.h" |
| 22 #include "components/proximity_auth/connection.h" | 26 #include "components/proximity_auth/connection.h" |
| 23 #include "device/bluetooth/bluetooth_adapter.h" | 27 #include "device/bluetooth/bluetooth_adapter.h" |
| 24 #include "device/bluetooth/bluetooth_device.h" | 28 #include "device/bluetooth/bluetooth_device.h" |
| 25 #include "device/bluetooth/bluetooth_gatt_notify_session.h" | 29 #include "device/bluetooth/bluetooth_gatt_notify_session.h" |
| 26 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" | 30 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
| 27 #include "device/bluetooth/bluetooth_uuid.h" | 31 #include "device/bluetooth/bluetooth_uuid.h" |
| 28 | 32 |
| 29 namespace base { | 33 namespace base { |
| 30 class TaskRunner; | 34 class TaskRunner; |
| 31 } | 35 } |
| 32 | 36 |
| 33 namespace proximity_auth { | 37 namespace proximity_auth { |
| 34 | |
| 35 class BluetoothThrottler; | 38 class BluetoothThrottler; |
| 36 | 39 |
| 37 // Represents a connection with a remote device over Bluetooth low energy. The | 40 namespace weave { |
| 38 // connection is a persistent bidirectional channel for sending and receiving | 41 // Creates GATT connection on top of the BLE connection and act as a Client. |
| 39 // wire messages. The remote device is the peripheral mode and the service | 42 // uWeave communication follows the flow: |
| 40 // contains two characteristics: one to send data and another to receive it. | 43 // Client | Server |
| 41 // | 44 // ---------------------------------|-------------------------------- |
| 42 // The connection flow is described below. | 45 // send connection request | |
| 43 // | 46 // | receive connection request |
| 44 // Discover Reader and Writer Characteristics | 47 // | send connection response |
| 45 // | | 48 // receive connection response | |
| 46 // | | 49 // opt: send data | opt: send data |
| 47 // | | 50 // receive data | receive data |
| 48 // Start Notify Session | 51 // opt: close connection | opt: close connection |
| 49 // | | 52 class BluetoothLowEnergyWeaveClientConnection |
| 50 // | | 53 : public Connection, |
| 51 // | | 54 public device::BluetoothAdapter::Observer { |
| 52 // Write kInviteToConnectSignal to Writer Characteristic | |
| 53 // | | |
| 54 // | | |
| 55 // | | |
| 56 // Read kInvitationResponseSignal from Reader Characteristic | |
| 57 // | | |
| 58 // | | |
| 59 // | | |
| 60 // Proximity Auth Connection Established | |
| 61 class BluetoothLowEnergyConnection : public Connection, | |
| 62 public device::BluetoothAdapter::Observer { | |
| 63 public: | 55 public: |
| 64 // Signals sent to the remote device to indicate connection related events. | 56 class Factory { |
| 65 enum class ControlSignal : uint32_t { | 57 public: |
| 66 kInviteToConnectSignal = 0, | 58 static std::unique_ptr<BluetoothLowEnergyWeaveClientConnection> |
| 67 kInvitationResponseSignal = 1, | 59 NewInstance(); |
| 68 kSendSignal = 2, | 60 |
| 69 kDisconnectSignal = 3, | 61 // Exposed for testing. |
| 62 static void SetInstanceForTesting(Factory* factory); | |
| 63 | |
| 64 protected: | |
| 65 // Exposed for testing. | |
| 66 virtual std::unique_ptr<BluetoothLowEnergyWeaveClientConnection> | |
| 67 BuildInstance(); | |
| 68 | |
| 69 private: | |
| 70 static Factory* factory_instance_; | |
| 70 }; | 71 }; |
| 71 | 72 |
| 72 // The sub-state of a proximity_auth::BluetoothLowEnergyConnection class | 73 // The sub-state of a proximity_auth::BluetoothLowEnergyWeaveClientConnection |
| 73 // extends the IN_PROGRESS state of proximity_auth::Connection::Status. | 74 // extends the IN_PROGRESS state of proximity_auth::Connection::Status. |
| 74 enum class SubStatus { | 75 enum SubStatus { |
| 75 DISCONNECTED, | 76 DISCONNECTED, |
| 76 WAITING_GATT_CONNECTION, | 77 WAITING_GATT_CONNECTION, |
| 77 WAITING_CHARACTERISTICS, | 78 WAITING_CHARACTERISTICS, |
| 78 CHARACTERISTICS_FOUND, | 79 CHARACTERISTICS_FOUND, |
| 79 WAITING_NOTIFY_SESSION, | 80 WAITING_NOTIFY_SESSION, |
| 80 NOTIFY_SESSION_READY, | 81 NOTIFY_SESSION_READY, |
| 81 WAITING_RESPONSE_SIGNAL, | 82 WAITING_CONNECTION_RESPONSE, |
| 82 CONNECTED, | 83 CONNECTED, |
| 83 }; | 84 }; |
| 84 | 85 |
| 85 // Constructs a Bluetooth low energy connection to the service with | 86 // Constructs a Bluetooth low energy connection to the service with |
| 86 // |remote_service_| on the |remote_device|. The |adapter| must be already | 87 // |remote_service_| on the |remote_device|. The |adapter| must be already |
| 87 // initaalized and ready. The GATT connection may alreaady be established and | 88 // initialized and ready. The GATT connection may alreaady be established and |
| 88 // pass through |gatt_connection|. A subsequent call to Connect() must be | 89 // pass through |gatt_connection|. A subsequent call to Connect() must be |
| 89 // made. | 90 // made. |
| 90 BluetoothLowEnergyConnection( | 91 BluetoothLowEnergyWeaveClientConnection( |
| 91 const RemoteDevice& remote_device, | 92 const RemoteDevice& remote_device, |
| 92 scoped_refptr<device::BluetoothAdapter> adapter, | 93 scoped_refptr<device::BluetoothAdapter> adapter, |
| 93 const device::BluetoothUUID remote_service_uuid, | 94 const device::BluetoothUUID remote_service_uuid, |
| 94 BluetoothThrottler* bluetooth_throttler, | 95 BluetoothThrottler* bluetooth_throttler, |
| 95 int max_number_of_write_attempts); | 96 int max_number_of_write_attempts); |
| 96 | 97 |
| 97 ~BluetoothLowEnergyConnection() override; | 98 ~BluetoothLowEnergyWeaveClientConnection() override; |
| 98 | 99 |
| 99 // proximity_auth::Connection: | 100 // proximity_auth::Connection: |
| 100 void Connect() override; | 101 void Connect() override; |
| 101 void Disconnect() override; | 102 void Disconnect() override; |
| 102 std::string GetDeviceAddress() override; | 103 std::string GetDeviceAddress() override; |
| 103 | 104 |
| 104 protected: | 105 protected: |
| 105 // Exposed for testing. | 106 // Exposed for testing. |
| 106 void SetSubStatus(SubStatus status); | 107 void DestroyConnection(); |
| 108 | |
| 109 // Exposed for testing. | |
| 107 SubStatus sub_status() { return sub_status_; } | 110 SubStatus sub_status() { return sub_status_; } |
| 108 | 111 |
| 112 // Exposed for testing. | |
| 113 int GetNumPendingMessages() { return map_to_message_.size(); } | |
| 114 | |
| 109 // Sets |task_runner_| for testing. | 115 // Sets |task_runner_| for testing. |
| 110 void SetTaskRunnerForTesting(scoped_refptr<base::TaskRunner> task_runner); | 116 void SetTaskRunnerForTesting(scoped_refptr<base::TaskRunner> task_runner); |
| 111 | 117 |
| 112 // Virtual for testing. | 118 // Virtual for testing. |
| 113 virtual BluetoothLowEnergyCharacteristicsFinder* CreateCharacteristicsFinder( | 119 virtual BluetoothLowEnergyCharacteristicsFinder* CreateCharacteristicsFinder( |
| 114 const BluetoothLowEnergyCharacteristicsFinder::SuccessCallback& | 120 const BluetoothLowEnergyCharacteristicsFinder::SuccessCallback& |
| 115 success_callback, | 121 success_callback, |
| 116 const BluetoothLowEnergyCharacteristicsFinder::ErrorCallback& | 122 const BluetoothLowEnergyCharacteristicsFinder::ErrorCallback& |
| 117 error_callback); | 123 error_callback); |
| 118 | 124 |
| 119 // proximity_auth::Connection: | 125 // proximity_auth::Connection: |
| 120 void SendMessageImpl(std::unique_ptr<WireMessage> message) override; | 126 void SendMessageImpl(std::unique_ptr<WireMessage> message) override; |
| 121 | 127 |
| 122 // device::BluetoothAdapter::Observer: | 128 // device::BluetoothAdapter::Observer: |
| 123 void DeviceChanged(device::BluetoothAdapter* adapter, | 129 void DeviceChanged(device::BluetoothAdapter* adapter, |
| 124 device::BluetoothDevice* device) override; | 130 device::BluetoothDevice* device) override; |
| 125 void DeviceRemoved(device::BluetoothAdapter* adapter, | 131 void DeviceRemoved(device::BluetoothAdapter* adapter, |
| 126 device::BluetoothDevice* device) override; | 132 device::BluetoothDevice* device) override; |
| 127 void GattCharacteristicValueChanged( | 133 void GattCharacteristicValueChanged( |
| 128 device::BluetoothAdapter* adapter, | 134 device::BluetoothAdapter* adapter, |
| 129 device::BluetoothRemoteGattCharacteristic* characteristic, | 135 device::BluetoothRemoteGattCharacteristic* characteristic, |
| 130 const std::vector<uint8_t>& value) override; | 136 const Packet& value) override; |
| 131 | 137 |
| 132 private: | 138 private: |
| 139 enum WriteRequestType { | |
| 140 REGULAR, | |
| 141 MESSAGE_COMPLETE, | |
| 142 CONNECTION_REQUEST, | |
| 143 CONNECTION_CLOSE | |
| 144 }; | |
| 145 | |
| 133 // Represents a request to write |value| to a some characteristic. | 146 // Represents a request to write |value| to a some characteristic. |
| 134 // |is_last_write_for_wire_messsage| indicates whether this request | 147 // |is_last_write_for_wire_messsage| indicates whether this request |
| 135 // corresponds to the last write request for some wire message. | 148 // corresponds to the last write request for some wire message. |
| 136 // A WireMessage corresponds to exactly two WriteRequest: the first containing | |
| 137 // a kSendSignal + the size of the WireMessage, and the second containing a | |
| 138 // SendStatusSignal + the serialized WireMessage. | |
| 139 struct WriteRequest { | 149 struct WriteRequest { |
| 140 WriteRequest(const std::vector<uint8_t>& val, bool flag); | 150 WriteRequest(const Packet& val, |
| 151 WriteRequestType request_type, | |
| 152 int message_counter); | |
| 153 WriteRequest(const Packet& val, WriteRequestType request_type); | |
| 141 WriteRequest(const WriteRequest& other); | 154 WriteRequest(const WriteRequest& other); |
| 142 ~WriteRequest(); | 155 ~WriteRequest(); |
| 143 | 156 |
| 144 std::vector<uint8_t> value; | 157 Packet value; |
| 145 bool is_last_write_for_wire_message; | 158 WriteRequestType request_type; |
| 159 int message_counter; | |
| 146 int number_of_failed_attempts; | 160 int number_of_failed_attempts; |
| 147 }; | 161 }; |
| 148 | 162 |
| 163 void SetSubStatus(SubStatus status); | |
| 164 | |
| 149 // Creates the GATT connection with |remote_device|. | 165 // Creates the GATT connection with |remote_device|. |
| 150 void CreateGattConnection(); | 166 void CreateGattConnection(); |
| 151 | 167 |
| 152 // Called when a GATT connection is created. | 168 // Called when a GATT connection is created. |
| 153 void OnGattConnectionCreated( | 169 void OnGattConnectionCreated( |
| 154 std::unique_ptr<device::BluetoothGattConnection> gatt_connection); | 170 std::unique_ptr<device::BluetoothGattConnection> gatt_connection); |
| 155 | 171 |
| 156 // Callback called when there is an error creating the GATT connection. | 172 // Callback called when there is an error creating the GATT connection. |
| 157 void OnCreateGattConnectionError( | 173 void OnCreateGattConnectionError( |
| 158 device::BluetoothDevice::ConnectErrorCode error_code); | 174 device::BluetoothDevice::ConnectErrorCode error_code); |
| 159 | 175 |
| 160 // Callback called when |to_peripheral_char_| and |from_peripheral_char_| were | 176 // Callback called when |tx_characteristic_| and |rx_characteristic_| were |
| 161 // found. | 177 // found. |
| 162 void OnCharacteristicsFound(const RemoteAttribute& service, | 178 void OnCharacteristicsFound(const RemoteAttribute& service, |
| 163 const RemoteAttribute& to_peripheral_char, | 179 const RemoteAttribute& tx_characteristic, |
| 164 const RemoteAttribute& from_peripheral_char); | 180 const RemoteAttribute& rx_characteristic); |
| 165 | 181 |
| 166 // Callback called there was an error finding the characteristics. | 182 // Callback called there was an error finding the characteristics. |
| 167 void OnCharacteristicsFinderError( | 183 void OnCharacteristicsFinderError(const RemoteAttribute& tx_characteristic, |
| 168 const RemoteAttribute& to_peripheral_char, | 184 const RemoteAttribute& rx_characteristic); |
| 169 const RemoteAttribute& from_peripheral_char); | |
| 170 | 185 |
| 171 // Starts a notify session for |from_peripheral_char_| when ready | 186 // Starts a notify session for |rx_characteristic_| when ready |
| 172 // (SubStatus::CHARACTERISTICS_FOUND). | 187 // (SubStatus::CHARACTERISTICS_FOUND). |
| 173 void StartNotifySession(); | 188 void StartNotifySession(); |
| 174 | 189 |
| 175 // Called when a notification session is successfully started for | 190 // Called when a notification session is successfully started for |
| 176 // |from_peripheral_char_| characteristic. | 191 // |rx_characteristic_| characteristic. |
| 177 void OnNotifySessionStarted( | 192 void OnNotifySessionStarted( |
| 178 std::unique_ptr<device::BluetoothGattNotifySession> notify_session); | 193 std::unique_ptr<device::BluetoothGattNotifySession> notify_session); |
| 179 | 194 |
| 180 // Called when there is an error starting a notification session for | 195 // Called when there is an error starting a notification session for |
| 181 // |from_peripheral_char_| characteristic. | 196 // |rx_characteristic_| characteristic. |
| 182 void OnNotifySessionError(device::BluetoothGattService::GattErrorCode); | 197 void OnNotifySessionError(device::BluetoothGattService::GattErrorCode); |
| 183 | 198 |
| 184 // Stops |notify_session_|. | 199 // Stops |notify_session_|. |
| 185 void StopNotifySession(); | 200 void StopNotifySession(); |
| 186 | 201 |
| 187 // Sends an invite to connect signal to the peripheral if when ready | 202 // Sends a connection request to server if ready |
| 188 // (SubStatus::NOTIFY_SESSION_READY). | 203 // (SubStatus::NOTIFY_SESSION_READY). |
| 189 void SendInviteToConnectSignal(); | 204 void SendConnectionRequest(); |
| 190 | 205 |
| 191 // Completes and updates the status accordingly. | 206 // Completes and updates the status accordingly. |
| 192 void CompleteConnection(); | 207 void CompleteConnection(); |
| 193 | 208 |
| 194 // This is the only entry point for WriteRequests, which are processed | 209 // This is the only entry point for WriteRequests, which are processed |
| 195 // accordingly the following flow: | 210 // accordingly the following flow: |
| 196 // 1) |request| is enqueued; | 211 // 1) |request| is enqueued; |
| 197 // 2) |request| will be processed by ProcessNextWriteRequest() when there is | 212 // 2) |request| will be processed by ProcessNextWriteRequest() when there is |
| 198 // no pending write request; | 213 // no pending write request; |
| 199 // 3) |request| will be dequeued when it's successfully processed | 214 // 3) |request| will be dequeued when it's successfully processed |
| 200 // (OnRemoteCharacteristicWritten()); | 215 // (OnRemoteCharacteristicWritten()); |
| 201 // 4) |request| is not dequeued if it fails | 216 // 4) |request| is not dequeued if it fails |
| 202 // (OnWriteRemoteCharacteristicError()), it remains on the queue and will be | 217 // (OnWriteRemoteCharacteristicError()), it remains on the queue and will be |
| 203 // retried. |request| will remain on the queue until it succeeds or it | 218 // retried. |request| will remain on the queue until it succeeds or it |
| 204 // triggers a Disconnect() call (after |max_number_of_tries_|). | 219 // triggers a Disconnect() call (after |max_number_of_tries_|). |
| 205 void WriteRemoteCharacteristic(WriteRequest request); | 220 void WriteRemoteCharacteristic(const WriteRequest& request); |
| 206 | 221 |
| 207 // Processes the next request in |write_requests_queue_|. | 222 // Processes the next request in |write_requests_queue_|. |
| 208 void ProcessNextWriteRequest(); | 223 void ProcessNextWriteRequest(); |
| 209 | 224 |
| 210 // Called when the | 225 // Called when the |
| 211 // BluetoothRemoteGattCharacteristic::RemoteCharacteristicWrite() is | 226 // BluetoothRemoteGattCharacteristic::RemoteCharacteristicWrite() is |
| 212 // successfully complete. | 227 // successfully complete. |
| 213 void OnRemoteCharacteristicWritten(bool run_did_send_message_callback); | 228 void OnRemoteCharacteristicWritten(WriteRequestType request_type, |
| 229 int message_counter); | |
| 214 | 230 |
| 215 // Called when there is an error writing to the remote characteristic | 231 // Called when there is an error writing to the remote characteristic |
| 216 // |to_peripheral_char_|. | 232 // |tx_characteristic_|. |
| 217 void OnWriteRemoteCharacteristicError( | 233 void OnWriteRemoteCharacteristicError( |
| 218 bool run_did_send_message_callback, | 234 WriteRequestType request_type, |
| 235 int message_counter, | |
| 219 device::BluetoothRemoteGattService::GattErrorCode error); | 236 device::BluetoothRemoteGattService::GattErrorCode error); |
| 220 | 237 |
| 221 // Builds the value to be written on |to_peripheral_char_|. The value | 238 void OnPacketReceiverError(); |
| 222 // corresponds to |signal| concatenated with |payload|. | |
| 223 WriteRequest BuildWriteRequest(const std::vector<uint8_t>& signal, | |
| 224 const std::vector<uint8_t>& bytes, | |
| 225 bool is_last_message_for_wire_message); | |
| 226 | 239 |
| 227 // Prints the time elapsed since |Connect()| was called. | 240 // Prints the time elapsed since |Connect()| was called. |
| 228 void PrintTimeElapsed(); | 241 void PrintTimeElapsed(); |
| 229 | 242 |
| 230 // Returns the device corresponding to |remote_device_address_|. | 243 // Returns the device corresponding to |remote_device_address_|. |
| 231 device::BluetoothDevice* GetRemoteDevice(); | 244 device::BluetoothDevice* GetRemoteDevice(); |
| 232 | 245 |
| 233 // Returns the service corresponding to |remote_service_| in the current | 246 // Returns the service corresponding to |remote_service_| in the current |
| 234 // device. | 247 // device. |
| 235 device::BluetoothRemoteGattService* GetRemoteService(); | 248 device::BluetoothRemoteGattService* GetRemoteService(); |
| 236 | 249 |
| 237 // Returns the characteristic corresponding to |identifier| in the current | 250 // Returns the characteristic corresponding to |identifier| in the current |
| 238 // service. | 251 // service. |
| 239 device::BluetoothRemoteGattCharacteristic* GetGattCharacteristic( | 252 device::BluetoothRemoteGattCharacteristic* GetGattCharacteristic( |
| 240 const std::string& identifier); | 253 const std::string& identifier); |
| 241 | 254 |
| 242 // Convert the first 4 bytes from a byte vector to a uint32_t. | 255 // Get the reason that the other side of the connection decided to close the |
| 243 uint32_t ToUint32(const std::vector<uint8_t>& bytes); | 256 // connection. |
| 244 | 257 // Will crash if the receiver is not in CONNECTION_CLOSED state. |
| 245 // Convert an uint32_t to a byte vector. | 258 std::string GetReasonForClose(); |
| 246 const std::vector<uint8_t> ToByteVector(uint32_t value); | |
| 247 | 259 |
| 248 // The Bluetooth adapter over which the Bluetooth connection will be made. | 260 // The Bluetooth adapter over which the Bluetooth connection will be made. |
| 249 scoped_refptr<device::BluetoothAdapter> adapter_; | 261 scoped_refptr<device::BluetoothAdapter> adapter_; |
| 250 | 262 |
| 251 // Remote service the |gatt_connection_| was established with. | 263 // Remote service the |gatt_connection_| was established with. |
| 252 RemoteAttribute remote_service_; | 264 RemoteAttribute remote_service_; |
| 253 | 265 |
| 266 // uWeave packet generator. | |
| 267 std::unique_ptr<BluetoothLowEnergyWeavePacketGenerator> packet_generator_; | |
| 268 | |
| 269 // uWeave packet receiver. | |
| 270 std::unique_ptr<BluetoothLowEnergyWeavePacketReceiver> packet_receiver_; | |
| 271 | |
| 254 // Characteristic used to send data to the remote device. | 272 // Characteristic used to send data to the remote device. |
| 255 RemoteAttribute to_peripheral_char_; | 273 RemoteAttribute tx_characteristic_; |
| 256 | 274 |
| 257 // Characteristic used to receive data from the remote device. | 275 // Characteristic used to receive data from the remote device. |
| 258 RemoteAttribute from_peripheral_char_; | 276 RemoteAttribute rx_characteristic_; |
| 259 | 277 |
| 260 // Throttles repeated connection attempts to the same device. This is a | 278 // Throttles repeated connection attempts to the same device. This is a |
| 261 // workaround for crbug.com/508919. Not owned, must outlive this instance. | 279 // workaround for crbug.com/508919. Not owned, must outlive this instance. |
| 262 BluetoothThrottler* bluetooth_throttler_; | 280 BluetoothThrottler* bluetooth_throttler_; |
| 263 | 281 |
| 264 scoped_refptr<base::TaskRunner> task_runner_; | 282 scoped_refptr<base::TaskRunner> task_runner_; |
| 265 | 283 |
| 266 // The GATT connection with the remote device. | 284 // The GATT connection with the remote device. |
| 267 std::unique_ptr<device::BluetoothGattConnection> gatt_connection_; | 285 std::unique_ptr<device::BluetoothGattConnection> gatt_connection_; |
| 268 | 286 |
| 269 // The characteristics finder for remote device. | 287 // The characteristics finder for remote device. |
| 270 std::unique_ptr<BluetoothLowEnergyCharacteristicsFinder> | 288 std::unique_ptr<BluetoothLowEnergyCharacteristicsFinder> |
| 271 characteristic_finder_; | 289 characteristic_finder_; |
| 272 | 290 |
| 273 // The notify session for |from_peripheral_char|. | 291 // The notify session for |rx_characteristic|. |
| 274 std::unique_ptr<device::BluetoothGattNotifySession> notify_session_; | 292 std::unique_ptr<device::BluetoothGattNotifySession> notify_session_; |
| 275 | 293 |
| 276 // Internal connection status | 294 // Internal connection status |
| 277 SubStatus sub_status_; | 295 SubStatus sub_status_; |
| 278 | 296 |
| 279 // Indicates a receiving operation is in progress. This is set after a | |
| 280 // ControlSignal::kSendSignal was received from the remote device. | |
| 281 bool receiving_bytes_; | |
| 282 | |
| 283 // Total number of bytes expected for the current receive operation. | |
| 284 std::size_t expected_number_of_incoming_bytes_; | |
| 285 | |
| 286 // Bytes already received for the current receive operation. | 297 // Bytes already received for the current receive operation. |
| 287 std::string incoming_bytes_buffer_; | 298 std::string incoming_bytes_buffer_; |
| 288 | 299 |
| 289 // Indicates there is a | 300 // Indicates there is a |
| 290 // BluetoothRemoteGattCharacteristic::WriteRemoteCharacteristic | 301 // BluetoothRemoteGattCharacteristic::WriteRemoteCharacteristic |
| 291 // operation pending. | 302 // operation pending. |
| 292 bool write_remote_characteristic_pending_; | 303 bool write_remote_characteristic_pending_; |
| 293 | 304 |
| 294 std::queue<WriteRequest> write_requests_queue_; | 305 std::queue<WriteRequest> write_requests_queue_; |
| 295 | 306 |
| 307 // Counter indicating which message the packet is from. | |
| 308 int next_message_counter_to_use_; | |
| 309 | |
| 310 // Map of the message_counter_ to it's corresponding message. | |
| 311 std::map<int, std::unique_ptr<WireMessage>> map_to_message_; | |
| 312 | |
| 296 // Maximum number of tries to send any write request. | 313 // Maximum number of tries to send any write request. |
| 297 int max_number_of_write_attempts_; | 314 int max_number_of_write_attempts_; |
| 298 | 315 |
| 299 // Maximum number of bytes that fit in a single chunk to be written in | |
| 300 // |to_peripheral_char_|. Ideally, this should be the maximum value the | |
| 301 // peripheral supports and it should be agreed when the GATT connection is | |
| 302 // created. Currently, there is no API to find this value. The implementation | |
| 303 // uses a hard-coded constant. | |
| 304 int max_chunk_size_; | |
| 305 | |
| 306 // Stores when the instace was created. | 316 // Stores when the instace was created. |
| 307 base::TimeTicks start_time_; | 317 base::TimeTicks start_time_; |
| 308 | 318 |
| 309 base::WeakPtrFactory<BluetoothLowEnergyConnection> weak_ptr_factory_; | 319 base::WeakPtrFactory<BluetoothLowEnergyWeaveClientConnection> |
| 320 weak_ptr_factory_; | |
| 310 | 321 |
| 311 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyConnection); | 322 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyWeaveClientConnection); |
| 312 }; | 323 }; |
| 313 | 324 |
| 325 } // namespace weave | |
| 326 | |
| 314 } // namespace proximity_auth | 327 } // namespace proximity_auth |
| 315 | 328 |
| 316 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_CONNECTION_H_ | 329 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WEAVE_CLIENT_CONNE CTION_H_ |
| OLD | NEW |