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

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

Issue 2466223002: Implement WebBluetooth getDescriptor[s] (Closed)
Patch Set: Rebase Created 4 years 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 const RemoteCharacteristicStartNotificationsCallback& callback) override; 127 const RemoteCharacteristicStartNotificationsCallback& callback) override;
128 void RemoteCharacteristicStopNotifications( 128 void RemoteCharacteristicStopNotifications(
129 const std::string& characteristic_instance_id, 129 const std::string& characteristic_instance_id,
130 const RemoteCharacteristicStopNotificationsCallback& callback) override; 130 const RemoteCharacteristicStopNotificationsCallback& callback) override;
131 void RemoteCharacteristicGetDescriptors(
132 const std::string& service_instance_id,
133 blink::mojom::WebBluetoothGATTQueryQuantity quantity,
134 const base::Optional<device::BluetoothUUID>& characteristics_uuid,
135 const RemoteCharacteristicGetDescriptorsCallback& callback) override;
136 void RemoteDescriptorReadValue(
ortuno 2016/12/02 06:14:50 No need for RemoteDescriptorReadValue/WriteValue s
dougt 2016/12/02 18:31:28 Done.
137 const std::string& descriptor_instance_id,
138 const RemoteDescriptorReadValueCallback& callback) override;
139 void RemoteDescriptorWriteValue(
140 const std::string& descriptor_instance_id,
141 const std::vector<uint8_t>& value,
142 const RemoteDescriptorWriteValueCallback& callback) override;
131 143
132 void RequestDeviceImpl( 144 void RequestDeviceImpl(
133 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, 145 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options,
134 const RequestDeviceCallback& callback, 146 const RequestDeviceCallback& callback,
135 device::BluetoothAdapter* adapter); 147 device::BluetoothAdapter* adapter);
136 148
137 // Should only be run after the services have been discovered for 149 // Should only be run after the services have been discovered for
138 // |device_address|. 150 // |device_address|.
139 void RemoteServerGetPrimaryServicesImpl( 151 void RemoteServerGetPrimaryServicesImpl(
140 const WebBluetoothDeviceId& device_id, 152 const WebBluetoothDeviceId& device_id,
(...skipping 15 matching lines...) Expand all
156 const WebBluetoothDeviceId& device_id, 168 const WebBluetoothDeviceId& device_id,
157 base::TimeTicks start_time, 169 base::TimeTicks start_time,
158 const RemoteServerConnectCallback& callback, 170 const RemoteServerConnectCallback& callback,
159 std::unique_ptr<device::BluetoothGattConnection> connection); 171 std::unique_ptr<device::BluetoothGattConnection> connection);
160 void OnCreateGATTConnectionFailed( 172 void OnCreateGATTConnectionFailed(
161 base::TimeTicks start_time, 173 base::TimeTicks start_time,
162 const RemoteServerConnectCallback& callback, 174 const RemoteServerConnectCallback& callback,
163 device::BluetoothDevice::ConnectErrorCode error_code); 175 device::BluetoothDevice::ConnectErrorCode error_code);
164 176
165 // Callbacks for BluetoothRemoteGattCharacteristic::ReadRemoteCharacteristic. 177 // Callbacks for BluetoothRemoteGattCharacteristic::ReadRemoteCharacteristic.
166 void OnReadValueSuccess(const RemoteCharacteristicReadValueCallback& callback, 178 void OnCharacteristicReadValueSuccess(
167 const std::vector<uint8_t>& value); 179 const RemoteCharacteristicReadValueCallback& callback,
168 void OnReadValueFailed( 180 const std::vector<uint8_t>& value);
181 void OnCharacteristicReadValueFailed(
169 const RemoteCharacteristicReadValueCallback& callback, 182 const RemoteCharacteristicReadValueCallback& callback,
170 device::BluetoothRemoteGattService::GattErrorCode error_code); 183 device::BluetoothRemoteGattService::GattErrorCode error_code);
171 184
172 // Callbacks for BluetoothRemoteGattCharacteristic::WriteRemoteCharacteristic. 185 // Callbacks for BluetoothRemoteGattCharacteristic::WriteRemoteCharacteristic.
173 void OnWriteValueSuccess( 186 void OnCharacteristicWriteValueSuccess(
174 const RemoteCharacteristicWriteValueCallback& callback); 187 const RemoteCharacteristicWriteValueCallback& callback);
175 void OnWriteValueFailed( 188 void OnCharacteristicWriteValueFailed(
176 const RemoteCharacteristicWriteValueCallback& callback, 189 const RemoteCharacteristicWriteValueCallback& callback,
177 device::BluetoothRemoteGattService::GattErrorCode error_code); 190 device::BluetoothRemoteGattService::GattErrorCode error_code);
178 191
179 // Callbacks for BluetoothRemoteGattCharacteristic::StartNotifySession. 192 // Callbacks for BluetoothRemoteGattCharacteristic::StartNotifySession.
180 void OnStartNotifySessionSuccess( 193 void OnStartNotifySessionSuccess(
181 const RemoteCharacteristicStartNotificationsCallback& callback, 194 const RemoteCharacteristicStartNotificationsCallback& callback,
182 std::unique_ptr<device::BluetoothGattNotifySession> notify_session); 195 std::unique_ptr<device::BluetoothGattNotifySession> notify_session);
183 void OnStartNotifySessionFailed( 196 void OnStartNotifySessionFailed(
184 const RemoteCharacteristicStartNotificationsCallback& callback, 197 const RemoteCharacteristicStartNotificationsCallback& callback,
185 device::BluetoothRemoteGattService::GattErrorCode error_code); 198 device::BluetoothRemoteGattService::GattErrorCode error_code);
186 199
187 // Callback for BluetoothGattNotifySession::Stop. 200 // Callback for BluetoothGattNotifySession::Stop.
188 void OnStopNotifySessionComplete( 201 void OnStopNotifySessionComplete(
189 const std::string& characteristic_instance_id, 202 const std::string& characteristic_instance_id,
190 const RemoteCharacteristicStopNotificationsCallback& callback); 203 const RemoteCharacteristicStopNotificationsCallback& callback);
191 204
205 // Callbacks for BluetoothRemoteGattDescriptor::ReadRemoteDescriptor.
ortuno 2016/12/02 06:14:50 Same here. No need for these callbacks.
dougt 2016/12/02 18:31:28 Done.
206 void OnDescriptorReadValueSuccess(
207 const RemoteDescriptorReadValueCallback& callback,
208 const std::vector<uint8_t>& value);
209 void OnDescriptorReadValueFailed(
210 const RemoteDescriptorReadValueCallback& callback,
211 device::BluetoothRemoteGattService::GattErrorCode error_code);
212
213 // Callbacks for BluetoothRemoteGattDescriptor::WriteRemoteDescriptor.
214 void OnDescriptorWriteValueSuccess(
215 const RemoteDescriptorWriteValueCallback& callback);
216 void OnDescriptorWriteValueFailed(
217 const RemoteDescriptorWriteValueCallback& callback,
218 device::BluetoothRemoteGattService::GattErrorCode error_code);
219
192 // Functions to query the platform cache for the bluetooth object. 220 // Functions to query the platform cache for the bluetooth object.
193 // result.outcome == CacheQueryOutcome::SUCCESS if the object was found in the 221 // result.outcome == CacheQueryOutcome::SUCCESS if the object was found in the
194 // cache. Otherwise result.outcome that can used to record the outcome and 222 // cache. Otherwise result.outcome that can used to record the outcome and
195 // result.error will contain the error that should be sent to the renderer. 223 // result.error will contain the error that should be sent to the renderer.
196 // One of the possible outcomes is BAD_RENDERER. In this case we crash the 224 // One of the possible outcomes is BAD_RENDERER. In this case we crash the
197 // renderer, record the reason and close the pipe, so it's safe to drop 225 // renderer, record the reason and close the pipe, so it's safe to drop
198 // any callbacks. 226 // any callbacks.
199 227
200 // Queries the platform cache for a Device with |device_id| for |origin|. 228 // Queries the platform cache for a Device with |device_id| for |origin|.
201 // Fills in the |outcome| field and the |device| field if successful. 229 // Fills in the |outcome| field and the |device| field if successful.
202 CacheQueryResult QueryCacheForDevice(const WebBluetoothDeviceId& device_id); 230 CacheQueryResult QueryCacheForDevice(const WebBluetoothDeviceId& device_id);
203 231
204 // Queries the platform cache for a Service with |service_instance_id|. Fills 232 // Queries the platform cache for a Service with |service_instance_id|. Fills
205 // in the |outcome| field, and |device| and |service| fields if successful. 233 // in the |outcome| field, and |device| and |service| fields if successful.
206 CacheQueryResult QueryCacheForService(const std::string& service_instance_id); 234 CacheQueryResult QueryCacheForService(const std::string& service_instance_id);
207 235
208 // Queries the platform cache for a characteristic with 236 // Queries the platform cache for a characteristic with
209 // |characteristic_instance_id|. Fills in the |outcome| field, and |device|, 237 // |characteristic_instance_id|. Fills in the |outcome| field, and |device|,
210 // |service| and |characteristic| fields if successful. 238 // |service| and |characteristic| fields if successful.
211 CacheQueryResult QueryCacheForCharacteristic( 239 CacheQueryResult QueryCacheForCharacteristic(
212 const std::string& characteristic_instance_id); 240 const std::string& characteristic_instance_id);
213 241
242 // Queries the platform cache for a descriptor with
ortuno 2016/12/02 06:14:50 No need for this one either.
dougt 2016/12/02 18:31:28 Done.
243 // |descriptor_instance_id|. Fills in the |outcome| field, and |service|,
244 // |characteristic| and |descriptor| fields if successful.
245 CacheQueryResult QueryCacheForDescriptor(
246 const std::string& descriptor_instance_id);
247
214 RenderProcessHost* GetRenderProcessHost(); 248 RenderProcessHost* GetRenderProcessHost();
215 device::BluetoothAdapter* GetAdapter(); 249 device::BluetoothAdapter* GetAdapter();
216 url::Origin GetOrigin(); 250 url::Origin GetOrigin();
217 251
218 // Clears all state (maps, sets, etc). 252 // Clears all state (maps, sets, etc).
219 void ClearState(); 253 void ClearState();
220 254
221 // Used to open a BluetoothChooser and start a device discovery session. 255 // Used to open a BluetoothChooser and start a device discovery session.
222 std::unique_ptr<BluetoothDeviceChooserController> device_chooser_controller_; 256 std::unique_ptr<BluetoothDeviceChooserController> device_chooser_controller_;
223 257
224 // Keeps track of which devices the frame's origin is allowed to access. 258 // Keeps track of which devices the frame's origin is allowed to access.
225 BluetoothAllowedDevicesMap allowed_devices_map_; 259 BluetoothAllowedDevicesMap allowed_devices_map_;
226 260
227 // Maps to get the object's parent based on its instanceID. 261 // Maps to get the object's parent based on its instanceID.
228 std::unordered_map<std::string, std::string> service_id_to_device_address_; 262 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_; 263 std::unordered_map<std::string, std::string> characteristic_id_to_service_id_;
264 std::unordered_map<std::string, std::string>
265 descriptor_id_to_characteristic_id_;
230 266
231 // Map to keep track of the connected Bluetooth devices. 267 // Map to keep track of the connected Bluetooth devices.
232 std::unique_ptr<FrameConnectedBluetoothDevices> connected_devices_; 268 std::unique_ptr<FrameConnectedBluetoothDevices> connected_devices_;
233 269
234 // Maps a device address to callbacks that are waiting for services to 270 // Maps a device address to callbacks that are waiting for services to
235 // be discovered for that device. 271 // be discovered for that device.
236 std::unordered_map<std::string, std::vector<PrimaryServicesRequestCallback>> 272 std::unordered_map<std::string, std::vector<PrimaryServicesRequestCallback>>
237 pending_primary_services_requests_; 273 pending_primary_services_requests_;
238 274
239 // Map to keep track of the characteristics' notify sessions. 275 // Map to keep track of the characteristics' notify sessions.
(...skipping 13 matching lines...) Expand all
253 mojo::Binding<blink::mojom::WebBluetoothService> binding_; 289 mojo::Binding<blink::mojom::WebBluetoothService> binding_;
254 290
255 base::WeakPtrFactory<WebBluetoothServiceImpl> weak_ptr_factory_; 291 base::WeakPtrFactory<WebBluetoothServiceImpl> weak_ptr_factory_;
256 292
257 DISALLOW_COPY_AND_ASSIGN(WebBluetoothServiceImpl); 293 DISALLOW_COPY_AND_ASSIGN(WebBluetoothServiceImpl);
258 }; 294 };
259 295
260 } // namespace content 296 } // namespace content
261 297
262 #endif // CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_ 298 #endif // CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698