| 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 |
| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 221 |
| 204 // Callbacks for BluetoothGattCharacteristic::ReadRemoteCharacteristic. | 222 // Callbacks for BluetoothGattCharacteristic::ReadRemoteCharacteristic. |
| 205 void OnCharacteristicValueRead(int thread_id, | 223 void OnCharacteristicValueRead(int thread_id, |
| 206 int request_id, | 224 int request_id, |
| 207 const std::vector<uint8_t>& value); | 225 const std::vector<uint8_t>& value); |
| 208 void OnCharacteristicReadValueError( | 226 void OnCharacteristicReadValueError( |
| 209 int thread_id, | 227 int thread_id, |
| 210 int request_id, | 228 int request_id, |
| 211 device::BluetoothGattService::GattErrorCode); | 229 device::BluetoothGattService::GattErrorCode); |
| 212 | 230 |
| 213 // Callbacks for BluetoothGattCharacteristic::WriteRemoteCharacteristic. | |
| 214 void OnWriteValueSuccess(int thread_id, int request_id); | |
| 215 void OnWriteValueFailed(int thread_id, | |
| 216 int request_id, | |
| 217 device::BluetoothGattService::GattErrorCode); | |
| 218 | |
| 219 // Callbacks for BluetoothGattCharacteristic::StartNotifySession. | 231 // Callbacks for BluetoothGattCharacteristic::StartNotifySession. |
| 220 void OnStartNotifySessionSuccess( | 232 void OnStartNotifySessionSuccess( |
| 221 int thread_id, | 233 int thread_id, |
| 222 int request_id, | 234 int request_id, |
| 223 scoped_ptr<device::BluetoothGattNotifySession> notify_session); | 235 scoped_ptr<device::BluetoothGattNotifySession> notify_session); |
| 224 void OnStartNotifySessionFailed( | 236 void OnStartNotifySessionFailed( |
| 225 int thread_id, | 237 int thread_id, |
| 226 int request_id, | 238 int request_id, |
| 227 device::BluetoothGattService::GattErrorCode error_code); | 239 device::BluetoothGattService::GattErrorCode error_code); |
| 228 | 240 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 240 // send a response. | 252 // send a response. |
| 241 | 253 |
| 242 // Queries the platform cache for a Device with |device_id| for |origin|. | 254 // Queries the platform cache for a Device with |device_id| for |origin|. |
| 243 // Fills in the |outcome| field and the |device| field if successful. | 255 // Fills in the |outcome| field and the |device| field if successful. |
| 244 CacheQueryResult QueryCacheForDevice(const url::Origin& origin, | 256 CacheQueryResult QueryCacheForDevice(const url::Origin& origin, |
| 245 const std::string& device_id); | 257 const std::string& device_id); |
| 246 // Queries the platform cache for a Service with |service_instance_id|. Fills | 258 // Queries the platform cache for a Service with |service_instance_id|. Fills |
| 247 // in the |outcome| field, and |device| and |service| fields if successful. | 259 // in the |outcome| field, and |device| and |service| fields if successful. |
| 248 CacheQueryResult QueryCacheForService(const url::Origin& origin, | 260 CacheQueryResult QueryCacheForService(const url::Origin& origin, |
| 249 const std::string& service_instance_id); | 261 const std::string& service_instance_id); |
| 250 // Queries the platform cache for a characteristic with | |
| 251 // |characteristic_instance_id|. Fills in the |outcome| field, and |device|, | |
| 252 // |service| and |characteristic| fields if successful. | |
| 253 CacheQueryResult QueryCacheForCharacteristic( | |
| 254 const url::Origin& origin, | |
| 255 const std::string& characteristic_instance_id); | |
| 256 | 262 |
| 257 // Adds the PrimaryServicesRequest to the vector of pending services requests | 263 // Adds the PrimaryServicesRequest to the vector of pending services requests |
| 258 // for that device. | 264 // for that device. |
| 259 void AddToPendingPrimaryServicesRequest( | 265 void AddToPendingPrimaryServicesRequest( |
| 260 const std::string& device_address, | 266 const std::string& device_address, |
| 261 const PrimaryServicesRequest& request); | 267 const PrimaryServicesRequest& request); |
| 262 | 268 |
| 263 // Returns the origin for the frame with "frame_routing_id" in | 269 // Returns the origin for the frame with "frame_routing_id" in |
| 264 // render_process_id_. | 270 // render_process_id_. |
| 265 url::Origin GetOrigin(int frame_routing_id); | 271 url::Origin GetOrigin(int frame_routing_id); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 // copies verify they are also used on the UI thread. | 330 // copies verify they are also used on the UI thread. |
| 325 base::WeakPtr<BluetoothDispatcherHost> weak_ptr_on_ui_thread_; | 331 base::WeakPtr<BluetoothDispatcherHost> weak_ptr_on_ui_thread_; |
| 326 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; | 332 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; |
| 327 | 333 |
| 328 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); | 334 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); |
| 329 }; | 335 }; |
| 330 | 336 |
| 331 } // namespace content | 337 } // namespace content |
| 332 | 338 |
| 333 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ | 339 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ |
| OLD | NEW |