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 // ID Not In Map Note: | 5 // ID Not In Map Note: |
6 // A service, characteristic, or descriptor ID not in the corresponding | 6 // A service, characteristic, or descriptor ID not in the corresponding |
7 // WebBluetoothServiceImpl map [service_id_to_device_address_, | 7 // WebBluetoothServiceImpl map [service_id_to_device_address_, |
8 // characteristic_id_to_service_id_, descriptor_to_characteristic_] implies a | 8 // characteristic_id_to_service_id_, descriptor_to_characteristic_] implies a |
9 // hostile renderer because a renderer obtains the corresponding ID from this | 9 // hostile renderer because a renderer obtains the corresponding ID from this |
10 // class and it will be added to the map at that time. | 10 // class and it will be added to the map at that time. |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 FROM_HERE, | 301 FROM_HERE, |
302 base::Bind(&WebBluetoothServiceImpl::NotifyCharacteristicValueChanged, | 302 base::Bind(&WebBluetoothServiceImpl::NotifyCharacteristicValueChanged, |
303 weak_ptr_factory_.GetWeakPtr(), | 303 weak_ptr_factory_.GetWeakPtr(), |
304 characteristic->GetIdentifier(), value))) { | 304 characteristic->GetIdentifier(), value))) { |
305 LOG(WARNING) << "No TaskRunner."; | 305 LOG(WARNING) << "No TaskRunner."; |
306 } | 306 } |
307 } | 307 } |
308 | 308 |
309 void WebBluetoothServiceImpl::NotifyCharacteristicValueChanged( | 309 void WebBluetoothServiceImpl::NotifyCharacteristicValueChanged( |
310 const std::string& characteristic_instance_id, | 310 const std::string& characteristic_instance_id, |
311 std::vector<uint8_t> value) { | 311 std::vector<uint8_t> value) { |
dcheng
2016/11/24 04:56:49
Nit: I'm not sure what the desired semantics here
juncai
2016/11/28 22:25:21
Done.
| |
312 if (client_) { | 312 if (client_) { |
313 client_->RemoteCharacteristicValueChanged( | 313 client_->RemoteCharacteristicValueChanged(characteristic_instance_id, |
314 characteristic_instance_id, mojo::Array<uint8_t>(std::move(value))); | 314 std::move(value)); |
315 } | 315 } |
316 } | 316 } |
317 | 317 |
318 void WebBluetoothServiceImpl::SetClient( | 318 void WebBluetoothServiceImpl::SetClient( |
319 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo client) { | 319 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo client) { |
320 DCHECK(!client_.get()); | 320 DCHECK(!client_.get()); |
321 client_.Bind(std::move(client)); | 321 client_.Bind(std::move(client)); |
322 } | 322 } |
323 | 323 |
324 void WebBluetoothServiceImpl::RequestDevice( | 324 void WebBluetoothServiceImpl::RequestDevice( |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 RecordWebBluetoothFunctionCall( | 404 RecordWebBluetoothFunctionCall( |
405 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE | 405 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE |
406 ? UMAWebBluetoothFunction::GET_PRIMARY_SERVICE | 406 ? UMAWebBluetoothFunction::GET_PRIMARY_SERVICE |
407 : UMAWebBluetoothFunction::GET_PRIMARY_SERVICES); | 407 : UMAWebBluetoothFunction::GET_PRIMARY_SERVICES); |
408 RecordGetPrimaryServicesServices(quantity, services_uuid); | 408 RecordGetPrimaryServicesServices(quantity, services_uuid); |
409 | 409 |
410 if (!allowed_devices_map_.IsOriginAllowedToAccessAtLeastOneService( | 410 if (!allowed_devices_map_.IsOriginAllowedToAccessAtLeastOneService( |
411 GetOrigin(), device_id)) { | 411 GetOrigin(), device_id)) { |
412 callback.Run( | 412 callback.Run( |
413 blink::mojom::WebBluetoothResult::NOT_ALLOWED_TO_ACCESS_ANY_SERVICE, | 413 blink::mojom::WebBluetoothResult::NOT_ALLOWED_TO_ACCESS_ANY_SERVICE, |
414 nullptr /* service */); | 414 base::nullopt /* service */); |
415 return; | 415 return; |
416 } | 416 } |
417 | 417 |
418 if (services_uuid && | 418 if (services_uuid && |
419 !allowed_devices_map_.IsOriginAllowedToAccessService( | 419 !allowed_devices_map_.IsOriginAllowedToAccessService( |
420 GetOrigin(), device_id, services_uuid.value())) { | 420 GetOrigin(), device_id, services_uuid.value())) { |
421 callback.Run( | 421 callback.Run( |
422 blink::mojom::WebBluetoothResult::NOT_ALLOWED_TO_ACCESS_SERVICE, | 422 blink::mojom::WebBluetoothResult::NOT_ALLOWED_TO_ACCESS_SERVICE, |
423 nullptr /* service */); | 423 base::nullopt /* service */); |
424 return; | 424 return; |
425 } | 425 } |
426 | 426 |
427 const CacheQueryResult query_result = QueryCacheForDevice(device_id); | 427 const CacheQueryResult query_result = QueryCacheForDevice(device_id); |
428 | 428 |
429 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 429 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
430 return; | 430 return; |
431 } | 431 } |
432 | 432 |
433 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 433 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
434 RecordGetPrimaryServicesOutcome(quantity, query_result.outcome); | 434 RecordGetPrimaryServicesOutcome(quantity, query_result.outcome); |
435 callback.Run(query_result.GetWebResult(), nullptr /* service */); | 435 callback.Run(query_result.GetWebResult(), base::nullopt /* service */); |
436 return; | 436 return; |
437 } | 437 } |
438 | 438 |
439 const std::string& device_address = query_result.device->GetAddress(); | 439 const std::string& device_address = query_result.device->GetAddress(); |
440 | 440 |
441 // We can't know if a service is present or not until GATT service discovery | 441 // We can't know if a service is present or not until GATT service discovery |
442 // is complete for the device. | 442 // is complete for the device. |
443 if (query_result.device->IsGattServicesDiscoveryComplete()) { | 443 if (query_result.device->IsGattServicesDiscoveryComplete()) { |
444 RemoteServerGetPrimaryServicesImpl(device_id, quantity, services_uuid, | 444 RemoteServerGetPrimaryServicesImpl(device_id, quantity, services_uuid, |
445 callback, query_result.device); | 445 callback, query_result.device); |
446 return; | 446 return; |
447 } | 447 } |
448 | 448 |
449 VLOG(1) << "Services not yet discovered."; | 449 VLOG(1) << "Services not yet discovered."; |
450 pending_primary_services_requests_[device_address].push_back(base::Bind( | 450 pending_primary_services_requests_[device_address].push_back(base::Bind( |
451 &WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl, | 451 &WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl, |
452 base::Unretained(this), device_id, quantity, services_uuid, callback)); | 452 base::Unretained(this), device_id, quantity, services_uuid, callback)); |
453 } | 453 } |
454 | 454 |
455 void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics( | 455 void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics( |
456 const mojo::String& service_instance_id, | 456 const std::string& service_instance_id, |
457 blink::mojom::WebBluetoothGATTQueryQuantity quantity, | 457 blink::mojom::WebBluetoothGATTQueryQuantity quantity, |
458 const base::Optional<BluetoothUUID>& characteristics_uuid, | 458 const base::Optional<BluetoothUUID>& characteristics_uuid, |
459 const RemoteServiceGetCharacteristicsCallback& callback) { | 459 const RemoteServiceGetCharacteristicsCallback& callback) { |
460 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 460 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
461 | 461 |
462 RecordWebBluetoothFunctionCall( | 462 RecordWebBluetoothFunctionCall( |
463 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE | 463 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE |
464 ? UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTIC | 464 ? UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTIC |
465 : UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTICS); | 465 : UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTICS); |
466 RecordGetCharacteristicsCharacteristic(quantity, characteristics_uuid); | 466 RecordGetCharacteristicsCharacteristic(quantity, characteristics_uuid); |
467 | 467 |
468 if (characteristics_uuid && | 468 if (characteristics_uuid && |
469 BluetoothBlocklist::Get().IsExcluded(characteristics_uuid.value())) { | 469 BluetoothBlocklist::Get().IsExcluded(characteristics_uuid.value())) { |
470 RecordGetCharacteristicsOutcome(quantity, | 470 RecordGetCharacteristicsOutcome(quantity, |
471 UMAGetCharacteristicOutcome::BLOCKLISTED); | 471 UMAGetCharacteristicOutcome::BLOCKLISTED); |
472 callback.Run( | 472 callback.Run( |
473 blink::mojom::WebBluetoothResult::BLOCKLISTED_CHARACTERISTIC_UUID, | 473 blink::mojom::WebBluetoothResult::BLOCKLISTED_CHARACTERISTIC_UUID, |
474 nullptr /* characteristics */); | 474 base::nullopt /* characteristics */); |
475 return; | 475 return; |
476 } | 476 } |
477 | 477 |
478 const CacheQueryResult query_result = | 478 const CacheQueryResult query_result = |
479 QueryCacheForService(service_instance_id); | 479 QueryCacheForService(service_instance_id); |
480 | 480 |
481 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 481 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
482 return; | 482 return; |
483 } | 483 } |
484 | 484 |
485 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 485 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
486 RecordGetCharacteristicsOutcome(quantity, query_result.outcome); | 486 RecordGetCharacteristicsOutcome(quantity, query_result.outcome); |
487 callback.Run(query_result.GetWebResult(), nullptr /* characteristics */); | 487 callback.Run(query_result.GetWebResult(), |
488 base::nullopt /* characteristics */); | |
488 return; | 489 return; |
489 } | 490 } |
490 | 491 |
491 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics = | 492 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics = |
492 characteristics_uuid | 493 characteristics_uuid |
493 ? GetCharacteristicsByUUID(query_result.service, | 494 ? GetCharacteristicsByUUID(query_result.service, |
494 characteristics_uuid.value()) | 495 characteristics_uuid.value()) |
495 : query_result.service->GetCharacteristics(); | 496 : query_result.service->GetCharacteristics(); |
496 | 497 |
497 mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> | 498 std::vector<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> |
498 response_characteristics; | 499 response_characteristics; |
499 for (device::BluetoothRemoteGattCharacteristic* characteristic : | 500 for (device::BluetoothRemoteGattCharacteristic* characteristic : |
500 characteristics) { | 501 characteristics) { |
501 if (BluetoothBlocklist::Get().IsExcluded(characteristic->GetUUID())) { | 502 if (BluetoothBlocklist::Get().IsExcluded(characteristic->GetUUID())) { |
502 continue; | 503 continue; |
503 } | 504 } |
504 std::string characteristic_instance_id = characteristic->GetIdentifier(); | 505 std::string characteristic_instance_id = characteristic->GetIdentifier(); |
505 auto insert_result = characteristic_id_to_service_id_.insert( | 506 auto insert_result = characteristic_id_to_service_id_.insert( |
506 std::make_pair(characteristic_instance_id, service_instance_id)); | 507 std::make_pair(characteristic_instance_id, service_instance_id)); |
507 // If value is already in map, DCHECK it's valid. | 508 // If value is already in map, DCHECK it's valid. |
(...skipping 21 matching lines...) Expand all Loading... | |
529 return; | 530 return; |
530 } | 531 } |
531 | 532 |
532 RecordGetCharacteristicsOutcome( | 533 RecordGetCharacteristicsOutcome( |
533 quantity, characteristics_uuid | 534 quantity, characteristics_uuid |
534 ? UMAGetCharacteristicOutcome::NOT_FOUND | 535 ? UMAGetCharacteristicOutcome::NOT_FOUND |
535 : UMAGetCharacteristicOutcome::NO_CHARACTERISTICS); | 536 : UMAGetCharacteristicOutcome::NO_CHARACTERISTICS); |
536 callback.Run(characteristics_uuid | 537 callback.Run(characteristics_uuid |
537 ? blink::mojom::WebBluetoothResult::CHARACTERISTIC_NOT_FOUND | 538 ? blink::mojom::WebBluetoothResult::CHARACTERISTIC_NOT_FOUND |
538 : blink::mojom::WebBluetoothResult::NO_CHARACTERISTICS_FOUND, | 539 : blink::mojom::WebBluetoothResult::NO_CHARACTERISTICS_FOUND, |
539 nullptr /* characteristics */); | 540 base::nullopt /* characteristics */); |
540 } | 541 } |
541 | 542 |
542 void WebBluetoothServiceImpl::RemoteCharacteristicReadValue( | 543 void WebBluetoothServiceImpl::RemoteCharacteristicReadValue( |
543 const mojo::String& characteristic_instance_id, | 544 const std::string& characteristic_instance_id, |
544 const RemoteCharacteristicReadValueCallback& callback) { | 545 const RemoteCharacteristicReadValueCallback& callback) { |
545 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 546 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
546 RecordWebBluetoothFunctionCall( | 547 RecordWebBluetoothFunctionCall( |
547 UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE); | 548 UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE); |
548 | 549 |
549 const CacheQueryResult query_result = | 550 const CacheQueryResult query_result = |
550 QueryCacheForCharacteristic(characteristic_instance_id); | 551 QueryCacheForCharacteristic(characteristic_instance_id); |
551 | 552 |
552 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 553 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
553 return; | 554 return; |
554 } | 555 } |
555 | 556 |
556 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 557 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
557 RecordCharacteristicReadValueOutcome(query_result.outcome); | 558 RecordCharacteristicReadValueOutcome(query_result.outcome); |
558 callback.Run(query_result.GetWebResult(), nullptr /* value */); | 559 callback.Run(query_result.GetWebResult(), base::nullopt /* value */); |
559 return; | 560 return; |
560 } | 561 } |
561 | 562 |
562 if (BluetoothBlocklist::Get().IsExcludedFromReads( | 563 if (BluetoothBlocklist::Get().IsExcludedFromReads( |
563 query_result.characteristic->GetUUID())) { | 564 query_result.characteristic->GetUUID())) { |
564 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::BLOCKLISTED); | 565 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::BLOCKLISTED); |
565 callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_READ, | 566 callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_READ, |
566 nullptr /* value */); | 567 base::nullopt /* value */); |
567 return; | 568 return; |
568 } | 569 } |
569 | 570 |
570 query_result.characteristic->ReadRemoteCharacteristic( | 571 query_result.characteristic->ReadRemoteCharacteristic( |
571 base::Bind(&WebBluetoothServiceImpl::OnReadValueSuccess, | 572 base::Bind(&WebBluetoothServiceImpl::OnReadValueSuccess, |
572 weak_ptr_factory_.GetWeakPtr(), callback), | 573 weak_ptr_factory_.GetWeakPtr(), callback), |
573 base::Bind(&WebBluetoothServiceImpl::OnReadValueFailed, | 574 base::Bind(&WebBluetoothServiceImpl::OnReadValueFailed, |
574 weak_ptr_factory_.GetWeakPtr(), callback)); | 575 weak_ptr_factory_.GetWeakPtr(), callback)); |
575 } | 576 } |
576 | 577 |
577 void WebBluetoothServiceImpl::RemoteCharacteristicWriteValue( | 578 void WebBluetoothServiceImpl::RemoteCharacteristicWriteValue( |
578 const mojo::String& characteristic_instance_id, | 579 const std::string& characteristic_instance_id, |
579 mojo::Array<uint8_t> value, | 580 const std::vector<uint8_t>& value, |
580 const RemoteCharacteristicWriteValueCallback& callback) { | 581 const RemoteCharacteristicWriteValueCallback& callback) { |
581 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 582 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
582 RecordWebBluetoothFunctionCall( | 583 RecordWebBluetoothFunctionCall( |
583 UMAWebBluetoothFunction::CHARACTERISTIC_WRITE_VALUE); | 584 UMAWebBluetoothFunction::CHARACTERISTIC_WRITE_VALUE); |
584 | 585 |
585 // We perform the length check on the renderer side. So if we | 586 // We perform the length check on the renderer side. So if we |
586 // get a value with length > 512, we can assume it's a hostile | 587 // get a value with length > 512, we can assume it's a hostile |
587 // renderer and kill it. | 588 // renderer and kill it. |
588 if (value.size() > 512) { | 589 if (value.size() > 512) { |
589 CrashRendererAndClosePipe(bad_message::BDH_INVALID_WRITE_VALUE_LENGTH); | 590 CrashRendererAndClosePipe(bad_message::BDH_INVALID_WRITE_VALUE_LENGTH); |
(...skipping 14 matching lines...) Expand all Loading... | |
604 } | 605 } |
605 | 606 |
606 if (BluetoothBlocklist::Get().IsExcludedFromWrites( | 607 if (BluetoothBlocklist::Get().IsExcludedFromWrites( |
607 query_result.characteristic->GetUUID())) { | 608 query_result.characteristic->GetUUID())) { |
608 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::BLOCKLISTED); | 609 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::BLOCKLISTED); |
609 callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_WRITE); | 610 callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_WRITE); |
610 return; | 611 return; |
611 } | 612 } |
612 | 613 |
613 query_result.characteristic->WriteRemoteCharacteristic( | 614 query_result.characteristic->WriteRemoteCharacteristic( |
614 value.To<std::vector<uint8_t>>(), | 615 value, base::Bind(&WebBluetoothServiceImpl::OnWriteValueSuccess, |
615 base::Bind(&WebBluetoothServiceImpl::OnWriteValueSuccess, | 616 weak_ptr_factory_.GetWeakPtr(), callback), |
616 weak_ptr_factory_.GetWeakPtr(), callback), | |
617 base::Bind(&WebBluetoothServiceImpl::OnWriteValueFailed, | 617 base::Bind(&WebBluetoothServiceImpl::OnWriteValueFailed, |
618 weak_ptr_factory_.GetWeakPtr(), callback)); | 618 weak_ptr_factory_.GetWeakPtr(), callback)); |
619 } | 619 } |
620 | 620 |
621 void WebBluetoothServiceImpl::RemoteCharacteristicStartNotifications( | 621 void WebBluetoothServiceImpl::RemoteCharacteristicStartNotifications( |
622 const mojo::String& characteristic_instance_id, | 622 const std::string& characteristic_instance_id, |
623 const RemoteCharacteristicStartNotificationsCallback& callback) { | 623 const RemoteCharacteristicStartNotificationsCallback& callback) { |
624 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 624 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
625 RecordWebBluetoothFunctionCall( | 625 RecordWebBluetoothFunctionCall( |
626 UMAWebBluetoothFunction::CHARACTERISTIC_START_NOTIFICATIONS); | 626 UMAWebBluetoothFunction::CHARACTERISTIC_START_NOTIFICATIONS); |
627 | 627 |
628 auto iter = | 628 auto iter = |
629 characteristic_id_to_notify_session_.find(characteristic_instance_id); | 629 characteristic_id_to_notify_session_.find(characteristic_instance_id); |
630 if (iter != characteristic_id_to_notify_session_.end() && | 630 if (iter != characteristic_id_to_notify_session_.end() && |
631 iter->second->IsActive()) { | 631 iter->second->IsActive()) { |
632 // If the frame has already started notifications and the notifications | 632 // If the frame has already started notifications and the notifications |
(...skipping 25 matching lines...) Expand all Loading... | |
658 } | 658 } |
659 | 659 |
660 query_result.characteristic->StartNotifySession( | 660 query_result.characteristic->StartNotifySession( |
661 base::Bind(&WebBluetoothServiceImpl::OnStartNotifySessionSuccess, | 661 base::Bind(&WebBluetoothServiceImpl::OnStartNotifySessionSuccess, |
662 weak_ptr_factory_.GetWeakPtr(), callback), | 662 weak_ptr_factory_.GetWeakPtr(), callback), |
663 base::Bind(&WebBluetoothServiceImpl::OnStartNotifySessionFailed, | 663 base::Bind(&WebBluetoothServiceImpl::OnStartNotifySessionFailed, |
664 weak_ptr_factory_.GetWeakPtr(), callback)); | 664 weak_ptr_factory_.GetWeakPtr(), callback)); |
665 } | 665 } |
666 | 666 |
667 void WebBluetoothServiceImpl::RemoteCharacteristicStopNotifications( | 667 void WebBluetoothServiceImpl::RemoteCharacteristicStopNotifications( |
668 const mojo::String& characteristic_instance_id, | 668 const std::string& characteristic_instance_id, |
669 const RemoteCharacteristicStopNotificationsCallback& callback) { | 669 const RemoteCharacteristicStopNotificationsCallback& callback) { |
670 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 670 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
671 RecordWebBluetoothFunctionCall( | 671 RecordWebBluetoothFunctionCall( |
672 UMAWebBluetoothFunction::CHARACTERISTIC_STOP_NOTIFICATIONS); | 672 UMAWebBluetoothFunction::CHARACTERISTIC_STOP_NOTIFICATIONS); |
673 | 673 |
674 const CacheQueryResult query_result = | 674 const CacheQueryResult query_result = |
675 QueryCacheForCharacteristic(characteristic_instance_id); | 675 QueryCacheForCharacteristic(characteristic_instance_id); |
676 | 676 |
677 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 677 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
678 return; | 678 return; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
719 const base::Optional<BluetoothUUID>& services_uuid, | 719 const base::Optional<BluetoothUUID>& services_uuid, |
720 const RemoteServerGetPrimaryServicesCallback& callback, | 720 const RemoteServerGetPrimaryServicesCallback& callback, |
721 device::BluetoothDevice* device) { | 721 device::BluetoothDevice* device) { |
722 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 722 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
723 DCHECK(device->IsGattServicesDiscoveryComplete()); | 723 DCHECK(device->IsGattServicesDiscoveryComplete()); |
724 | 724 |
725 std::vector<device::BluetoothRemoteGattService*> services = | 725 std::vector<device::BluetoothRemoteGattService*> services = |
726 services_uuid ? GetPrimaryServicesByUUID(device, services_uuid.value()) | 726 services_uuid ? GetPrimaryServicesByUUID(device, services_uuid.value()) |
727 : GetPrimaryServices(device); | 727 : GetPrimaryServices(device); |
728 | 728 |
729 mojo::Array<blink::mojom::WebBluetoothRemoteGATTServicePtr> response_services; | 729 std::vector<blink::mojom::WebBluetoothRemoteGATTServicePtr> response_services; |
730 for (device::BluetoothRemoteGattService* service : services) { | 730 for (device::BluetoothRemoteGattService* service : services) { |
731 if (!allowed_devices_map_.IsOriginAllowedToAccessService( | 731 if (!allowed_devices_map_.IsOriginAllowedToAccessService( |
732 GetOrigin(), device_id, service->GetUUID())) { | 732 GetOrigin(), device_id, service->GetUUID())) { |
733 continue; | 733 continue; |
734 } | 734 } |
735 std::string service_instance_id = service->GetIdentifier(); | 735 std::string service_instance_id = service->GetIdentifier(); |
736 const std::string& device_address = device->GetAddress(); | 736 const std::string& device_address = device->GetAddress(); |
737 auto insert_result = service_id_to_device_address_.insert( | 737 auto insert_result = service_id_to_device_address_.insert( |
738 make_pair(service_instance_id, device_address)); | 738 make_pair(service_instance_id, device_address)); |
739 // If value is already in map, DCHECK it's valid. | 739 // If value is already in map, DCHECK it's valid. |
(...skipping 20 matching lines...) Expand all Loading... | |
760 return; | 760 return; |
761 } | 761 } |
762 | 762 |
763 VLOG(1) << "Services not found in device."; | 763 VLOG(1) << "Services not found in device."; |
764 RecordGetPrimaryServicesOutcome( | 764 RecordGetPrimaryServicesOutcome( |
765 quantity, services_uuid ? UMAGetPrimaryServiceOutcome::NOT_FOUND | 765 quantity, services_uuid ? UMAGetPrimaryServiceOutcome::NOT_FOUND |
766 : UMAGetPrimaryServiceOutcome::NO_SERVICES); | 766 : UMAGetPrimaryServiceOutcome::NO_SERVICES); |
767 callback.Run(services_uuid | 767 callback.Run(services_uuid |
768 ? blink::mojom::WebBluetoothResult::SERVICE_NOT_FOUND | 768 ? blink::mojom::WebBluetoothResult::SERVICE_NOT_FOUND |
769 : blink::mojom::WebBluetoothResult::NO_SERVICES_FOUND, | 769 : blink::mojom::WebBluetoothResult::NO_SERVICES_FOUND, |
770 nullptr /* services */); | 770 base::nullopt /* services */); |
771 } | 771 } |
772 | 772 |
773 void WebBluetoothServiceImpl::OnGetDeviceSuccess( | 773 void WebBluetoothServiceImpl::OnGetDeviceSuccess( |
774 const RequestDeviceCallback& callback, | 774 const RequestDeviceCallback& callback, |
775 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, | 775 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, |
776 const std::string& device_address) { | 776 const std::string& device_address) { |
777 device_chooser_controller_.reset(); | 777 device_chooser_controller_.reset(); |
778 | 778 |
779 const device::BluetoothDevice* const device = | 779 const device::BluetoothDevice* const device = |
780 GetAdapter()->GetDevice(device_address); | 780 GetAdapter()->GetDevice(device_address); |
781 if (device == nullptr) { | 781 if (device == nullptr) { |
782 VLOG(1) << "Device " << device_address << " no longer in adapter"; | 782 VLOG(1) << "Device " << device_address << " no longer in adapter"; |
783 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::CHOSEN_DEVICE_VANISHED); | 783 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::CHOSEN_DEVICE_VANISHED); |
784 callback.Run(blink::mojom::WebBluetoothResult::CHOSEN_DEVICE_VANISHED, | 784 callback.Run(blink::mojom::WebBluetoothResult::CHOSEN_DEVICE_VANISHED, |
785 nullptr /* device */); | 785 nullptr /* device */); |
786 return; | 786 return; |
787 } | 787 } |
788 | 788 |
789 const WebBluetoothDeviceId device_id_for_origin = | 789 const WebBluetoothDeviceId device_id_for_origin = |
790 allowed_devices_map_.AddDevice(GetOrigin(), device_address, options); | 790 allowed_devices_map_.AddDevice(GetOrigin(), device_address, options); |
791 | 791 |
792 VLOG(1) << "Device: " << device->GetNameForDisplay(); | 792 VLOG(1) << "Device: " << device->GetNameForDisplay(); |
793 | 793 |
794 blink::mojom::WebBluetoothDevicePtr device_ptr = | 794 blink::mojom::WebBluetoothDevicePtr device_ptr = |
795 blink::mojom::WebBluetoothDevice::New(); | 795 blink::mojom::WebBluetoothDevice::New(); |
796 device_ptr->id = device_id_for_origin; | 796 device_ptr->id = device_id_for_origin; |
797 device_ptr->name = device->GetName() ? mojo::String(device->GetName().value()) | 797 device_ptr->name = device->GetName(); |
798 : mojo::String(nullptr); | |
799 | 798 |
800 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::SUCCESS); | 799 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::SUCCESS); |
801 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, | 800 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, |
802 std::move(device_ptr)); | 801 std::move(device_ptr)); |
803 } | 802 } |
804 | 803 |
805 void WebBluetoothServiceImpl::OnGetDeviceFailed( | 804 void WebBluetoothServiceImpl::OnGetDeviceFailed( |
806 const RequestDeviceCallback& callback, | 805 const RequestDeviceCallback& callback, |
807 blink::mojom::WebBluetoothResult result) { | 806 blink::mojom::WebBluetoothResult result) { |
808 // Errors are recorded by the *device_chooser_controller_. | 807 // Errors are recorded by the *device_chooser_controller_. |
(...skipping 21 matching lines...) Expand all Loading... | |
830 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 829 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
831 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time); | 830 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time); |
832 callback.Run(TranslateConnectErrorAndRecord(error_code)); | 831 callback.Run(TranslateConnectErrorAndRecord(error_code)); |
833 } | 832 } |
834 | 833 |
835 void WebBluetoothServiceImpl::OnReadValueSuccess( | 834 void WebBluetoothServiceImpl::OnReadValueSuccess( |
836 const RemoteCharacteristicReadValueCallback& callback, | 835 const RemoteCharacteristicReadValueCallback& callback, |
837 const std::vector<uint8_t>& value) { | 836 const std::vector<uint8_t>& value) { |
838 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 837 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
839 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::SUCCESS); | 838 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::SUCCESS); |
840 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, | 839 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, value); |
841 mojo::Array<uint8_t>::From(value)); | |
842 } | 840 } |
843 | 841 |
844 void WebBluetoothServiceImpl::OnReadValueFailed( | 842 void WebBluetoothServiceImpl::OnReadValueFailed( |
845 const RemoteCharacteristicReadValueCallback& callback, | 843 const RemoteCharacteristicReadValueCallback& callback, |
846 device::BluetoothRemoteGattService::GattErrorCode error_code) { | 844 device::BluetoothRemoteGattService::GattErrorCode error_code) { |
847 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 845 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
848 callback.Run(TranslateGATTErrorAndRecord( | 846 callback.Run(TranslateGATTErrorAndRecord( |
849 error_code, UMAGATTOperation::CHARACTERISTIC_READ), | 847 error_code, UMAGATTOperation::CHARACTERISTIC_READ), |
850 nullptr /* value */); | 848 base::nullopt /* value */); |
851 } | 849 } |
852 | 850 |
853 void WebBluetoothServiceImpl::OnWriteValueSuccess( | 851 void WebBluetoothServiceImpl::OnWriteValueSuccess( |
854 const RemoteCharacteristicWriteValueCallback& callback) { | 852 const RemoteCharacteristicWriteValueCallback& callback) { |
855 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 853 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
856 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::SUCCESS); | 854 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::SUCCESS); |
857 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); | 855 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); |
858 } | 856 } |
859 | 857 |
860 void WebBluetoothServiceImpl::OnWriteValueFailed( | 858 void WebBluetoothServiceImpl::OnWriteValueFailed( |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1000 characteristic_id_to_service_id_.clear(); | 998 characteristic_id_to_service_id_.clear(); |
1001 service_id_to_device_address_.clear(); | 999 service_id_to_device_address_.clear(); |
1002 connected_devices_.reset( | 1000 connected_devices_.reset( |
1003 new FrameConnectedBluetoothDevices(render_frame_host_)); | 1001 new FrameConnectedBluetoothDevices(render_frame_host_)); |
1004 allowed_devices_map_ = BluetoothAllowedDevicesMap(); | 1002 allowed_devices_map_ = BluetoothAllowedDevicesMap(); |
1005 device_chooser_controller_.reset(); | 1003 device_chooser_controller_.reset(); |
1006 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); | 1004 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); |
1007 } | 1005 } |
1008 | 1006 |
1009 } // namespace content | 1007 } // namespace content |
OLD | NEW |