| 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 <vector> | 10 #include <vector> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 namespace url { | 26 namespace url { |
| 27 class Origin; | 27 class Origin; |
| 28 } // namespace url | 28 } // namespace url |
| 29 | 29 |
| 30 namespace content { | 30 namespace content { |
| 31 | 31 |
| 32 class BluetoothDeviceChooserController; | 32 class BluetoothDeviceChooserController; |
| 33 struct CacheQueryResult; | 33 struct CacheQueryResult; |
| 34 class FrameConnectedBluetoothDevices; | 34 class FrameConnectedBluetoothDevices; |
| 35 struct GATTNotifySessionAndCharacteristicClient; |
| 35 class RenderFrameHost; | 36 class RenderFrameHost; |
| 36 class RenderProcessHost; | 37 class RenderProcessHost; |
| 37 | 38 |
| 38 // Implementation of Mojo WebBluetoothService located in | 39 // Implementation of Mojo WebBluetoothService located in |
| 39 // third_party/WebKit/public/platform/modules/bluetooth. | 40 // third_party/WebKit/public/platform/modules/bluetooth. |
| 40 // It handles Web Bluetooth API requests coming from Blink / renderer | 41 // It handles Web Bluetooth API requests coming from Blink / renderer |
| 41 // process and uses the platform abstraction of device/bluetooth. | 42 // process and uses the platform abstraction of device/bluetooth. |
| 42 // WebBluetoothServiceImpl is not thread-safe and should be created on the | 43 // WebBluetoothServiceImpl is not thread-safe and should be created on the |
| 43 // UI thread as required by device/bluetooth. | 44 // UI thread as required by device/bluetooth. |
| 44 // This class is instantiated on-demand via Mojo's ConnectToRemoteService | 45 // This class is instantiated on-demand via Mojo's ConnectToRemoteService |
| (...skipping 45 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, |
| 105 blink::mojom::WebBluetoothServerClientAssociatedPtrInfo client, |
| 106 const RemoteServerConnectCallback& callback) override; | 106 const RemoteServerConnectCallback& callback) override; |
| 107 void RemoteServerDisconnect(const WebBluetoothDeviceId& device_id) override; | 107 void RemoteServerDisconnect(const WebBluetoothDeviceId& device_id) override; |
| 108 void RemoteServerGetPrimaryServices( | 108 void RemoteServerGetPrimaryServices( |
| 109 const WebBluetoothDeviceId& device_id, | 109 const WebBluetoothDeviceId& device_id, |
| 110 blink::mojom::WebBluetoothGATTQueryQuantity quantity, | 110 blink::mojom::WebBluetoothGATTQueryQuantity quantity, |
| 111 const base::Optional<device::BluetoothUUID>& services_uuid, | 111 const base::Optional<device::BluetoothUUID>& services_uuid, |
| 112 const RemoteServerGetPrimaryServicesCallback& callback) override; | 112 const RemoteServerGetPrimaryServicesCallback& callback) override; |
| 113 void RemoteServiceGetCharacteristics( | 113 void RemoteServiceGetCharacteristics( |
| 114 const std::string& service_instance_id, | 114 const std::string& service_instance_id, |
| 115 blink::mojom::WebBluetoothGATTQueryQuantity quantity, | 115 blink::mojom::WebBluetoothGATTQueryQuantity quantity, |
| 116 const base::Optional<device::BluetoothUUID>& characteristics_uuid, | 116 const base::Optional<device::BluetoothUUID>& characteristics_uuid, |
| 117 const RemoteServiceGetCharacteristicsCallback& callback) override; | 117 const RemoteServiceGetCharacteristicsCallback& callback) override; |
| 118 void RemoteCharacteristicReadValue( | 118 void RemoteCharacteristicReadValue( |
| 119 const std::string& characteristic_instance_id, | 119 const std::string& characteristic_instance_id, |
| 120 const RemoteCharacteristicReadValueCallback& callback) override; | 120 const RemoteCharacteristicReadValueCallback& callback) override; |
| 121 void RemoteCharacteristicWriteValue( | 121 void RemoteCharacteristicWriteValue( |
| 122 const std::string& characteristic_instance_id, | 122 const std::string& characteristic_instance_id, |
| 123 const std::vector<uint8_t>& value, | 123 const std::vector<uint8_t>& value, |
| 124 const RemoteCharacteristicWriteValueCallback& callback) override; | 124 const RemoteCharacteristicWriteValueCallback& callback) override; |
| 125 void RemoteCharacteristicStartNotifications( | 125 void RemoteCharacteristicStartNotifications( |
| 126 const std::string& characteristic_instance_id, | 126 const std::string& characteristic_instance_id, |
| 127 blink::mojom::WebBluetoothCharacteristicClientAssociatedPtrInfo client, |
| 127 const RemoteCharacteristicStartNotificationsCallback& callback) override; | 128 const RemoteCharacteristicStartNotificationsCallback& callback) override; |
| 128 void RemoteCharacteristicStopNotifications( | 129 void RemoteCharacteristicStopNotifications( |
| 129 const std::string& characteristic_instance_id, | 130 const std::string& characteristic_instance_id, |
| 130 const RemoteCharacteristicStopNotificationsCallback& callback) override; | 131 const RemoteCharacteristicStopNotificationsCallback& callback) override; |
| 131 void RemoteCharacteristicGetDescriptors( | 132 void RemoteCharacteristicGetDescriptors( |
| 132 const std::string& service_instance_id, | 133 const std::string& service_instance_id, |
| 133 blink::mojom::WebBluetoothGATTQueryQuantity quantity, | 134 blink::mojom::WebBluetoothGATTQueryQuantity quantity, |
| 134 const base::Optional<device::BluetoothUUID>& characteristics_uuid, | 135 const base::Optional<device::BluetoothUUID>& characteristics_uuid, |
| 135 const RemoteCharacteristicGetDescriptorsCallback& callback) override; | 136 const RemoteCharacteristicGetDescriptorsCallback& callback) override; |
| 136 void RemoteDescriptorReadValue( | 137 void RemoteDescriptorReadValue( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 160 const RequestDeviceCallback& callback, | 161 const RequestDeviceCallback& callback, |
| 161 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, | 162 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, |
| 162 const std::string& device_id); | 163 const std::string& device_id); |
| 163 void OnGetDeviceFailed(const RequestDeviceCallback& callback, | 164 void OnGetDeviceFailed(const RequestDeviceCallback& callback, |
| 164 blink::mojom::WebBluetoothResult result); | 165 blink::mojom::WebBluetoothResult result); |
| 165 | 166 |
| 166 // Callbacks for BluetoothDevice::CreateGattConnection. | 167 // Callbacks for BluetoothDevice::CreateGattConnection. |
| 167 void OnCreateGATTConnectionSuccess( | 168 void OnCreateGATTConnectionSuccess( |
| 168 const WebBluetoothDeviceId& device_id, | 169 const WebBluetoothDeviceId& device_id, |
| 169 base::TimeTicks start_time, | 170 base::TimeTicks start_time, |
| 171 blink::mojom::WebBluetoothServerClientAssociatedPtr client, |
| 170 const RemoteServerConnectCallback& callback, | 172 const RemoteServerConnectCallback& callback, |
| 171 std::unique_ptr<device::BluetoothGattConnection> connection); | 173 std::unique_ptr<device::BluetoothGattConnection> connection); |
| 172 void OnCreateGATTConnectionFailed( | 174 void OnCreateGATTConnectionFailed( |
| 173 base::TimeTicks start_time, | 175 base::TimeTicks start_time, |
| 174 const RemoteServerConnectCallback& callback, | 176 const RemoteServerConnectCallback& callback, |
| 175 device::BluetoothDevice::ConnectErrorCode error_code); | 177 device::BluetoothDevice::ConnectErrorCode error_code); |
| 176 | 178 |
| 177 // Callbacks for BluetoothRemoteGattCharacteristic::ReadRemoteCharacteristic. | 179 // Callbacks for BluetoothRemoteGattCharacteristic::ReadRemoteCharacteristic. |
| 178 void OnCharacteristicReadValueSuccess( | 180 void OnCharacteristicReadValueSuccess( |
| 179 const RemoteCharacteristicReadValueCallback& callback, | 181 const RemoteCharacteristicReadValueCallback& callback, |
| 180 const std::vector<uint8_t>& value); | 182 const std::vector<uint8_t>& value); |
| 181 void OnCharacteristicReadValueFailed( | 183 void OnCharacteristicReadValueFailed( |
| 182 const RemoteCharacteristicReadValueCallback& callback, | 184 const RemoteCharacteristicReadValueCallback& callback, |
| 183 device::BluetoothRemoteGattService::GattErrorCode error_code); | 185 device::BluetoothRemoteGattService::GattErrorCode error_code); |
| 184 | 186 |
| 185 // Callbacks for BluetoothRemoteGattCharacteristic::WriteRemoteCharacteristic. | 187 // Callbacks for BluetoothRemoteGattCharacteristic::WriteRemoteCharacteristic. |
| 186 void OnCharacteristicWriteValueSuccess( | 188 void OnCharacteristicWriteValueSuccess( |
| 187 const RemoteCharacteristicWriteValueCallback& callback); | 189 const RemoteCharacteristicWriteValueCallback& callback); |
| 188 void OnCharacteristicWriteValueFailed( | 190 void OnCharacteristicWriteValueFailed( |
| 189 const RemoteCharacteristicWriteValueCallback& callback, | 191 const RemoteCharacteristicWriteValueCallback& callback, |
| 190 device::BluetoothRemoteGattService::GattErrorCode error_code); | 192 device::BluetoothRemoteGattService::GattErrorCode error_code); |
| 191 | 193 |
| 192 // Callbacks for BluetoothRemoteGattCharacteristic::StartNotifySession. | 194 // Callbacks for BluetoothRemoteGattCharacteristic::StartNotifySession. |
| 193 void OnStartNotifySessionSuccess( | 195 void OnStartNotifySessionSuccess( |
| 196 blink::mojom::WebBluetoothCharacteristicClientAssociatedPtr client, |
| 194 const RemoteCharacteristicStartNotificationsCallback& callback, | 197 const RemoteCharacteristicStartNotificationsCallback& callback, |
| 195 std::unique_ptr<device::BluetoothGattNotifySession> notify_session); | 198 std::unique_ptr<device::BluetoothGattNotifySession> notify_session); |
| 196 void OnStartNotifySessionFailed( | 199 void OnStartNotifySessionFailed( |
| 197 const RemoteCharacteristicStartNotificationsCallback& callback, | 200 const RemoteCharacteristicStartNotificationsCallback& callback, |
| 198 device::BluetoothRemoteGattService::GattErrorCode error_code); | 201 device::BluetoothRemoteGattService::GattErrorCode error_code); |
| 199 | 202 |
| 200 // Callback for BluetoothGattNotifySession::Stop. | 203 // Callback for BluetoothGattNotifySession::Stop. |
| 201 void OnStopNotifySessionComplete( | 204 void OnStopNotifySessionComplete( |
| 202 const std::string& characteristic_instance_id, | 205 const std::string& characteristic_instance_id, |
| 203 const RemoteCharacteristicStopNotificationsCallback& callback); | 206 const RemoteCharacteristicStopNotificationsCallback& callback); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 // Map to keep track of the connected Bluetooth devices. | 268 // Map to keep track of the connected Bluetooth devices. |
| 266 std::unique_ptr<FrameConnectedBluetoothDevices> connected_devices_; | 269 std::unique_ptr<FrameConnectedBluetoothDevices> connected_devices_; |
| 267 | 270 |
| 268 // Maps a device address to callbacks that are waiting for services to | 271 // Maps a device address to callbacks that are waiting for services to |
| 269 // be discovered for that device. | 272 // be discovered for that device. |
| 270 std::unordered_map<std::string, std::vector<PrimaryServicesRequestCallback>> | 273 std::unordered_map<std::string, std::vector<PrimaryServicesRequestCallback>> |
| 271 pending_primary_services_requests_; | 274 pending_primary_services_requests_; |
| 272 | 275 |
| 273 // Map to keep track of the characteristics' notify sessions. | 276 // Map to keep track of the characteristics' notify sessions. |
| 274 std::unordered_map<std::string, | 277 std::unordered_map<std::string, |
| 275 std::unique_ptr<device::BluetoothGattNotifySession>> | 278 std::unique_ptr<GATTNotifySessionAndCharacteristicClient>> |
| 276 characteristic_id_to_notify_session_; | 279 characteristic_id_to_notify_session_; |
| 277 | 280 |
| 278 // The RFH that owns this instance. | 281 // The RFH that owns this instance. |
| 279 RenderFrameHost* render_frame_host_; | 282 RenderFrameHost* render_frame_host_; |
| 280 | 283 |
| 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 | 284 // 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 | 285 // owns it so we use a "Binding" as opposed to a "StrongBinding" which deletes |
| 286 // the service on pipe connection errors. | 286 // the service on pipe connection errors. |
| 287 mojo::Binding<blink::mojom::WebBluetoothService> binding_; | 287 mojo::Binding<blink::mojom::WebBluetoothService> binding_; |
| 288 | 288 |
| 289 base::WeakPtrFactory<WebBluetoothServiceImpl> weak_ptr_factory_; | 289 base::WeakPtrFactory<WebBluetoothServiceImpl> weak_ptr_factory_; |
| 290 | 290 |
| 291 DISALLOW_COPY_AND_ASSIGN(WebBluetoothServiceImpl); | 291 DISALLOW_COPY_AND_ASSIGN(WebBluetoothServiceImpl); |
| 292 }; | 292 }; |
| 293 | 293 |
| 294 } // namespace content | 294 } // namespace content |
| 295 | 295 |
| 296 #endif // CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ | 296 #endif // CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ |
| OLD | NEW |