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/public/browser/bluetooth_chooser.h" | 17 #include "content/public/browser/bluetooth_chooser.h" |
17 #include "content/public/browser/browser_message_filter.h" | 18 #include "content/public/browser/browser_message_filter.h" |
18 #include "device/bluetooth/bluetooth_adapter.h" | 19 #include "device/bluetooth/bluetooth_adapter.h" |
19 #include "device/bluetooth/bluetooth_gatt_connection.h" | 20 #include "device/bluetooth/bluetooth_gatt_connection.h" |
20 #include "device/bluetooth/bluetooth_gatt_notify_session.h" | 21 #include "device/bluetooth/bluetooth_gatt_notify_session.h" |
21 #include "device/bluetooth/bluetooth_gatt_service.h" | 22 #include "device/bluetooth/bluetooth_gatt_service.h" |
22 | 23 |
23 namespace device { | 24 namespace device { |
24 class BluetoothUUID; | 25 class BluetoothUUID; |
25 } | 26 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 98 |
98 // IPC Handlers, see definitions in bluetooth_messages.h. | 99 // IPC Handlers, see definitions in bluetooth_messages.h. |
99 void OnRequestDevice( | 100 void OnRequestDevice( |
100 int thread_id, | 101 int thread_id, |
101 int request_id, | 102 int request_id, |
102 int frame_routing_id, | 103 int frame_routing_id, |
103 const std::vector<content::BluetoothScanFilter>& filters, | 104 const std::vector<content::BluetoothScanFilter>& filters, |
104 const std::vector<device::BluetoothUUID>& optional_services); | 105 const std::vector<device::BluetoothUUID>& optional_services); |
105 void OnConnectGATT(int thread_id, | 106 void OnConnectGATT(int thread_id, |
106 int request_id, | 107 int request_id, |
| 108 int frame_routing_id, |
107 const std::string& device_id); | 109 const std::string& device_id); |
108 void OnGetPrimaryService(int thread_id, | 110 void OnGetPrimaryService(int thread_id, |
109 int request_id, | 111 int request_id, |
| 112 int frame_routing_id, |
110 const std::string& device_id, | 113 const std::string& device_id, |
111 const std::string& service_uuid); | 114 const std::string& service_uuid); |
112 void OnGetCharacteristic(int thread_id, | 115 void OnGetCharacteristic(int thread_id, |
113 int request_id, | 116 int request_id, |
| 117 int frame_routing_id, |
114 const std::string& service_instance_id, | 118 const std::string& service_instance_id, |
115 const std::string& characteristic_uuid); | 119 const std::string& characteristic_uuid); |
116 void OnReadValue(int thread_id, | 120 void OnReadValue(int thread_id, |
117 int request_id, | 121 int request_id, |
| 122 int frame_routing_id, |
118 const std::string& characteristic_instance_id); | 123 const std::string& characteristic_instance_id); |
119 void OnWriteValue(int thread_id, | 124 void OnWriteValue(int thread_id, |
120 int request_id, | 125 int request_id, |
| 126 int frame_routing_id, |
121 const std::string& characteristic_instance_id, | 127 const std::string& characteristic_instance_id, |
122 const std::vector<uint8_t>& value); | 128 const std::vector<uint8_t>& value); |
123 void OnStartNotifications(int thread_id, | 129 void OnStartNotifications(int thread_id, |
124 int request_id, | 130 int request_id, |
| 131 int frame_routing_id, |
125 const std::string& characteristic_instance_id); | 132 const std::string& characteristic_instance_id); |
126 void OnStopNotifications(int thread_id, | 133 void OnStopNotifications(int thread_id, |
127 int request_id, | 134 int request_id, |
| 135 int frame_routing_id, |
128 const std::string& characteristic_instance_id); | 136 const std::string& characteristic_instance_id); |
129 void OnRegisterCharacteristicObject( | 137 void OnRegisterCharacteristicObject( |
130 int thread_id, | 138 int thread_id, |
| 139 int frame_routing_id, |
131 const std::string& characteristic_instance_id); | 140 const std::string& characteristic_instance_id); |
132 void OnUnregisterCharacteristicObject( | 141 void OnUnregisterCharacteristicObject( |
133 int thread_id, | 142 int thread_id, |
| 143 int frame_routing_id, |
134 const std::string& characteristic_instance_id); | 144 const std::string& characteristic_instance_id); |
135 | 145 |
136 // Callbacks for BluetoothAdapter::StartDiscoverySession. | 146 // Callbacks for BluetoothAdapter::StartDiscoverySession. |
137 void OnDiscoverySessionStarted( | 147 void OnDiscoverySessionStarted( |
138 int chooser_id, | 148 int chooser_id, |
139 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); | 149 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); |
140 void OnDiscoverySessionStartedError(int chooser_id); | 150 void OnDiscoverySessionStartedError(int chooser_id); |
141 | 151 |
142 // BluetoothChooser::EventHandler: | 152 // BluetoothChooser::EventHandler: |
143 void OnBluetoothChooserEvent(int chooser_id, | 153 void OnBluetoothChooserEvent(int chooser_id, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 const std::string& characteristic_instance_id); | 213 const std::string& characteristic_instance_id); |
204 | 214 |
205 // Functions to query the platform cache for the bluetooth object. | 215 // Functions to query the platform cache for the bluetooth object. |
206 // result.outcome == CacheQueryOutcome::SUCCESS if the object was found in the | 216 // result.outcome == CacheQueryOutcome::SUCCESS if the object was found in the |
207 // cache. Otherwise result.outcome that can used to record the outcome and | 217 // cache. Otherwise result.outcome that can used to record the outcome and |
208 // result.error will contain the error that should be send to the renderer. | 218 // result.error will contain the error that should be send to the renderer. |
209 // One of the possible outcomes is BAD_RENDERER. In this case the outcome | 219 // One of the possible outcomes is BAD_RENDERER. In this case the outcome |
210 // was already recorded and since there renderer crashed there is no need to | 220 // was already recorded and since there renderer crashed there is no need to |
211 // send a response. | 221 // send a response. |
212 | 222 |
213 // Queries the platform cache for a Device with |device_id|. Fills in the | 223 // Queries the platform cache for a Device with |device_id| for |origin|. |
214 // |outcome| field and the |device| field if successful. | 224 // Fills in the |outcome| field and the |device| field if successful. |
215 CacheQueryResult QueryCacheForDevice(const std::string& device_id); | 225 CacheQueryResult QueryCacheForDevice(const url::Origin& origin, |
| 226 const std::string& device_id); |
216 // Queries the platform cache for a Service with |service_instance_id|. Fills | 227 // Queries the platform cache for a Service with |service_instance_id|. Fills |
217 // in the |outcome| field, and |device| and |service| fields if successful. | 228 // in the |outcome| field, and |device| and |service| fields if successful. |
218 CacheQueryResult QueryCacheForService(const std::string& service_instance_id); | 229 CacheQueryResult QueryCacheForService(const url::Origin& origin, |
| 230 const std::string& service_instance_id); |
219 // Queries the platform cache for a characteristic with | 231 // Queries the platform cache for a characteristic with |
220 // |characteristic_instance_id|. Fills in the |outcome| field, and |device|, | 232 // |characteristic_instance_id|. Fills in the |outcome| field, and |device|, |
221 // |service| and |characteristic| fields if successful. | 233 // |service| and |characteristic| fields if successful. |
222 CacheQueryResult QueryCacheForCharacteristic( | 234 CacheQueryResult QueryCacheForCharacteristic( |
| 235 const url::Origin& origin, |
223 const std::string& characteristic_instance_id); | 236 const std::string& characteristic_instance_id); |
224 | 237 |
225 // Adds the PrimaryServicesRequest to the vector of pending services requests | 238 // Adds the PrimaryServicesRequest to the vector of pending services requests |
226 // for that device. | 239 // for that device. |
227 void AddToPendingPrimaryServicesRequest( | 240 void AddToPendingPrimaryServicesRequest( |
228 const std::string& device_id, | 241 const std::string& device_address, |
229 const PrimaryServicesRequest& request); | 242 const PrimaryServicesRequest& request); |
230 | 243 |
| 244 // Returns the origin for the frame with "frame_routing_id" in |
| 245 // render_process_id_. |
| 246 url::Origin GetOrigin(int frame_routing_id); |
| 247 |
| 248 // Returns true if the frame has permission to access the characteristic |
| 249 // with |characteristic_instance_id|. |
| 250 bool CanFrameAccessCharacteristicInstance( |
| 251 int frame_routing_id, |
| 252 const std::string& characteristic_instance_id); |
| 253 |
231 // Show help pages from the chooser dialog. | 254 // Show help pages from the chooser dialog. |
232 void ShowBluetoothOverviewLink(); | 255 void ShowBluetoothOverviewLink(); |
233 void ShowBluetoothPairingLink(); | 256 void ShowBluetoothPairingLink(); |
234 void ShowBluetoothAdapterOffLink(); | 257 void ShowBluetoothAdapterOffLink(); |
235 void ShowNeedLocationLink(); | 258 void ShowNeedLocationLink(); |
236 | 259 |
237 int render_process_id_; | 260 int render_process_id_; |
238 | 261 |
239 // Maps a (thread_id,request_id) to information about its requestDevice call, | 262 // Maps a (thread_id,request_id) to information about its requestDevice call, |
240 // including the chooser dialog. | 263 // including the chooser dialog. |
241 // An entry is added to this map in OnRequestDevice, and should be removed | 264 // An entry is added to this map in OnRequestDevice, and should be removed |
242 // again everywhere a requestDevice() reply is sent. | 265 // again everywhere a requestDevice() reply is sent. |
243 IDMap<RequestDeviceSession, IDMapOwnPointer> request_device_sessions_; | 266 IDMap<RequestDeviceSession, IDMapOwnPointer> request_device_sessions_; |
244 | 267 |
| 268 BluetoothAllowedDevicesMap allowed_devices_map_; |
| 269 |
245 // Maps to get the object's parent based on it's instanceID | 270 // Maps to get the object's parent based on it's instanceID |
246 // Map of service_instance_id to device_id. | 271 // Map of service_instance_id to device_address. |
247 std::map<std::string, std::string> service_to_device_; | 272 std::map<std::string, std::string> service_to_device_; |
248 // Map of characteristic_instance_id to service_instance_id. | 273 // Map of characteristic_instance_id to service_instance_id. |
249 std::map<std::string, std::string> characteristic_to_service_; | 274 std::map<std::string, std::string> characteristic_to_service_; |
250 | 275 |
251 // Map that matches characteristic_instance_id to notify session. | 276 // Map that matches characteristic_instance_id to notify session. |
252 // TODO(ortuno): Also key by thread_id once support for web workers, | 277 // TODO(ortuno): Also key by thread_id once support for web workers, |
253 // is added: http://crbug.com/537372 | 278 // is added: http://crbug.com/537372 |
254 std::map<std::string, scoped_ptr<device::BluetoothGattNotifySession>> | 279 std::map<std::string, scoped_ptr<device::BluetoothGattNotifySession>> |
255 characteristic_id_to_notify_session_; | 280 characteristic_id_to_notify_session_; |
256 | 281 |
(...skipping 12 matching lines...) Expand all Loading... |
269 // started. We have a single timer for all of Web Bluetooth because it's | 294 // started. We have a single timer for all of Web Bluetooth because it's |
270 // simpler than tracking timeouts for each RequestDeviceSession individually, | 295 // simpler than tracking timeouts for each RequestDeviceSession individually, |
271 // and because there's no harm in extending the length of a few discovery | 296 // and because there's no harm in extending the length of a few discovery |
272 // sessions when other sessions are active. | 297 // sessions when other sessions are active. |
273 base::Timer discovery_session_timer_; | 298 base::Timer discovery_session_timer_; |
274 | 299 |
275 // Retain BluetoothGattConnection objects to keep connections open. | 300 // Retain BluetoothGattConnection objects to keep connections open. |
276 // TODO(scheib): Destroy as connections are closed. http://crbug.com/539643 | 301 // TODO(scheib): Destroy as connections are closed. http://crbug.com/539643 |
277 ScopedVector<device::BluetoothGattConnection> connections_; | 302 ScopedVector<device::BluetoothGattConnection> connections_; |
278 | 303 |
279 // Map of device_id's to primary-services requests that need responses when | 304 // Map of device_address's to primary-services requests that need responses |
280 // that device's service discovery completes. | 305 // when that device's service discovery completes. |
281 std::map<std::string, std::vector<PrimaryServicesRequest>> | 306 std::map<std::string, std::vector<PrimaryServicesRequest>> |
282 pending_primary_services_requests_; | 307 pending_primary_services_requests_; |
283 | 308 |
284 // |weak_ptr_on_ui_thread_| provides weak pointers, e.g. for callbacks, and | 309 // |weak_ptr_on_ui_thread_| provides weak pointers, e.g. for callbacks, and |
285 // because it exists and has been bound to the UI thread enforces that all | 310 // because it exists and has been bound to the UI thread enforces that all |
286 // copies verify they are also used on the UI thread. | 311 // copies verify they are also used on the UI thread. |
287 base::WeakPtr<BluetoothDispatcherHost> weak_ptr_on_ui_thread_; | 312 base::WeakPtr<BluetoothDispatcherHost> weak_ptr_on_ui_thread_; |
288 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; | 313 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; |
289 | 314 |
290 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); | 315 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); |
291 }; | 316 }; |
292 | 317 |
293 } // namespace content | 318 } // namespace content |
294 | 319 |
295 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ | 320 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ |
OLD | NEW |