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" | |
| 19 #include "content/public/browser/bluetooth_chooser.h" | 17 #include "content/public/browser/bluetooth_chooser.h" |
| 20 #include "content/public/browser/browser_message_filter.h" | 18 #include "content/public/browser/browser_message_filter.h" |
| 21 #include "device/bluetooth/bluetooth_adapter.h" | 19 #include "device/bluetooth/bluetooth_adapter.h" |
| 22 #include "device/bluetooth/bluetooth_gatt_connection.h" | 20 #include "device/bluetooth/bluetooth_gatt_connection.h" |
| 23 #include "device/bluetooth/bluetooth_gatt_notify_session.h" | 21 #include "device/bluetooth/bluetooth_gatt_notify_session.h" |
| 24 #include "device/bluetooth/bluetooth_gatt_service.h" | 22 #include "device/bluetooth/bluetooth_gatt_service.h" |
| 25 | 23 |
| 26 namespace device { | 24 namespace device { |
| 27 class BluetoothUUID; | 25 class BluetoothUUID; |
| 28 } | 26 } |
| 29 | 27 |
| 30 namespace content { | 28 namespace content { |
| 31 | 29 |
| 32 struct BluetoothScanFilter; | 30 struct BluetoothScanFilter; |
| 31 struct CacheQueryResult; | |
| 33 | 32 |
| 34 // Dispatches and sends bluetooth related messages sent to/from a child | 33 // Dispatches and sends bluetooth related messages sent to/from a child |
| 35 // process BluetoothDispatcher from/to the main browser process. | 34 // process BluetoothDispatcher from/to the main browser process. |
| 36 // | 35 // |
| 37 // Intended to be instantiated by the RenderProcessHost and installed as | 36 // Intended to be instantiated by the RenderProcessHost and installed as |
| 38 // a filter on the channel. BrowserMessageFilter is refcounted and typically | 37 // a filter on the channel. BrowserMessageFilter is refcounted and typically |
| 39 // lives as long as it is installed on a channel. | 38 // lives as long as it is installed on a channel. |
| 40 // | 39 // |
| 41 // UI Thread Note: | 40 // UI Thread Note: |
| 42 // BluetoothDispatcherHost is constructed, operates, and destroyed on the UI | 41 // BluetoothDispatcherHost is constructed, operates, and destroyed on the UI |
| 43 // thread because BluetoothAdapter and related objects live there. | 42 // thread because BluetoothAdapter and related objects live there. |
| 44 class CONTENT_EXPORT BluetoothDispatcherHost final | 43 class CONTENT_EXPORT BluetoothDispatcherHost final |
| 45 : public BrowserMessageFilter, | 44 : public BrowserMessageFilter, |
| 46 public device::BluetoothAdapter::Observer { | 45 public device::BluetoothAdapter::Observer { |
| 47 public: | 46 public: |
| 48 BluetoothDispatcherHost(int render_process_id); | 47 BluetoothDispatcherHost(int render_process_id); |
| 49 // BrowserMessageFilter: | 48 // BrowserMessageFilter: |
| 50 void OnDestruct() const override; | 49 void OnDestruct() const override; |
| 51 void OverrideThreadForMessage(const IPC::Message& message, | 50 void OverrideThreadForMessage(const IPC::Message& message, |
| 52 BrowserThread::ID* thread) override; | 51 BrowserThread::ID* thread) override; |
| 53 bool OnMessageReceived(const IPC::Message& message) override; | 52 bool OnMessageReceived(const IPC::Message& message) override; |
| 54 | 53 |
| 55 void SetBluetoothAdapterForTesting( | 54 void SetBluetoothAdapterForTesting( |
| 56 scoped_refptr<device::BluetoothAdapter> mock_adapter); | 55 scoped_refptr<device::BluetoothAdapter> mock_adapter); |
| 57 | 56 |
| 58 // TODO(ortuno): We temporarily make this a public struct so that | 57 // Queries the platform cache for a Service with |service_instance_id|. Fills |
| 59 // both BluetoothDispatcherHost and WebBluetoothServiceImpl can use it, | 58 // in the |outcome| field, and |device| and |service| fields if successful. |
| 60 // while we move functions from BluetoothDispatcherHost to | 59 CacheQueryResult QueryCacheForService(const url::Origin& origin, |
|
Jeffrey Yasskin
2016/04/22 01:16:37
It might make sense to make BluetoothServiceImpl a
ortuno
2016/04/25 15:29:45
Done.
| |
| 61 // WebBluetoothServiceImpl. | 60 const std::string& service_instance_id); |
| 62 // https://crbug.com/508771 | |
| 63 struct CacheQueryResult { | |
| 64 CacheQueryResult(); | |
| 65 CacheQueryResult(CacheQueryOutcome outcome); | |
| 66 ~CacheQueryResult(); | |
| 67 blink::WebBluetoothError GetWebError() const; | |
| 68 device::BluetoothDevice* device = nullptr; | |
| 69 device::BluetoothGattService* service = nullptr; | |
| 70 device::BluetoothGattCharacteristic* characteristic = nullptr; | |
| 71 CacheQueryOutcome outcome = CacheQueryOutcome::SUCCESS; | |
| 72 }; | |
| 73 | |
| 74 // Queries the platform cache for a characteristic with | |
| 75 // |characteristic_instance_id|. Fills in the |outcome| field, and |device|, | |
| 76 // |service| and |characteristic| fields if successful. | |
| 77 CacheQueryResult QueryCacheForCharacteristic( | |
| 78 const url::Origin& origin, | |
| 79 const std::string& characteristic_instance_id); | |
| 80 | 61 |
| 81 // Temporary functions so that WebBluetoothServices can add themselves as | 62 // Temporary functions so that WebBluetoothServices can add themselves as |
| 82 // observers of the Bluetooth Adapter without having to get an adapter for | 63 // observers of the Bluetooth Adapter without having to get an adapter for |
| 83 // themselves. | 64 // themselves. |
| 84 // TODO(ortuno): Remove once WebBluetoothServiceImpl gets its own adapter. | 65 // TODO(ortuno): Remove once WebBluetoothServiceImpl gets its own adapter. |
| 85 // https://crbug.com/508771 | 66 // https://crbug.com/508771 |
| 86 void AddAdapterObserver(device::BluetoothAdapter::Observer* observer); | 67 void AddAdapterObserver(device::BluetoothAdapter::Observer* observer); |
| 87 void RemoveAdapterObserver(device::BluetoothAdapter::Observer* observer); | 68 void RemoveAdapterObserver(device::BluetoothAdapter::Observer* observer); |
| 88 | 69 |
| 89 protected: | 70 protected: |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 int frame_routing_id, | 141 int frame_routing_id, |
| 161 const std::string& device_id); | 142 const std::string& device_id); |
| 162 void OnGATTServerDisconnect(int thread_id, | 143 void OnGATTServerDisconnect(int thread_id, |
| 163 int frame_routing_id, | 144 int frame_routing_id, |
| 164 const std::string& device_id); | 145 const std::string& device_id); |
| 165 void OnGetPrimaryService(int thread_id, | 146 void OnGetPrimaryService(int thread_id, |
| 166 int request_id, | 147 int request_id, |
| 167 int frame_routing_id, | 148 int frame_routing_id, |
| 168 const std::string& device_id, | 149 const std::string& device_id, |
| 169 const std::string& service_uuid); | 150 const std::string& service_uuid); |
| 170 void OnGetCharacteristic(int thread_id, | |
| 171 int request_id, | |
| 172 int frame_routing_id, | |
| 173 const std::string& service_instance_id, | |
| 174 const std::string& characteristic_uuid); | |
| 175 void OnGetCharacteristics(int thread_id, | |
| 176 int request_id, | |
| 177 int frame_routing_id, | |
| 178 const std::string& service_instance_id, | |
| 179 const std::string& characteristics_uuid); | |
| 180 | 151 |
| 181 // Callbacks for BluetoothDevice::OnRequestDevice. | 152 // Callbacks for BluetoothDevice::OnRequestDevice. |
| 182 // If necessary, the adapter must be obtained before continuing to Impl. | 153 // If necessary, the adapter must be obtained before continuing to Impl. |
| 183 void OnGetAdapter(base::Closure continuation, | 154 void OnGetAdapter(base::Closure continuation, |
| 184 scoped_refptr<device::BluetoothAdapter> adapter); | 155 scoped_refptr<device::BluetoothAdapter> adapter); |
| 185 void OnRequestDeviceImpl( | 156 void OnRequestDeviceImpl( |
| 186 int thread_id, | 157 int thread_id, |
| 187 int request_id, | 158 int request_id, |
| 188 int frame_routing_id, | 159 int frame_routing_id, |
| 189 const std::vector<content::BluetoothScanFilter>& filters, | 160 const std::vector<content::BluetoothScanFilter>& filters, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 // cache. Otherwise result.outcome that can used to record the outcome and | 205 // cache. Otherwise result.outcome that can used to record the outcome and |
| 235 // result.error will contain the error that should be send to the renderer. | 206 // result.error will contain the error that should be send to the renderer. |
| 236 // One of the possible outcomes is BAD_RENDERER. In this case the outcome | 207 // One of the possible outcomes is BAD_RENDERER. In this case the outcome |
| 237 // was already recorded and since there renderer crashed there is no need to | 208 // was already recorded and since there renderer crashed there is no need to |
| 238 // send a response. | 209 // send a response. |
| 239 | 210 |
| 240 // Queries the platform cache for a Device with |device_id| for |origin|. | 211 // Queries the platform cache for a Device with |device_id| for |origin|. |
| 241 // Fills in the |outcome| field and the |device| field if successful. | 212 // Fills in the |outcome| field and the |device| field if successful. |
| 242 CacheQueryResult QueryCacheForDevice(const url::Origin& origin, | 213 CacheQueryResult QueryCacheForDevice(const url::Origin& origin, |
| 243 const std::string& device_id); | 214 const std::string& device_id); |
| 244 // Queries the platform cache for a Service with |service_instance_id|. Fills | |
| 245 // in the |outcome| field, and |device| and |service| fields if successful. | |
| 246 CacheQueryResult QueryCacheForService(const url::Origin& origin, | |
| 247 const std::string& service_instance_id); | |
| 248 | 215 |
| 249 // Adds the PrimaryServicesRequest to the vector of pending services requests | 216 // Adds the PrimaryServicesRequest to the vector of pending services requests |
| 250 // for that device. | 217 // for that device. |
| 251 void AddToPendingPrimaryServicesRequest( | 218 void AddToPendingPrimaryServicesRequest( |
| 252 const std::string& device_address, | 219 const std::string& device_address, |
| 253 const PrimaryServicesRequest& request); | 220 const PrimaryServicesRequest& request); |
| 254 | 221 |
| 255 // Returns the origin for the frame with "frame_routing_id" in | 222 // Returns the origin for the frame with "frame_routing_id" in |
| 256 // render_process_id_. | 223 // render_process_id_. |
| 257 url::Origin GetOrigin(int frame_routing_id); | 224 url::Origin GetOrigin(int frame_routing_id); |
| 258 | 225 |
| 259 int render_process_id_; | 226 int render_process_id_; |
| 260 | 227 |
| 261 // Maps a (thread_id,request_id) to information about its requestDevice call, | 228 // Maps a (thread_id,request_id) to information about its requestDevice call, |
| 262 // including the chooser dialog. | 229 // including the chooser dialog. |
| 263 // An entry is added to this map in OnRequestDevice, and should be removed | 230 // An entry is added to this map in OnRequestDevice, and should be removed |
| 264 // again everywhere a requestDevice() reply is sent. | 231 // again everywhere a requestDevice() reply is sent. |
| 265 IDMap<RequestDeviceSession, IDMapOwnPointer> request_device_sessions_; | 232 IDMap<RequestDeviceSession, IDMapOwnPointer> request_device_sessions_; |
| 266 | 233 |
| 267 BluetoothAllowedDevicesMap allowed_devices_map_; | 234 BluetoothAllowedDevicesMap allowed_devices_map_; |
| 268 | 235 |
| 269 // Maps to get the object's parent based on it's instanceID | 236 // Maps to get the object's parent based on it's instanceID |
| 270 // Map of service_instance_id to device_address. | 237 // Map of service_instance_id to device_address. |
| 271 std::map<std::string, std::string> service_to_device_; | 238 std::map<std::string, std::string> service_to_device_; |
| 272 // Map of characteristic_instance_id to service_instance_id. | |
| 273 std::map<std::string, std::string> characteristic_to_service_; | |
| 274 | 239 |
| 275 // Defines how long to scan for and how long to discover services for. | 240 // Defines how long to scan for and how long to discover services for. |
| 276 int current_delay_time_; | 241 int current_delay_time_; |
| 277 | 242 |
| 278 // A BluetoothAdapter instance representing an adapter of the system. | 243 // A BluetoothAdapter instance representing an adapter of the system. |
| 279 scoped_refptr<device::BluetoothAdapter> adapter_; | 244 scoped_refptr<device::BluetoothAdapter> adapter_; |
| 280 | 245 |
| 281 std::unordered_set<device::BluetoothAdapter::Observer*> adapter_observers_; | 246 std::unordered_set<device::BluetoothAdapter::Observer*> adapter_observers_; |
| 282 | 247 |
| 283 // Automatically stops Bluetooth discovery a set amount of time after it was | 248 // Automatically stops Bluetooth discovery a set amount of time after it was |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 300 // copies verify they are also used on the UI thread. | 265 // copies verify they are also used on the UI thread. |
| 301 base::WeakPtr<BluetoothDispatcherHost> weak_ptr_on_ui_thread_; | 266 base::WeakPtr<BluetoothDispatcherHost> weak_ptr_on_ui_thread_; |
| 302 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; | 267 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; |
| 303 | 268 |
| 304 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); | 269 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); |
| 305 }; | 270 }; |
| 306 | 271 |
| 307 } // namespace content | 272 } // namespace content |
| 308 | 273 |
| 309 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ | 274 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ |
| OLD | NEW |