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

Side by Side Diff: content/renderer/bluetooth/bluetooth_dispatcher.cc

Issue 1235083006: CallbackPromiseAdapter types should be more compatible with WebCallbacks (2/3). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@web-callbacks-3
Patch Set: Created 5 years, 4 months 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 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 #include "content/renderer/bluetooth/bluetooth_dispatcher.h" 5 #include "content/renderer/bluetooth/bluetooth_dispatcher.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
11 #include "content/child/thread_safe_sender.h" 11 #include "content/child/thread_safe_sender.h"
12 #include "content/common/bluetooth/bluetooth_messages.h" 12 #include "content/common/bluetooth/bluetooth_messages.h"
13 #include "device/bluetooth/bluetooth_uuid.h" 13 #include "device/bluetooth/bluetooth_uuid.h"
14 #include "third_party/WebKit/public/platform/WebPassOwnPtr.h"
14 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic e.h" 15 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic e.h"
15 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError .h" 16 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothError .h"
16 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTC haracteristic.h" 17 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTC haracteristic.h"
17 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTR emoteServer.h" 18 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTR emoteServer.h"
18 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTS ervice.h" 19 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothGATTS ervice.h"
19 #include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceO ptions.h" 20 #include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceO ptions.h"
20 21
21 using blink::WebBluetoothConnectGATTCallbacks; 22 using blink::WebBluetoothConnectGATTCallbacks;
22 using blink::WebBluetoothDevice; 23 using blink::WebBluetoothDevice;
23 using blink::WebBluetoothError; 24 using blink::WebBluetoothError;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 int thread_id, 234 int thread_id,
234 int request_id, 235 int request_id,
235 const BluetoothDevice& device) { 236 const BluetoothDevice& device) {
236 DCHECK(pending_requests_.Lookup(request_id)) << request_id; 237 DCHECK(pending_requests_.Lookup(request_id)) << request_id;
237 238
238 WebVector<WebString> uuids(device.uuids.size()); 239 WebVector<WebString> uuids(device.uuids.size());
239 for (size_t i = 0; i < device.uuids.size(); ++i) 240 for (size_t i = 0; i < device.uuids.size(); ++i)
240 uuids[i] = WebString::fromUTF8(device.uuids[i].c_str()); 241 uuids[i] = WebString::fromUTF8(device.uuids[i].c_str());
241 242
242 pending_requests_.Lookup(request_id) 243 pending_requests_.Lookup(request_id)
243 ->onSuccess(new WebBluetoothDevice( 244 ->onSuccess(blink::adoptWebPtr(new WebBluetoothDevice(
244 WebString::fromUTF8(device.instance_id), WebString(device.name), 245 WebString::fromUTF8(device.instance_id), WebString(device.name),
245 device.device_class, GetWebVendorIdSource(device.vendor_id_source), 246 device.device_class, GetWebVendorIdSource(device.vendor_id_source),
246 device.vendor_id, device.product_id, device.product_version, 247 device.vendor_id, device.product_id, device.product_version,
247 device.paired, uuids)); 248 device.paired, uuids)));
248 pending_requests_.Remove(request_id); 249 pending_requests_.Remove(request_id);
249 } 250 }
250 251
251 void BluetoothDispatcher::OnRequestDeviceError(int thread_id, 252 void BluetoothDispatcher::OnRequestDeviceError(int thread_id,
252 int request_id, 253 int request_id,
253 WebBluetoothError error) { 254 WebBluetoothError error) {
254 DCHECK(pending_requests_.Lookup(request_id)) << request_id; 255 DCHECK(pending_requests_.Lookup(request_id)) << request_id;
255 pending_requests_.Lookup(request_id)->onError(new WebBluetoothError(error)); 256 pending_requests_.Lookup(request_id)->onError(WebBluetoothError(error));
256 pending_requests_.Remove(request_id); 257 pending_requests_.Remove(request_id);
257 } 258 }
258 259
259 void BluetoothDispatcher::OnConnectGATTSuccess( 260 void BluetoothDispatcher::OnConnectGATTSuccess(
260 int thread_id, 261 int thread_id,
261 int request_id, 262 int request_id,
262 const std::string& device_instance_id) { 263 const std::string& device_instance_id) {
263 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id; 264 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id;
264 pending_connect_requests_.Lookup(request_id) 265 pending_connect_requests_.Lookup(request_id)
265 ->onSuccess(new WebBluetoothGATTRemoteServer( 266 ->onSuccess(blink::adoptWebPtr(new WebBluetoothGATTRemoteServer(
266 WebString::fromUTF8(device_instance_id), true /* connected */)); 267 WebString::fromUTF8(device_instance_id), true /* connected */)));
267 pending_connect_requests_.Remove(request_id); 268 pending_connect_requests_.Remove(request_id);
268 } 269 }
269 270
270 void BluetoothDispatcher::OnConnectGATTError(int thread_id, 271 void BluetoothDispatcher::OnConnectGATTError(int thread_id,
271 int request_id, 272 int request_id,
272 WebBluetoothError error) { 273 WebBluetoothError error) {
273 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id; 274 DCHECK(pending_connect_requests_.Lookup(request_id)) << request_id;
274 pending_connect_requests_.Lookup(request_id) 275 pending_connect_requests_.Lookup(request_id)
275 ->onError(new WebBluetoothError(error)); 276 ->onError(WebBluetoothError(error));
276 pending_connect_requests_.Remove(request_id); 277 pending_connect_requests_.Remove(request_id);
277 } 278 }
278 279
279 void BluetoothDispatcher::OnGetPrimaryServiceSuccess( 280 void BluetoothDispatcher::OnGetPrimaryServiceSuccess(
280 int thread_id, 281 int thread_id,
281 int request_id, 282 int request_id,
282 const std::string& service_instance_id) { 283 const std::string& service_instance_id) {
283 DCHECK(pending_primary_service_requests_.Lookup(request_id)) << request_id; 284 DCHECK(pending_primary_service_requests_.Lookup(request_id)) << request_id;
284 BluetoothPrimaryServiceRequest* request = 285 BluetoothPrimaryServiceRequest* request =
285 pending_primary_service_requests_.Lookup(request_id); 286 pending_primary_service_requests_.Lookup(request_id);
286 request->callbacks->onSuccess(new WebBluetoothGATTService( 287 request->callbacks->onSuccess(blink::adoptWebPtr(new WebBluetoothGATTService(
287 WebString::fromUTF8(service_instance_id), request->service_uuid, 288 WebString::fromUTF8(service_instance_id), request->service_uuid,
288 true /* isPrimary */, request->device_instance_id)); 289 true /* isPrimary */, request->device_instance_id)));
289 pending_primary_service_requests_.Remove(request_id); 290 pending_primary_service_requests_.Remove(request_id);
290 } 291 }
291 292
292 void BluetoothDispatcher::OnGetPrimaryServiceError(int thread_id, 293 void BluetoothDispatcher::OnGetPrimaryServiceError(int thread_id,
293 int request_id, 294 int request_id,
294 WebBluetoothError error) { 295 WebBluetoothError error) {
295 DCHECK(pending_primary_service_requests_.Lookup(request_id)) << request_id; 296 DCHECK(pending_primary_service_requests_.Lookup(request_id)) << request_id;
296 297
297 // Since we couldn't find the service return null. See Step 3 of 298 // Since we couldn't find the service return null. See Step 3 of
298 // getPrimaryService algorithm: 299 // getPrimaryService algorithm:
299 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothgattremote server-getprimaryservice 300 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothgattremote server-getprimaryservice
300 if (error == WebBluetoothError::ServiceNotFound) { 301 if (error == WebBluetoothError::ServiceNotFound) {
301 pending_primary_service_requests_.Lookup(request_id) 302 pending_primary_service_requests_.Lookup(request_id)
302 ->callbacks->onSuccess(nullptr); 303 ->callbacks->onSuccess(nullptr);
303 pending_primary_service_requests_.Remove(request_id); 304 pending_primary_service_requests_.Remove(request_id);
304 return; 305 return;
305 } 306 }
306 307
307 pending_primary_service_requests_.Lookup(request_id) 308 pending_primary_service_requests_.Lookup(request_id)
308 ->callbacks->onError(new WebBluetoothError(error)); 309 ->callbacks->onError(WebBluetoothError(error));
309 pending_primary_service_requests_.Remove(request_id); 310 pending_primary_service_requests_.Remove(request_id);
310 } 311 }
311 312
312 void BluetoothDispatcher::OnGetCharacteristicSuccess( 313 void BluetoothDispatcher::OnGetCharacteristicSuccess(
313 int thread_id, 314 int thread_id,
314 int request_id, 315 int request_id,
315 const std::string& characteristic_instance_id) { 316 const std::string& characteristic_instance_id) {
316 DCHECK(pending_characteristic_requests_.Lookup(request_id)) << request_id; 317 DCHECK(pending_characteristic_requests_.Lookup(request_id)) << request_id;
317 318
318 BluetoothCharacteristicRequest* request = 319 BluetoothCharacteristicRequest* request =
319 pending_characteristic_requests_.Lookup(request_id); 320 pending_characteristic_requests_.Lookup(request_id);
320 request->callbacks->onSuccess(new WebBluetoothGATTCharacteristic( 321 request->callbacks->onSuccess(
321 WebString::fromUTF8(characteristic_instance_id), 322 blink::adoptWebPtr(new WebBluetoothGATTCharacteristic(
322 request->service_instance_id, request->characteristic_uuid)); 323 WebString::fromUTF8(characteristic_instance_id),
324 request->service_instance_id, request->characteristic_uuid)));
323 325
324 pending_characteristic_requests_.Remove(request_id); 326 pending_characteristic_requests_.Remove(request_id);
325 } 327 }
326 328
327 void BluetoothDispatcher::OnGetCharacteristicError(int thread_id, 329 void BluetoothDispatcher::OnGetCharacteristicError(int thread_id,
328 int request_id, 330 int request_id,
329 WebBluetoothError error) { 331 WebBluetoothError error) {
330 DCHECK(pending_characteristic_requests_.Lookup(request_id)) << request_id; 332 DCHECK(pending_characteristic_requests_.Lookup(request_id)) << request_id;
331 333
332 // Since we couldn't find the characteristic return null. See Step 3 of 334 // Since we couldn't find the characteristic return null. See Step 3 of
333 // getCharacteristic algorithm: 335 // getCharacteristic algorithm:
334 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothgattservic e-getcharacteristic 336 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothgattservic e-getcharacteristic
335 if (error == WebBluetoothError::CharacteristicNotFound) { 337 if (error == WebBluetoothError::CharacteristicNotFound) {
336 pending_characteristic_requests_.Lookup(request_id) 338 pending_characteristic_requests_.Lookup(request_id)
337 ->callbacks->onSuccess(nullptr); 339 ->callbacks->onSuccess(nullptr);
338 } else { 340 } else {
339 pending_characteristic_requests_.Lookup(request_id) 341 pending_characteristic_requests_.Lookup(request_id)
340 ->callbacks->onError(new WebBluetoothError(error)); 342 ->callbacks->onError(WebBluetoothError(error));
341 } 343 }
342 pending_characteristic_requests_.Remove(request_id); 344 pending_characteristic_requests_.Remove(request_id);
343 } 345 }
344 346
345 void BluetoothDispatcher::OnReadValueSuccess( 347 void BluetoothDispatcher::OnReadValueSuccess(
346 int thread_id, 348 int thread_id,
347 int request_id, 349 int request_id,
348 const std::vector<uint8_t>& value) { 350 const std::vector<uint8_t>& value) {
349 DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id; 351 DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id;
350 352
351 // WebArrayBuffer is not accessible from Source/modules so we pass a 353 // WebArrayBuffer is not accessible from Source/modules so we pass a
352 // WebVector instead. 354 // WebVector instead.
353 pending_read_value_requests_.Lookup(request_id) 355 pending_read_value_requests_.Lookup(request_id)->onSuccess(value);
354 ->onSuccess(new WebVector<uint8_t>(value));
355 356
356 pending_read_value_requests_.Remove(request_id); 357 pending_read_value_requests_.Remove(request_id);
357 } 358 }
358 359
359 void BluetoothDispatcher::OnReadValueError(int thread_id, 360 void BluetoothDispatcher::OnReadValueError(int thread_id,
360 int request_id, 361 int request_id,
361 WebBluetoothError error) { 362 WebBluetoothError error) {
362 DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id; 363 DCHECK(pending_read_value_requests_.Lookup(request_id)) << request_id;
363 364
364 pending_read_value_requests_.Lookup(request_id) 365 pending_read_value_requests_.Lookup(request_id)
365 ->onError(new WebBluetoothError(error)); 366 ->onError(WebBluetoothError(error));
366 367
367 pending_read_value_requests_.Remove(request_id); 368 pending_read_value_requests_.Remove(request_id);
368 } 369 }
369 370
370 void BluetoothDispatcher::OnWriteValueSuccess(int thread_id, int request_id) { 371 void BluetoothDispatcher::OnWriteValueSuccess(int thread_id, int request_id) {
371 DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id; 372 DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id;
372 373
373 pending_write_value_requests_.Lookup(request_id)->onSuccess(); 374 pending_write_value_requests_.Lookup(request_id)->onSuccess();
374 375
375 pending_write_value_requests_.Remove(request_id); 376 pending_write_value_requests_.Remove(request_id);
376 } 377 }
377 378
378 void BluetoothDispatcher::OnWriteValueError(int thread_id, 379 void BluetoothDispatcher::OnWriteValueError(int thread_id,
379 int request_id, 380 int request_id,
380 WebBluetoothError error) { 381 WebBluetoothError error) {
381 DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id; 382 DCHECK(pending_write_value_requests_.Lookup(request_id)) << request_id;
382 383
383 pending_write_value_requests_.Lookup(request_id) 384 pending_write_value_requests_.Lookup(request_id)
384 ->onError(new WebBluetoothError(error)); 385 ->onError(WebBluetoothError(error));
385 386
386 pending_write_value_requests_.Remove(request_id); 387 pending_write_value_requests_.Remove(request_id);
387 } 388 }
388 389
389 } // namespace content 390 } // namespace content
OLDNEW
« no previous file with comments | « content/child/service_worker/service_worker_dispatcher.cc ('k') | content/renderer/cache_storage/cache_storage_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698