OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_WEB_BLUETOOTH_SERVICE_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ |
6 #define CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ | 6 #define CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
| 10 #include <utility> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/optional.h" | 14 #include "base/optional.h" |
14 #include "content/browser/bad_message.h" | 15 #include "content/browser/bad_message.h" |
15 #include "content/browser/bluetooth/bluetooth_allowed_devices.h" | 16 #include "content/browser/bluetooth/bluetooth_allowed_devices.h" |
16 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
17 #include "content/public/browser/web_contents_observer.h" | 18 #include "content/public/browser/web_contents_observer.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" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 const std::vector<uint8_t>& value) override; | 91 const std::vector<uint8_t>& value) override; |
91 | 92 |
92 // Notifies the WebBluetoothServiceClient that characteristic | 93 // Notifies the WebBluetoothServiceClient that characteristic |
93 // |characteristic_instance_id| changed it's value. We only do this for | 94 // |characteristic_instance_id| changed it's value. We only do this for |
94 // characteristics that have been returned to the client in the past. | 95 // characteristics that have been returned to the client in the past. |
95 void NotifyCharacteristicValueChanged( | 96 void NotifyCharacteristicValueChanged( |
96 const std::string& characteristic_instance_id, | 97 const std::string& characteristic_instance_id, |
97 const std::vector<uint8_t>& value); | 98 const std::vector<uint8_t>& value); |
98 | 99 |
99 // WebBluetoothService methods: | 100 // WebBluetoothService methods: |
100 void SetClient( | |
101 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo client) override; | |
102 void RequestDevice(blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, | 101 void RequestDevice(blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, |
103 const RequestDeviceCallback& callback) override; | 102 const RequestDeviceCallback& callback) override; |
104 void RemoteServerConnect( | 103 void RemoteServerConnect( |
105 const WebBluetoothDeviceId& device_id, | 104 const WebBluetoothDeviceId& device_id, |
106 const RemoteServerConnectCallback& callback) override; | 105 const RemoteServerConnectCallback& callback) override; |
107 void RemoteServerDisconnect(const WebBluetoothDeviceId& device_id) override; | 106 void RemoteServerDisconnect(const WebBluetoothDeviceId& device_id) override; |
108 void RemoteServerGetPrimaryServices( | 107 void RemoteServerGetPrimaryServices( |
109 const WebBluetoothDeviceId& device_id, | 108 const WebBluetoothDeviceId& device_id, |
110 blink::mojom::WebBluetoothGATTQueryQuantity quantity, | 109 blink::mojom::WebBluetoothGATTQueryQuantity quantity, |
111 const base::Optional<device::BluetoothUUID>& services_uuid, | 110 const base::Optional<device::BluetoothUUID>& services_uuid, |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 | 263 |
265 // Map to keep track of the connected Bluetooth devices. | 264 // Map to keep track of the connected Bluetooth devices. |
266 std::unique_ptr<FrameConnectedBluetoothDevices> connected_devices_; | 265 std::unique_ptr<FrameConnectedBluetoothDevices> connected_devices_; |
267 | 266 |
268 // Maps a device address to callbacks that are waiting for services to | 267 // Maps a device address to callbacks that are waiting for services to |
269 // be discovered for that device. | 268 // be discovered for that device. |
270 std::unordered_map<std::string, std::vector<PrimaryServicesRequestCallback>> | 269 std::unordered_map<std::string, std::vector<PrimaryServicesRequestCallback>> |
271 pending_primary_services_requests_; | 270 pending_primary_services_requests_; |
272 | 271 |
273 // Map to keep track of the characteristics' notify sessions. | 272 // Map to keep track of the characteristics' notify sessions. |
274 std::unordered_map<std::string, | 273 std::unordered_map< |
275 std::unique_ptr<device::BluetoothGattNotifySession>> | 274 std::string, |
| 275 std::pair<std::unique_ptr<device::BluetoothGattNotifySession>, |
| 276 blink::mojom::WebBluetoothCharacteristicClientAssociatedPtr>> |
276 characteristic_id_to_notify_session_; | 277 characteristic_id_to_notify_session_; |
277 | 278 |
278 // The RFH that owns this instance. | 279 // The RFH that owns this instance. |
279 RenderFrameHost* render_frame_host_; | 280 RenderFrameHost* render_frame_host_; |
280 | 281 |
281 // Proxy to the WebBluetoothServiceClient to send device events to. | |
282 blink::mojom::WebBluetoothServiceClientAssociatedPtr client_; | |
283 | |
284 // The lifetime of this instance is exclusively managed by the RFH that | 282 // The lifetime of this instance is exclusively managed by the RFH that |
285 // owns it so we use a "Binding" as opposed to a "StrongBinding" which deletes | 283 // owns it so we use a "Binding" as opposed to a "StrongBinding" which deletes |
286 // the service on pipe connection errors. | 284 // the service on pipe connection errors. |
287 mojo::Binding<blink::mojom::WebBluetoothService> binding_; | 285 mojo::Binding<blink::mojom::WebBluetoothService> binding_; |
288 | 286 |
289 base::WeakPtrFactory<WebBluetoothServiceImpl> weak_ptr_factory_; | 287 base::WeakPtrFactory<WebBluetoothServiceImpl> weak_ptr_factory_; |
290 | 288 |
291 DISALLOW_COPY_AND_ASSIGN(WebBluetoothServiceImpl); | 289 DISALLOW_COPY_AND_ASSIGN(WebBluetoothServiceImpl); |
292 }; | 290 }; |
293 | 291 |
294 } // namespace content | 292 } // namespace content |
295 | 293 |
296 #endif // CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ | 294 #endif // CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ |
OLD | NEW |