Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ |
| 6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ | 6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 | 11 |
| 12 #include "base/id_map.h" | 12 #include "base/id_map.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "content/browser/bluetooth/bluetooth_allowed_devices_map.h" | 16 #include "content/browser/bluetooth/bluetooth_allowed_devices_map.h" |
| 17 #include "content/browser/bluetooth/bluetooth_metrics.h" | |
| 18 #include "content/common/bluetooth/bluetooth_messages.h" | |
| 17 #include "content/public/browser/bluetooth_chooser.h" | 19 #include "content/public/browser/bluetooth_chooser.h" |
| 18 #include "content/public/browser/browser_message_filter.h" | 20 #include "content/public/browser/browser_message_filter.h" |
| 19 #include "device/bluetooth/bluetooth_adapter.h" | 21 #include "device/bluetooth/bluetooth_adapter.h" |
| 20 #include "device/bluetooth/bluetooth_gatt_connection.h" | 22 #include "device/bluetooth/bluetooth_gatt_connection.h" |
| 21 #include "device/bluetooth/bluetooth_gatt_notify_session.h" | 23 #include "device/bluetooth/bluetooth_gatt_notify_session.h" |
| 22 #include "device/bluetooth/bluetooth_gatt_service.h" | 24 #include "device/bluetooth/bluetooth_gatt_service.h" |
| 23 | 25 |
| 24 namespace device { | 26 namespace device { |
| 25 class BluetoothUUID; | 27 class BluetoothUUID; |
| 26 } | 28 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 46 BluetoothDispatcherHost(int render_process_id); | 48 BluetoothDispatcherHost(int render_process_id); |
| 47 // BrowserMessageFilter: | 49 // BrowserMessageFilter: |
| 48 void OnDestruct() const override; | 50 void OnDestruct() const override; |
| 49 void OverrideThreadForMessage(const IPC::Message& message, | 51 void OverrideThreadForMessage(const IPC::Message& message, |
| 50 BrowserThread::ID* thread) override; | 52 BrowserThread::ID* thread) override; |
| 51 bool OnMessageReceived(const IPC::Message& message) override; | 53 bool OnMessageReceived(const IPC::Message& message) override; |
| 52 | 54 |
| 53 void SetBluetoothAdapterForTesting( | 55 void SetBluetoothAdapterForTesting( |
| 54 scoped_refptr<device::BluetoothAdapter> mock_adapter); | 56 scoped_refptr<device::BluetoothAdapter> mock_adapter); |
| 55 | 57 |
| 58 // TODO(ortuno): We temporarily make this a public struct so that | |
|
palmer
2016/03/30 21:34:51
Attach a bug ID to every TODO. Also typo: capital
ortuno
2016/03/30 22:37:56
Done.
| |
| 59 // both BluetoothDispatcherHost and WebBluetoothServiceImpl can use it, | |
| 60 // while we move functions from BluetoothDispatcherhost to | |
| 61 // WebBluetoothServiceImpl. | |
| 62 struct CacheQueryResult { | |
| 63 CacheQueryResult(); | |
| 64 CacheQueryResult(CacheQueryOutcome outcome); | |
| 65 ~CacheQueryResult(); | |
| 66 blink::WebBluetoothError GetWebError() const; | |
| 67 device::BluetoothDevice* device = nullptr; | |
| 68 device::BluetoothGattService* service = nullptr; | |
| 69 device::BluetoothGattCharacteristic* characteristic = nullptr; | |
| 70 CacheQueryOutcome outcome = CacheQueryOutcome::SUCCESS; | |
| 71 }; | |
| 72 | |
| 73 // Queries the platform cache for a characteristic with | |
| 74 // |characteristic_instance_id|. Fills in the |outcome| field, and |device|, | |
| 75 // |service| and |characteristic| fields if successful. | |
| 76 CacheQueryResult QueryCacheForCharacteristic( | |
| 77 const url::Origin& origin, | |
| 78 const std::string& characteristic_instance_id); | |
| 79 | |
| 56 protected: | 80 protected: |
| 57 ~BluetoothDispatcherHost() override; | 81 ~BluetoothDispatcherHost() override; |
| 58 | 82 |
| 59 private: | 83 private: |
| 60 friend class base::DeleteHelper<BluetoothDispatcherHost>; | 84 friend class base::DeleteHelper<BluetoothDispatcherHost>; |
| 61 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 85 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
| 62 | 86 |
| 63 struct CacheQueryResult; | |
| 64 struct RequestDeviceSession; | 87 struct RequestDeviceSession; |
| 65 struct PrimaryServicesRequest; | 88 struct PrimaryServicesRequest; |
| 66 | 89 |
| 67 // Set |adapter_| to a BluetoothAdapter instance and register observers, | 90 // Set |adapter_| to a BluetoothAdapter instance and register observers, |
| 68 // releasing references to previous |adapter_|. | 91 // releasing references to previous |adapter_|. |
| 69 void set_adapter(scoped_refptr<device::BluetoothAdapter> adapter); | 92 void set_adapter(scoped_refptr<device::BluetoothAdapter> adapter); |
| 70 | 93 |
| 71 // Makes sure a BluetoothDiscoverySession is active for |session|, and resets | 94 // Makes sure a BluetoothDiscoverySession is active for |session|, and resets |
| 72 // its timeout. | 95 // its timeout. |
| 73 void StartDeviceDiscovery(RequestDeviceSession* session, int chooser_id); | 96 void StartDeviceDiscovery(RequestDeviceSession* session, int chooser_id); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 const std::string& characteristic_uuid); | 145 const std::string& characteristic_uuid); |
| 123 void OnGetCharacteristics(int thread_id, | 146 void OnGetCharacteristics(int thread_id, |
| 124 int request_id, | 147 int request_id, |
| 125 int frame_routing_id, | 148 int frame_routing_id, |
| 126 const std::string& service_instance_id, | 149 const std::string& service_instance_id, |
| 127 const std::string& characteristics_uuid); | 150 const std::string& characteristics_uuid); |
| 128 void OnReadValue(int thread_id, | 151 void OnReadValue(int thread_id, |
| 129 int request_id, | 152 int request_id, |
| 130 int frame_routing_id, | 153 int frame_routing_id, |
| 131 const std::string& characteristic_instance_id); | 154 const std::string& characteristic_instance_id); |
| 132 void OnWriteValue(int thread_id, | |
| 133 int request_id, | |
| 134 int frame_routing_id, | |
| 135 const std::string& characteristic_instance_id, | |
| 136 const std::vector<uint8_t>& value); | |
| 137 void OnStartNotifications(int thread_id, | 155 void OnStartNotifications(int thread_id, |
| 138 int request_id, | 156 int request_id, |
| 139 int frame_routing_id, | 157 int frame_routing_id, |
| 140 const std::string& characteristic_instance_id); | 158 const std::string& characteristic_instance_id); |
| 141 void OnStopNotifications(int thread_id, | 159 void OnStopNotifications(int thread_id, |
| 142 int request_id, | 160 int request_id, |
| 143 int frame_routing_id, | 161 int frame_routing_id, |
| 144 const std::string& characteristic_instance_id); | 162 const std::string& characteristic_instance_id); |
| 145 void OnRegisterCharacteristicObject( | 163 void OnRegisterCharacteristicObject( |
| 146 int thread_id, | 164 int thread_id, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 | 222 |
| 205 // Callbacks for BluetoothGattCharacteristic::ReadRemoteCharacteristic. | 223 // Callbacks for BluetoothGattCharacteristic::ReadRemoteCharacteristic. |
| 206 void OnCharacteristicValueRead(int thread_id, | 224 void OnCharacteristicValueRead(int thread_id, |
| 207 int request_id, | 225 int request_id, |
| 208 const std::vector<uint8_t>& value); | 226 const std::vector<uint8_t>& value); |
| 209 void OnCharacteristicReadValueError( | 227 void OnCharacteristicReadValueError( |
| 210 int thread_id, | 228 int thread_id, |
| 211 int request_id, | 229 int request_id, |
| 212 device::BluetoothGattService::GattErrorCode); | 230 device::BluetoothGattService::GattErrorCode); |
| 213 | 231 |
| 214 // Callbacks for BluetoothGattCharacteristic::WriteRemoteCharacteristic. | |
| 215 void OnWriteValueSuccess(int thread_id, int request_id); | |
| 216 void OnWriteValueFailed(int thread_id, | |
| 217 int request_id, | |
| 218 device::BluetoothGattService::GattErrorCode); | |
| 219 | |
| 220 // Callbacks for BluetoothGattCharacteristic::StartNotifySession. | 232 // Callbacks for BluetoothGattCharacteristic::StartNotifySession. |
| 221 void OnStartNotifySessionSuccess( | 233 void OnStartNotifySessionSuccess( |
| 222 int thread_id, | 234 int thread_id, |
| 223 int request_id, | 235 int request_id, |
| 224 scoped_ptr<device::BluetoothGattNotifySession> notify_session); | 236 scoped_ptr<device::BluetoothGattNotifySession> notify_session); |
| 225 void OnStartNotifySessionFailed( | 237 void OnStartNotifySessionFailed( |
| 226 int thread_id, | 238 int thread_id, |
| 227 int request_id, | 239 int request_id, |
| 228 device::BluetoothGattService::GattErrorCode error_code); | 240 device::BluetoothGattService::GattErrorCode error_code); |
| 229 | 241 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 241 // send a response. | 253 // send a response. |
| 242 | 254 |
| 243 // Queries the platform cache for a Device with |device_id| for |origin|. | 255 // Queries the platform cache for a Device with |device_id| for |origin|. |
| 244 // Fills in the |outcome| field and the |device| field if successful. | 256 // Fills in the |outcome| field and the |device| field if successful. |
| 245 CacheQueryResult QueryCacheForDevice(const url::Origin& origin, | 257 CacheQueryResult QueryCacheForDevice(const url::Origin& origin, |
| 246 const std::string& device_id); | 258 const std::string& device_id); |
| 247 // Queries the platform cache for a Service with |service_instance_id|. Fills | 259 // Queries the platform cache for a Service with |service_instance_id|. Fills |
| 248 // in the |outcome| field, and |device| and |service| fields if successful. | 260 // in the |outcome| field, and |device| and |service| fields if successful. |
| 249 CacheQueryResult QueryCacheForService(const url::Origin& origin, | 261 CacheQueryResult QueryCacheForService(const url::Origin& origin, |
| 250 const std::string& service_instance_id); | 262 const std::string& service_instance_id); |
| 251 // Queries the platform cache for a characteristic with | |
| 252 // |characteristic_instance_id|. Fills in the |outcome| field, and |device|, | |
| 253 // |service| and |characteristic| fields if successful. | |
| 254 CacheQueryResult QueryCacheForCharacteristic( | |
| 255 const url::Origin& origin, | |
| 256 const std::string& characteristic_instance_id); | |
| 257 | 263 |
| 258 // Adds the PrimaryServicesRequest to the vector of pending services requests | 264 // Adds the PrimaryServicesRequest to the vector of pending services requests |
| 259 // for that device. | 265 // for that device. |
| 260 void AddToPendingPrimaryServicesRequest( | 266 void AddToPendingPrimaryServicesRequest( |
| 261 const std::string& device_address, | 267 const std::string& device_address, |
| 262 const PrimaryServicesRequest& request); | 268 const PrimaryServicesRequest& request); |
| 263 | 269 |
| 264 // Returns the origin for the frame with "frame_routing_id" in | 270 // Returns the origin for the frame with "frame_routing_id" in |
| 265 // render_process_id_. | 271 // render_process_id_. |
| 266 url::Origin GetOrigin(int frame_routing_id); | 272 url::Origin GetOrigin(int frame_routing_id); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 // copies verify they are also used on the UI thread. | 331 // copies verify they are also used on the UI thread. |
| 326 base::WeakPtr<BluetoothDispatcherHost> weak_ptr_on_ui_thread_; | 332 base::WeakPtr<BluetoothDispatcherHost> weak_ptr_on_ui_thread_; |
| 327 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; | 333 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; |
| 328 | 334 |
| 329 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); | 335 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); |
| 330 }; | 336 }; |
| 331 | 337 |
| 332 } // namespace content | 338 } // namespace content |
| 333 | 339 |
| 334 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ | 340 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ |
| OLD | NEW |