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> |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // Map to keep track of connections. Inserting and removing connections | 91 // Map to keep track of connections. Inserting and removing connections |
92 // will update the Web Contents for the frame. Upon destruction | 92 // will update the Web Contents for the frame. Upon destruction |
93 // the map will clear Web Contents of Bluetooth connections. | 93 // the map will clear Web Contents of Bluetooth connections. |
94 struct ConnectedDevicesMap { | 94 struct ConnectedDevicesMap { |
95 ConnectedDevicesMap(int render_process_id); | 95 ConnectedDevicesMap(int render_process_id); |
96 ~ConnectedDevicesMap(); | 96 ~ConnectedDevicesMap(); |
97 bool HasActiveConnection(const std::string& device_id); | 97 bool HasActiveConnection(const std::string& device_id); |
98 void InsertOrReplace( | 98 void InsertOrReplace( |
99 int frame_routing_id, | 99 int frame_routing_id, |
100 const std::string& device_id, | 100 const std::string& device_id, |
101 scoped_ptr<device::BluetoothGattConnection> connection); | 101 std::unique_ptr<device::BluetoothGattConnection> connection); |
102 void Remove(int frame_routing_id, const std::string& device_id); | 102 void Remove(int frame_routing_id, const std::string& device_id); |
103 void IncrementBluetoothConnectedDeviceCount(int frame_routing_id); | 103 void IncrementBluetoothConnectedDeviceCount(int frame_routing_id); |
104 void DecrementBluetoothConnectedDeviceCount(int frame_routing_id); | 104 void DecrementBluetoothConnectedDeviceCount(int frame_routing_id); |
105 | 105 |
106 int render_process_id_; | 106 int render_process_id_; |
107 std::unordered_map<std::string, scoped_ptr<device::BluetoothGattConnection>> | 107 std::unordered_map<std::string, |
| 108 std::unique_ptr<device::BluetoothGattConnection>> |
108 device_id_to_connection_map_; | 109 device_id_to_connection_map_; |
109 // Keeps track of which frame is connected to which device so that | 110 // Keeps track of which frame is connected to which device so that |
110 // we can clean up the WebContents in our destructor. | 111 // we can clean up the WebContents in our destructor. |
111 std::set<std::pair<int, std::string>> frame_ids_device_ids_; | 112 std::set<std::pair<int, std::string>> frame_ids_device_ids_; |
112 }; | 113 }; |
113 | 114 |
114 // Set |adapter_| to a BluetoothAdapter instance and register observers, | 115 // Set |adapter_| to a BluetoothAdapter instance and register observers, |
115 // releasing references to previous |adapter_|. | 116 // releasing references to previous |adapter_|. |
116 void set_adapter(scoped_refptr<device::BluetoothAdapter> adapter); | 117 void set_adapter(scoped_refptr<device::BluetoothAdapter> adapter); |
117 | 118 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 void OnRequestDeviceImpl( | 201 void OnRequestDeviceImpl( |
201 int thread_id, | 202 int thread_id, |
202 int request_id, | 203 int request_id, |
203 int frame_routing_id, | 204 int frame_routing_id, |
204 const std::vector<content::BluetoothScanFilter>& filters, | 205 const std::vector<content::BluetoothScanFilter>& filters, |
205 const std::vector<device::BluetoothUUID>& optional_services); | 206 const std::vector<device::BluetoothUUID>& optional_services); |
206 | 207 |
207 // Callbacks for BluetoothAdapter::StartDiscoverySession. | 208 // Callbacks for BluetoothAdapter::StartDiscoverySession. |
208 void OnDiscoverySessionStarted( | 209 void OnDiscoverySessionStarted( |
209 int chooser_id, | 210 int chooser_id, |
210 scoped_ptr<device::BluetoothDiscoverySession> discovery_session); | 211 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session); |
211 void OnDiscoverySessionStartedError(int chooser_id); | 212 void OnDiscoverySessionStartedError(int chooser_id); |
212 | 213 |
213 // BluetoothChooser::EventHandler: | 214 // BluetoothChooser::EventHandler: |
214 void OnBluetoothChooserEvent(int chooser_id, | 215 void OnBluetoothChooserEvent(int chooser_id, |
215 BluetoothChooser::Event event, | 216 BluetoothChooser::Event event, |
216 const std::string& device_id); | 217 const std::string& device_id); |
217 | 218 |
218 // The chooser implementation yields to the event loop to avoid re-entering | 219 // The chooser implementation yields to the event loop to avoid re-entering |
219 // code that's still using the RequestDeviceSession, and continues with this | 220 // code that's still using the RequestDeviceSession, and continues with this |
220 // function. | 221 // function. |
221 void FinishClosingChooser(int chooser_id, | 222 void FinishClosingChooser(int chooser_id, |
222 BluetoothChooser::Event event, | 223 BluetoothChooser::Event event, |
223 const std::string& device_id); | 224 const std::string& device_id); |
224 | 225 |
225 // Callbacks for BluetoothDevice::CreateGattConnection. | 226 // Callbacks for BluetoothDevice::CreateGattConnection. |
226 void OnGATTConnectionCreated( | 227 void OnGATTConnectionCreated( |
227 int thread_id, | 228 int thread_id, |
228 int request_id, | 229 int request_id, |
229 int frame_routing_id, | 230 int frame_routing_id, |
230 const std::string& device_id, | 231 const std::string& device_id, |
231 base::TimeTicks start_time, | 232 base::TimeTicks start_time, |
232 scoped_ptr<device::BluetoothGattConnection> connection); | 233 std::unique_ptr<device::BluetoothGattConnection> connection); |
233 void OnCreateGATTConnectionError( | 234 void OnCreateGATTConnectionError( |
234 int thread_id, | 235 int thread_id, |
235 int request_id, | 236 int request_id, |
236 const std::string& device_id, | 237 const std::string& device_id, |
237 base::TimeTicks start_time, | 238 base::TimeTicks start_time, |
238 device::BluetoothDevice::ConnectErrorCode error_code); | 239 device::BluetoothDevice::ConnectErrorCode error_code); |
239 | 240 |
240 // Adds the service to the map of services' instance ids to devices' instance | 241 // Adds the service to the map of services' instance ids to devices' instance |
241 // ids and sends the service to the renderer. | 242 // ids and sends the service to the renderer. |
242 void AddToServicesMapAndSendGetPrimaryServiceSuccess( | 243 void AddToServicesMapAndSendGetPrimaryServiceSuccess( |
243 const device::BluetoothGattService& service, | 244 const device::BluetoothGattService& service, |
244 int thread_id, | 245 int thread_id, |
245 int request_id); | 246 int request_id); |
246 | 247 |
247 // Callbacks for BluetoothGattCharacteristic::ReadRemoteCharacteristic. | 248 // Callbacks for BluetoothGattCharacteristic::ReadRemoteCharacteristic. |
248 void OnCharacteristicValueRead(int thread_id, | 249 void OnCharacteristicValueRead(int thread_id, |
249 int request_id, | 250 int request_id, |
250 const std::vector<uint8_t>& value); | 251 const std::vector<uint8_t>& value); |
251 void OnCharacteristicReadValueError( | 252 void OnCharacteristicReadValueError( |
252 int thread_id, | 253 int thread_id, |
253 int request_id, | 254 int request_id, |
254 device::BluetoothGattService::GattErrorCode); | 255 device::BluetoothGattService::GattErrorCode); |
255 | 256 |
256 // Callbacks for BluetoothGattCharacteristic::StartNotifySession. | 257 // Callbacks for BluetoothGattCharacteristic::StartNotifySession. |
257 void OnStartNotifySessionSuccess( | 258 void OnStartNotifySessionSuccess( |
258 int thread_id, | 259 int thread_id, |
259 int request_id, | 260 int request_id, |
260 scoped_ptr<device::BluetoothGattNotifySession> notify_session); | 261 std::unique_ptr<device::BluetoothGattNotifySession> notify_session); |
261 void OnStartNotifySessionFailed( | 262 void OnStartNotifySessionFailed( |
262 int thread_id, | 263 int thread_id, |
263 int request_id, | 264 int request_id, |
264 device::BluetoothGattService::GattErrorCode error_code); | 265 device::BluetoothGattService::GattErrorCode error_code); |
265 | 266 |
266 // Callback for BluetoothGattNotifySession::Stop. | 267 // Callback for BluetoothGattNotifySession::Stop. |
267 void OnStopNotifySession(int thread_id, | 268 void OnStopNotifySession(int thread_id, |
268 int request_id, | 269 int request_id, |
269 const std::string& characteristic_instance_id); | 270 const std::string& characteristic_instance_id); |
270 | 271 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 | 314 |
314 // Maps to get the object's parent based on it's instanceID | 315 // Maps to get the object's parent based on it's instanceID |
315 // Map of service_instance_id to device_address. | 316 // Map of service_instance_id to device_address. |
316 std::map<std::string, std::string> service_to_device_; | 317 std::map<std::string, std::string> service_to_device_; |
317 // Map of characteristic_instance_id to service_instance_id. | 318 // Map of characteristic_instance_id to service_instance_id. |
318 std::map<std::string, std::string> characteristic_to_service_; | 319 std::map<std::string, std::string> characteristic_to_service_; |
319 | 320 |
320 // Map that matches characteristic_instance_id to notify session. | 321 // Map that matches characteristic_instance_id to notify session. |
321 // TODO(ortuno): Also key by thread_id once support for web workers, | 322 // TODO(ortuno): Also key by thread_id once support for web workers, |
322 // is added: http://crbug.com/537372 | 323 // is added: http://crbug.com/537372 |
323 std::map<std::string, scoped_ptr<device::BluetoothGattNotifySession>> | 324 std::map<std::string, std::unique_ptr<device::BluetoothGattNotifySession>> |
324 characteristic_id_to_notify_session_; | 325 characteristic_id_to_notify_session_; |
325 | 326 |
326 // Map of characteristic_instance_id to a set of thread ids. | 327 // Map of characteristic_instance_id to a set of thread ids. |
327 // A thread_id in the set represents a BluetoothDispatcher that | 328 // A thread_id in the set represents a BluetoothDispatcher that |
328 // needs to be notified of changes to the characteristic. | 329 // needs to be notified of changes to the characteristic. |
329 std::map<std::string, std::set<int>> active_characteristic_threads_; | 330 std::map<std::string, std::set<int>> active_characteristic_threads_; |
330 | 331 |
331 // Defines how long to scan for and how long to discover services for. | 332 // Defines how long to scan for and how long to discover services for. |
332 int current_delay_time_; | 333 int current_delay_time_; |
333 | 334 |
334 // A BluetoothAdapter instance representing an adapter of the system. | 335 // A BluetoothAdapter instance representing an adapter of the system. |
335 scoped_refptr<device::BluetoothAdapter> adapter_; | 336 scoped_refptr<device::BluetoothAdapter> adapter_; |
336 | 337 |
337 // Automatically stops Bluetooth discovery a set amount of time after it was | 338 // Automatically stops Bluetooth discovery a set amount of time after it was |
338 // started. We have a single timer for all of Web Bluetooth because it's | 339 // started. We have a single timer for all of Web Bluetooth because it's |
339 // simpler than tracking timeouts for each RequestDeviceSession individually, | 340 // simpler than tracking timeouts for each RequestDeviceSession individually, |
340 // and because there's no harm in extending the length of a few discovery | 341 // and because there's no harm in extending the length of a few discovery |
341 // sessions when other sessions are active. | 342 // sessions when other sessions are active. |
342 base::Timer discovery_session_timer_; | 343 base::Timer discovery_session_timer_; |
343 | 344 |
344 // Retains BluetoothGattConnection objects to keep connections open. | 345 // Retains BluetoothGattConnection objects to keep connections open. |
345 scoped_ptr<ConnectedDevicesMap> connected_devices_map_; | 346 std::unique_ptr<ConnectedDevicesMap> connected_devices_map_; |
346 | 347 |
347 // Map of device_address's to primary-services requests that need responses | 348 // Map of device_address's to primary-services requests that need responses |
348 // when that device's service discovery completes. | 349 // when that device's service discovery completes. |
349 std::map<std::string, std::vector<PrimaryServicesRequest>> | 350 std::map<std::string, std::vector<PrimaryServicesRequest>> |
350 pending_primary_services_requests_; | 351 pending_primary_services_requests_; |
351 | 352 |
352 // |weak_ptr_on_ui_thread_| provides weak pointers, e.g. for callbacks, and | 353 // |weak_ptr_on_ui_thread_| provides weak pointers, e.g. for callbacks, and |
353 // because it exists and has been bound to the UI thread enforces that all | 354 // because it exists and has been bound to the UI thread enforces that all |
354 // copies verify they are also used on the UI thread. | 355 // copies verify they are also used on the UI thread. |
355 base::WeakPtr<BluetoothDispatcherHost> weak_ptr_on_ui_thread_; | 356 base::WeakPtr<BluetoothDispatcherHost> weak_ptr_on_ui_thread_; |
356 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; | 357 base::WeakPtrFactory<BluetoothDispatcherHost> weak_ptr_factory_; |
357 | 358 |
358 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); | 359 DISALLOW_COPY_AND_ASSIGN(BluetoothDispatcherHost); |
359 }; | 360 }; |
360 | 361 |
361 } // namespace content | 362 } // namespace content |
362 | 363 |
363 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ | 364 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DISPATCHER_HOST_H_ |
OLD | NEW |