Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: content/browser/bluetooth/web_bluetooth_service_impl.h

Issue 2466223002: Implement WebBluetooth getDescriptor[s] (Closed)
Patch Set: Ensure that we throw a kGattServerNotConnected error if getDescriptor[s] is called while not connec… Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 device::BluetoothRemoteGattCharacteristic* characteristic, 89 device::BluetoothRemoteGattCharacteristic* characteristic,
90 const std::vector<uint8_t>& value) override; 90 const std::vector<uint8_t>& value) override;
91 91
92 // Notifies the WebBluetoothServiceClient that characteristic 92 // Notifies the WebBluetoothServiceClient that characteristic
93 // |characteristic_instance_id| changed it's value. We only do this for 93 // |characteristic_instance_id| changed it's value. We only do this for
94 // characteristics that have been returned to the client in the past. 94 // characteristics that have been returned to the client in the past.
95 void NotifyCharacteristicValueChanged( 95 void NotifyCharacteristicValueChanged(
96 const std::string& characteristic_instance_id, 96 const std::string& characteristic_instance_id,
97 std::vector<uint8_t> value); 97 std::vector<uint8_t> value);
98 98
99 void GattDescriptorValueChanged(
ortuno 2016/11/21 03:34:08 per comment in web_bluetooth.mojom, we don't need
dougt 2016/11/22 01:47:16 Acknowledged.
100 device::BluetoothAdapter* adapter,
101 device::BluetoothRemoteGattDescriptor* descriptor,
102 const std::vector<uint8_t>& value) override;
103
104 // Notifies the WebBluetoothServiceClient that descriptor
105 // |descriptor_instance_id| changed it's value. We only do this for
106 // descriptors that have been returned to the client in the past.
107 void NotifyDescriptorValueChanged(const std::string& descriptor_instance_id,
108 std::vector<uint8_t> value);
109
99 // WebBluetoothService methods: 110 // WebBluetoothService methods:
100 void SetClient( 111 void SetClient(
101 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo client) override; 112 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo client) override;
102 void RequestDevice(blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, 113 void RequestDevice(blink::mojom::WebBluetoothRequestDeviceOptionsPtr options,
103 const RequestDeviceCallback& callback) override; 114 const RequestDeviceCallback& callback) override;
104 void RemoteServerConnect( 115 void RemoteServerConnect(
105 const WebBluetoothDeviceId& device_id, 116 const WebBluetoothDeviceId& device_id,
106 const RemoteServerConnectCallback& callback) override; 117 const RemoteServerConnectCallback& callback) override;
107 void RemoteServerDisconnect(const WebBluetoothDeviceId& device_id) override; 118 void RemoteServerDisconnect(const WebBluetoothDeviceId& device_id) override;
108 void RemoteServerGetPrimaryServices( 119 void RemoteServerGetPrimaryServices(
(...skipping 12 matching lines...) Expand all
121 void RemoteCharacteristicWriteValue( 132 void RemoteCharacteristicWriteValue(
122 const mojo::String& characteristic_instance_id, 133 const mojo::String& characteristic_instance_id,
123 mojo::Array<uint8_t> value, 134 mojo::Array<uint8_t> value,
124 const RemoteCharacteristicWriteValueCallback& callback) override; 135 const RemoteCharacteristicWriteValueCallback& callback) override;
125 void RemoteCharacteristicStartNotifications( 136 void RemoteCharacteristicStartNotifications(
126 const mojo::String& characteristic_instance_id, 137 const mojo::String& characteristic_instance_id,
127 const RemoteCharacteristicStartNotificationsCallback& callback) override; 138 const RemoteCharacteristicStartNotificationsCallback& callback) override;
128 void RemoteCharacteristicStopNotifications( 139 void RemoteCharacteristicStopNotifications(
129 const mojo::String& characteristic_instance_id, 140 const mojo::String& characteristic_instance_id,
130 const RemoteCharacteristicStopNotificationsCallback& callback) override; 141 const RemoteCharacteristicStopNotificationsCallback& callback) override;
142 void RemoteCharacteristicGetDescriptors(
143 const mojo::String& service_instance_id,
144 blink::mojom::WebBluetoothGATTQueryQuantity quantity,
145 const base::Optional<device::BluetoothUUID>& characteristics_uuid,
146 const RemoteCharacteristicGetDescriptorsCallback& callback) override;
147 void RemoteDescriptorReadValue(
148 const mojo::String& descriptor_instance_id,
149 const RemoteDescriptorReadValueCallback& callback) override;
150 void RemoteDescriptorWriteValue(
151 const mojo::String& descriptor_instance_id,
152 mojo::Array<uint8_t> value,
153 const RemoteDescriptorWriteValueCallback& callback) override;
154
155 // Callbacks for BluetoothRemoteGattDescriptor::ReadRemoteDescriptor.
ortuno 2016/11/21 03:34:08 Move these down with the rest of the callbacks.
dougt 2016/11/22 01:47:16 Acknowledged.
156 void OnDescriptorReadValueSuccess(
157 const RemoteDescriptorReadValueCallback& callback,
158 const std::vector<uint8_t>& value);
159 void OnDescriptorReadValueFailed(
160 const RemoteDescriptorReadValueCallback& callback,
161 device::BluetoothRemoteGattService::GattErrorCode error_code);
162
163 // Callbacks for BluetoothRemoteGattDescriptor::WriteRemoteDescriptor.
164 void OnDescriptorWriteValueSuccess(
165 const RemoteDescriptorWriteValueCallback& callback);
166 void OnDescriptorWriteValueFailed(
167 const RemoteDescriptorWriteValueCallback& callback,
168 device::BluetoothRemoteGattService::GattErrorCode error_code);
131 169
132 void RequestDeviceImpl( 170 void RequestDeviceImpl(
133 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, 171 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options,
134 const RequestDeviceCallback& callback, 172 const RequestDeviceCallback& callback,
135 device::BluetoothAdapter* adapter); 173 device::BluetoothAdapter* adapter);
136 174
137 // Should only be run after the services have been discovered for 175 // Should only be run after the services have been discovered for
138 // |device_address|. 176 // |device_address|.
139 void RemoteServerGetPrimaryServicesImpl( 177 void RemoteServerGetPrimaryServicesImpl(
140 const WebBluetoothDeviceId& device_id, 178 const WebBluetoothDeviceId& device_id,
(...skipping 15 matching lines...) Expand all
156 const WebBluetoothDeviceId& device_id, 194 const WebBluetoothDeviceId& device_id,
157 base::TimeTicks start_time, 195 base::TimeTicks start_time,
158 const RemoteServerConnectCallback& callback, 196 const RemoteServerConnectCallback& callback,
159 std::unique_ptr<device::BluetoothGattConnection> connection); 197 std::unique_ptr<device::BluetoothGattConnection> connection);
160 void OnCreateGATTConnectionFailed( 198 void OnCreateGATTConnectionFailed(
161 base::TimeTicks start_time, 199 base::TimeTicks start_time,
162 const RemoteServerConnectCallback& callback, 200 const RemoteServerConnectCallback& callback,
163 device::BluetoothDevice::ConnectErrorCode error_code); 201 device::BluetoothDevice::ConnectErrorCode error_code);
164 202
165 // Callbacks for BluetoothRemoteGattCharacteristic::ReadRemoteCharacteristic. 203 // Callbacks for BluetoothRemoteGattCharacteristic::ReadRemoteCharacteristic.
166 void OnReadValueSuccess(const RemoteCharacteristicReadValueCallback& callback, 204 void OnCharacteristicReadValueSuccess(
167 const std::vector<uint8_t>& value); 205 const RemoteCharacteristicReadValueCallback& callback,
168 void OnReadValueFailed( 206 const std::vector<uint8_t>& value);
207 void OnCharacteristicReadValueFailed(
169 const RemoteCharacteristicReadValueCallback& callback, 208 const RemoteCharacteristicReadValueCallback& callback,
170 device::BluetoothRemoteGattService::GattErrorCode error_code); 209 device::BluetoothRemoteGattService::GattErrorCode error_code);
171 210
172 // Callbacks for BluetoothRemoteGattCharacteristic::WriteRemoteCharacteristic. 211 // Callbacks for BluetoothRemoteGattCharacteristic::WriteRemoteCharacteristic.
173 void OnWriteValueSuccess( 212 void OnCharacteristicWriteValueSuccess(
174 const RemoteCharacteristicWriteValueCallback& callback); 213 const RemoteCharacteristicWriteValueCallback& callback);
175 void OnWriteValueFailed( 214 void OnCharacteristicWriteValueFailed(
176 const RemoteCharacteristicWriteValueCallback& callback, 215 const RemoteCharacteristicWriteValueCallback& callback,
177 device::BluetoothRemoteGattService::GattErrorCode error_code); 216 device::BluetoothRemoteGattService::GattErrorCode error_code);
178 217
179 // Callbacks for BluetoothRemoteGattCharacteristic::StartNotifySession. 218 // Callbacks for BluetoothRemoteGattCharacteristic::StartNotifySession.
180 void OnStartNotifySessionSuccess( 219 void OnStartNotifySessionSuccess(
181 const RemoteCharacteristicStartNotificationsCallback& callback, 220 const RemoteCharacteristicStartNotificationsCallback& callback,
182 std::unique_ptr<device::BluetoothGattNotifySession> notify_session); 221 std::unique_ptr<device::BluetoothGattNotifySession> notify_session);
183 void OnStartNotifySessionFailed( 222 void OnStartNotifySessionFailed(
184 const RemoteCharacteristicStartNotificationsCallback& callback, 223 const RemoteCharacteristicStartNotificationsCallback& callback,
185 device::BluetoothRemoteGattService::GattErrorCode error_code); 224 device::BluetoothRemoteGattService::GattErrorCode error_code);
(...skipping 18 matching lines...) Expand all
204 // Queries the platform cache for a Service with |service_instance_id|. Fills 243 // Queries the platform cache for a Service with |service_instance_id|. Fills
205 // in the |outcome| field, and |device| and |service| fields if successful. 244 // in the |outcome| field, and |device| and |service| fields if successful.
206 CacheQueryResult QueryCacheForService(const std::string& service_instance_id); 245 CacheQueryResult QueryCacheForService(const std::string& service_instance_id);
207 246
208 // Queries the platform cache for a characteristic with 247 // Queries the platform cache for a characteristic with
209 // |characteristic_instance_id|. Fills in the |outcome| field, and |device|, 248 // |characteristic_instance_id|. Fills in the |outcome| field, and |device|,
210 // |service| and |characteristic| fields if successful. 249 // |service| and |characteristic| fields if successful.
211 CacheQueryResult QueryCacheForCharacteristic( 250 CacheQueryResult QueryCacheForCharacteristic(
212 const std::string& characteristic_instance_id); 251 const std::string& characteristic_instance_id);
213 252
253 // Queries the platform cache for a descriptor with
254 // |descriptor_instance_id|. Fills in the |outcome| field, and |device|,
255 // |service| and |descriptor| fields if successful.
ortuno 2016/11/21 03:34:08 |service|, |characteristic|, and |descriptor|
dougt 2016/11/22 01:47:16 Acknowledged.
256 CacheQueryResult QueryCacheForDescriptor(
257 const std::string& descriptor_instance_id);
258
214 RenderProcessHost* GetRenderProcessHost(); 259 RenderProcessHost* GetRenderProcessHost();
215 device::BluetoothAdapter* GetAdapter(); 260 device::BluetoothAdapter* GetAdapter();
216 url::Origin GetOrigin(); 261 url::Origin GetOrigin();
217 262
218 // Clears all state (maps, sets, etc). 263 // Clears all state (maps, sets, etc).
219 void ClearState(); 264 void ClearState();
220 265
221 // Used to open a BluetoothChooser and start a device discovery session. 266 // Used to open a BluetoothChooser and start a device discovery session.
222 std::unique_ptr<BluetoothDeviceChooserController> device_chooser_controller_; 267 std::unique_ptr<BluetoothDeviceChooserController> device_chooser_controller_;
223 268
224 // Keeps track of which devices the frame's origin is allowed to access. 269 // Keeps track of which devices the frame's origin is allowed to access.
225 BluetoothAllowedDevicesMap allowed_devices_map_; 270 BluetoothAllowedDevicesMap allowed_devices_map_;
226 271
227 // Maps to get the object's parent based on its instanceID. 272 // Maps to get the object's parent based on its instanceID.
228 std::unordered_map<std::string, std::string> service_id_to_device_address_; 273 std::unordered_map<std::string, std::string> service_id_to_device_address_;
229 std::unordered_map<std::string, std::string> characteristic_id_to_service_id_; 274 std::unordered_map<std::string, std::string> characteristic_id_to_service_id_;
275 std::unordered_map<std::string, std::string>
276 descriptor_id_to_characteristic_id_;
230 277
231 // Map to keep track of the connected Bluetooth devices. 278 // Map to keep track of the connected Bluetooth devices.
232 std::unique_ptr<FrameConnectedBluetoothDevices> connected_devices_; 279 std::unique_ptr<FrameConnectedBluetoothDevices> connected_devices_;
233 280
234 // Maps a device address to callbacks that are waiting for services to 281 // Maps a device address to callbacks that are waiting for services to
235 // be discovered for that device. 282 // be discovered for that device.
236 std::unordered_map<std::string, std::vector<PrimaryServicesRequestCallback>> 283 std::unordered_map<std::string, std::vector<PrimaryServicesRequestCallback>>
237 pending_primary_services_requests_; 284 pending_primary_services_requests_;
238 285
239 // Map to keep track of the characteristics' notify sessions. 286 // Map to keep track of the characteristics' notify sessions.
(...skipping 13 matching lines...) Expand all
253 mojo::Binding<blink::mojom::WebBluetoothService> binding_; 300 mojo::Binding<blink::mojom::WebBluetoothService> binding_;
254 301
255 base::WeakPtrFactory<WebBluetoothServiceImpl> weak_ptr_factory_; 302 base::WeakPtrFactory<WebBluetoothServiceImpl> weak_ptr_factory_;
256 303
257 DISALLOW_COPY_AND_ASSIGN(WebBluetoothServiceImpl); 304 DISALLOW_COPY_AND_ASSIGN(WebBluetoothServiceImpl);
258 }; 305 };
259 306
260 } // namespace content 307 } // namespace content
261 308
262 #endif // CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ 309 #endif // CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698