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

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

Issue 2015463004: bluetooth: Use BluetoothUUID instead of string when sending uuids (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-mojo-request-device
Patch Set: Lint Created 4 years, 6 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 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.
11 11
12 #include "content/browser/bluetooth/web_bluetooth_service_impl.h" 12 #include "content/browser/bluetooth/web_bluetooth_service_impl.h"
13 13
14 #include <algorithm> 14 #include <algorithm>
15 15
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
18 #include "content/browser/bluetooth/bluetooth_adapter_factory_wrapper.h" 18 #include "content/browser/bluetooth/bluetooth_adapter_factory_wrapper.h"
19 #include "content/browser/bluetooth/bluetooth_blacklist.h" 19 #include "content/browser/bluetooth/bluetooth_blacklist.h"
20 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h" 20 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h"
21 #include "content/browser/bluetooth/bluetooth_metrics.h" 21 #include "content/browser/bluetooth/bluetooth_metrics.h"
22 #include "content/browser/bluetooth/frame_connected_bluetooth_devices.h" 22 #include "content/browser/bluetooth/frame_connected_bluetooth_devices.h"
23 #include "content/browser/renderer_host/render_process_host_impl.h" 23 #include "content/browser/renderer_host/render_process_host_impl.h"
24 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/navigation_handle.h" 25 #include "content/public/browser/navigation_handle.h"
26 #include "content/public/browser/render_frame_host.h" 26 #include "content/public/browser/render_frame_host.h"
27 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
28 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" 28 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
29 29
30 using device::BluetoothUUID;
31
30 namespace content { 32 namespace content {
31 33
32 namespace { 34 namespace {
33 35
34 blink::mojom::WebBluetoothError TranslateConnectErrorAndRecord( 36 blink::mojom::WebBluetoothError TranslateConnectErrorAndRecord(
35 device::BluetoothDevice::ConnectErrorCode error_code) { 37 device::BluetoothDevice::ConnectErrorCode error_code) {
36 switch (error_code) { 38 switch (error_code) {
37 case device::BluetoothDevice::ERROR_UNKNOWN: 39 case device::BluetoothDevice::ERROR_UNKNOWN:
38 RecordConnectGATTOutcome(UMAConnectGATTOutcome::UNKNOWN); 40 RecordConnectGATTOutcome(UMAConnectGATTOutcome::UNKNOWN);
39 return blink::mojom::WebBluetoothError::CONNECT_UNKNOWN_ERROR; 41 return blink::mojom::WebBluetoothError::CONNECT_UNKNOWN_ERROR;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 return blink::mojom::WebBluetoothError::GATT_NOT_SUPPORTED; 125 return blink::mojom::WebBluetoothError::GATT_NOT_SUPPORTED;
124 } 126 }
125 NOTREACHED(); 127 NOTREACHED();
126 return blink::mojom::WebBluetoothError::GATT_UNTRANSLATED_ERROR_CODE; 128 return blink::mojom::WebBluetoothError::GATT_UNTRANSLATED_ERROR_CODE;
127 } 129 }
128 130
129 // TODO(ortuno): This should really be a BluetoothDevice method. 131 // TODO(ortuno): This should really be a BluetoothDevice method.
130 // Replace when implemented. http://crbug.com/552022 132 // Replace when implemented. http://crbug.com/552022
131 std::vector<device::BluetoothRemoteGattCharacteristic*> 133 std::vector<device::BluetoothRemoteGattCharacteristic*>
132 GetCharacteristicsByUUID(device::BluetoothRemoteGattService* service, 134 GetCharacteristicsByUUID(device::BluetoothRemoteGattService* service,
133 const std::string& characteristic_uuid) { 135 const BluetoothUUID& characteristic_uuid) {
134 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics; 136 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics;
135 VLOG(1) << "Looking for characteristic: " << characteristic_uuid; 137 VLOG(1) << "Looking for characteristic: "
138 << characteristic_uuid.canonical_value();
136 for (device::BluetoothRemoteGattCharacteristic* characteristic : 139 for (device::BluetoothRemoteGattCharacteristic* characteristic :
137 service->GetCharacteristics()) { 140 service->GetCharacteristics()) {
138 VLOG(1) << "Characteristic in cache: " 141 VLOG(1) << "Characteristic in cache: "
139 << characteristic->GetUUID().canonical_value(); 142 << characteristic->GetUUID().canonical_value();
140 if (characteristic->GetUUID().canonical_value() == characteristic_uuid) { 143 if (characteristic->GetUUID() == characteristic_uuid) {
141 characteristics.push_back(characteristic); 144 characteristics.push_back(characteristic);
142 } 145 }
143 } 146 }
144 return characteristics; 147 return characteristics;
145 } 148 }
146 149
147 // TODO(ortuno): This should really be a BluetoothDevice method. 150 // TODO(ortuno): This should really be a BluetoothDevice method.
148 // Replace when implemented. http://crbug.com/552022 151 // Replace when implemented. http://crbug.com/552022
149 std::vector<device::BluetoothRemoteGattService*> GetPrimaryServicesByUUID( 152 std::vector<device::BluetoothRemoteGattService*> GetPrimaryServicesByUUID(
150 device::BluetoothDevice* device, 153 device::BluetoothDevice* device,
151 const std::string& service_uuid) { 154 const BluetoothUUID& service_uuid) {
152 std::vector<device::BluetoothRemoteGattService*> services; 155 std::vector<device::BluetoothRemoteGattService*> services;
153 VLOG(1) << "Looking for service: " << service_uuid; 156 VLOG(1) << "Looking for service: " << service_uuid.canonical_value();
154 for (device::BluetoothRemoteGattService* service : 157 for (device::BluetoothRemoteGattService* service :
155 device->GetGattServices()) { 158 device->GetGattServices()) {
156 VLOG(1) << "Service in cache: " << service->GetUUID().canonical_value(); 159 VLOG(1) << "Service in cache: " << service->GetUUID().canonical_value();
157 if (service->GetUUID().canonical_value() == service_uuid && 160 if (service->GetUUID() == service_uuid && service->IsPrimary()) {
158 service->IsPrimary()) {
159 services.push_back(service); 161 services.push_back(service);
160 } 162 }
161 } 163 }
162 return services; 164 return services;
163 } 165 }
164 166
165 } // namespace 167 } // namespace
166 168
167 WebBluetoothServiceImpl::WebBluetoothServiceImpl( 169 WebBluetoothServiceImpl::WebBluetoothServiceImpl(
168 RenderFrameHost* render_frame_host, 170 RenderFrameHost* render_frame_host,
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 UMAWebBluetoothFunction::REMOTE_GATT_SERVER_DISCONNECT); 359 UMAWebBluetoothFunction::REMOTE_GATT_SERVER_DISCONNECT);
358 360
359 if (connected_devices_->IsConnectedToDeviceWithId(device_id)) { 361 if (connected_devices_->IsConnectedToDeviceWithId(device_id)) {
360 VLOG(1) << "Disconnecting device: " << device_id; 362 VLOG(1) << "Disconnecting device: " << device_id;
361 connected_devices_->CloseConnectionToDeviceWithId(device_id); 363 connected_devices_->CloseConnectionToDeviceWithId(device_id);
362 } 364 }
363 } 365 }
364 366
365 void WebBluetoothServiceImpl::RemoteServerGetPrimaryService( 367 void WebBluetoothServiceImpl::RemoteServerGetPrimaryService(
366 const mojo::String& device_id, 368 const mojo::String& device_id,
367 const mojo::String& service_uuid, 369 const std::unique_ptr<BluetoothUUID>& service_uuid,
368 const RemoteServerGetPrimaryServiceCallback& callback) { 370 const RemoteServerGetPrimaryServiceCallback& callback) {
369 DCHECK_CURRENTLY_ON(BrowserThread::UI); 371 DCHECK_CURRENTLY_ON(BrowserThread::UI);
372
370 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_PRIMARY_SERVICE); 373 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_PRIMARY_SERVICE);
371 RecordGetPrimaryServiceService(device::BluetoothUUID(service_uuid)); 374 RecordGetPrimaryServiceService(service_uuid);
372 375
373 if (!allowed_devices_map_.IsOriginAllowedToAccessService( 376 if (!allowed_devices_map_.IsOriginAllowedToAccessService(
374 GetOrigin(), device_id, service_uuid)) { 377 GetOrigin(), device_id, *service_uuid)) {
375 callback.Run(blink::mojom::WebBluetoothError::NOT_ALLOWED_TO_ACCESS_SERVICE, 378 callback.Run(blink::mojom::WebBluetoothError::NOT_ALLOWED_TO_ACCESS_SERVICE,
376 nullptr /* service */); 379 nullptr /* service */);
377 return; 380 return;
378 } 381 }
379 382
380 const CacheQueryResult query_result = QueryCacheForDevice(device_id); 383 const CacheQueryResult query_result = QueryCacheForDevice(device_id);
381 384
382 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { 385 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) {
383 binding_.Close(); 386 binding_.Close();
384 return; 387 return;
385 } 388 }
386 389
387 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { 390 if (query_result.outcome != CacheQueryOutcome::SUCCESS) {
388 RecordGetPrimaryServiceOutcome(query_result.outcome); 391 RecordGetPrimaryServiceOutcome(query_result.outcome);
389 callback.Run(query_result.GetWebError(), nullptr /* service */); 392 callback.Run(query_result.GetWebError(), nullptr /* service */);
390 return; 393 return;
391 } 394 }
392 395
393 const std::string& device_address = query_result.device->GetAddress(); 396 const std::string& device_address = query_result.device->GetAddress();
394 397
395 // We can't know if a service is present or not until GATT service discovery 398 // We can't know if a service is present or not until GATT service discovery
396 // is complete for the device. 399 // is complete for the device.
397 if (query_result.device->IsGattServicesDiscoveryComplete()) { 400 if (query_result.device->IsGattServicesDiscoveryComplete()) {
398 RemoteServerGetPrimaryServiceImpl(service_uuid, callback, 401 RemoteServerGetPrimaryServiceImpl(
399 query_result.device); 402 base::WrapUnique(new BluetoothUUID(*service_uuid)), callback,
403 query_result.device);
400 return; 404 return;
401 } 405 }
402 406
403 VLOG(1) << "Services not yet discovered."; 407 VLOG(1) << "Services not yet discovered.";
404 pending_primary_services_requests_[device_address].push_back( 408 pending_primary_services_requests_[device_address].push_back(base::Bind(
405 base::Bind(&WebBluetoothServiceImpl::RemoteServerGetPrimaryServiceImpl, 409 &WebBluetoothServiceImpl::RemoteServerGetPrimaryServiceImpl,
406 base::Unretained(this), service_uuid, callback)); 410 base::Unretained(this),
411 base::Passed(base::WrapUnique(new BluetoothUUID(*service_uuid))),
412 callback));
407 } 413 }
408 414
409 void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics( 415 void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics(
410 const mojo::String& service_instance_id, 416 const mojo::String& service_instance_id,
411 blink::mojom::WebBluetoothGATTQueryQuantity quantity, 417 blink::mojom::WebBluetoothGATTQueryQuantity quantity,
412 const mojo::String& characteristics_uuid, 418 const std::unique_ptr<BluetoothUUID>& characteristics_uuid,
413 const RemoteServiceGetCharacteristicsCallback& callback) { 419 const RemoteServiceGetCharacteristicsCallback& callback) {
414 DCHECK_CURRENTLY_ON(BrowserThread::UI); 420 DCHECK_CURRENTLY_ON(BrowserThread::UI);
421
415 RecordWebBluetoothFunctionCall( 422 RecordWebBluetoothFunctionCall(
416 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE 423 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE
417 ? UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTIC 424 ? UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTIC
418 : UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTICS); 425 : UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTICS);
419 RecordGetCharacteristicsCharacteristic(quantity, characteristics_uuid); 426 RecordGetCharacteristicsCharacteristic(quantity, characteristics_uuid);
420 427
421 if (!characteristics_uuid.is_null() && 428 if (characteristics_uuid.get() &&
Jeffrey Yasskin 2016/05/28 04:38:06 unique_ptr and base::Optional can be directly used
ortuno 2016/05/31 17:30:47 I think that .get() is more explicit, but I've bee
Jeffrey Yasskin 2016/05/31 21:52:57 I'm totally happy with things like "!= nullptr" or
422 BluetoothBlacklist::Get().IsExcluded( 429 BluetoothBlacklist::Get().IsExcluded(*characteristics_uuid)) {
423 device::BluetoothUUID(characteristics_uuid))) {
424 RecordGetCharacteristicsOutcome(quantity, 430 RecordGetCharacteristicsOutcome(quantity,
425 UMAGetCharacteristicOutcome::BLACKLISTED); 431 UMAGetCharacteristicOutcome::BLACKLISTED);
426 callback.Run( 432 callback.Run(
427 blink::mojom::WebBluetoothError::BLACKLISTED_CHARACTERISTIC_UUID, 433 blink::mojom::WebBluetoothError::BLACKLISTED_CHARACTERISTIC_UUID,
428 nullptr /* characteristics */); 434 nullptr /* characteristics */);
429 return; 435 return;
430 } 436 }
431 437
432 const CacheQueryResult query_result = 438 const CacheQueryResult query_result =
433 QueryCacheForService(service_instance_id); 439 QueryCacheForService(service_instance_id);
434 440
435 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { 441 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) {
436 binding_.Close(); 442 binding_.Close();
437 return; 443 return;
438 } 444 }
439 445
440 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { 446 if (query_result.outcome != CacheQueryOutcome::SUCCESS) {
441 RecordGetCharacteristicsOutcome(quantity, query_result.outcome); 447 RecordGetCharacteristicsOutcome(quantity, query_result.outcome);
442 callback.Run(query_result.GetWebError(), nullptr /* characteristics */); 448 callback.Run(query_result.GetWebError(), nullptr /* characteristics */);
443 return; 449 return;
444 } 450 }
445 451
446 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics = 452 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics =
447 characteristics_uuid.is_null() 453 characteristics_uuid.get()
448 ? query_result.service->GetCharacteristics() 454 ? GetCharacteristicsByUUID(query_result.service,
449 : GetCharacteristicsByUUID(query_result.service, 455 *characteristics_uuid)
450 characteristics_uuid); 456 : query_result.service->GetCharacteristics();
451 457
452 mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> 458 mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr>
453 response_characteristics; 459 response_characteristics;
454 for (device::BluetoothRemoteGattCharacteristic* characteristic : 460 for (device::BluetoothRemoteGattCharacteristic* characteristic :
455 characteristics) { 461 characteristics) {
456 if (BluetoothBlacklist::Get().IsExcluded(characteristic->GetUUID())) { 462 if (BluetoothBlacklist::Get().IsExcluded(characteristic->GetUUID())) {
457 continue; 463 continue;
458 } 464 }
459 std::string characteristic_instance_id = characteristic->GetIdentifier(); 465 std::string characteristic_instance_id = characteristic->GetIdentifier();
460 auto insert_result = characteristic_id_to_service_id_.insert( 466 auto insert_result = characteristic_id_to_service_id_.insert(
(...skipping 15 matching lines...) Expand all
476 } 482 }
477 } 483 }
478 484
479 if (!response_characteristics.empty()) { 485 if (!response_characteristics.empty()) {
480 RecordGetCharacteristicsOutcome(quantity, 486 RecordGetCharacteristicsOutcome(quantity,
481 UMAGetCharacteristicOutcome::SUCCESS); 487 UMAGetCharacteristicOutcome::SUCCESS);
482 callback.Run(blink::mojom::WebBluetoothError::SUCCESS, 488 callback.Run(blink::mojom::WebBluetoothError::SUCCESS,
483 std::move(response_characteristics)); 489 std::move(response_characteristics));
484 return; 490 return;
485 } 491 }
492
486 RecordGetCharacteristicsOutcome( 493 RecordGetCharacteristicsOutcome(
487 quantity, characteristics_uuid.is_null() 494 quantity, characteristics_uuid.get()
488 ? UMAGetCharacteristicOutcome::NO_CHARACTERISTICS 495 ? UMAGetCharacteristicOutcome::NOT_FOUND
489 : UMAGetCharacteristicOutcome::NOT_FOUND); 496 : UMAGetCharacteristicOutcome::NO_CHARACTERISTICS);
490 callback.Run(characteristics_uuid.is_null() 497 callback.Run(characteristics_uuid.get()
491 ? blink::mojom::WebBluetoothError::NO_CHARACTERISTICS_FOUND 498 ? blink::mojom::WebBluetoothError::CHARACTERISTIC_NOT_FOUND
492 : blink::mojom::WebBluetoothError::CHARACTERISTIC_NOT_FOUND, 499 : blink::mojom::WebBluetoothError::NO_CHARACTERISTICS_FOUND,
493 nullptr /* characteristics */); 500 nullptr /* characteristics */);
494 return; 501 return;
495 } 502 }
496 503
497 void WebBluetoothServiceImpl::RemoteCharacteristicReadValue( 504 void WebBluetoothServiceImpl::RemoteCharacteristicReadValue(
498 const mojo::String& characteristic_instance_id, 505 const mojo::String& characteristic_instance_id,
499 const RemoteCharacteristicReadValueCallback& callback) { 506 const RemoteCharacteristicReadValueCallback& callback) {
500 DCHECK_CURRENTLY_ON(BrowserThread::UI); 507 DCHECK_CURRENTLY_ON(BrowserThread::UI);
501 RecordWebBluetoothFunctionCall( 508 RecordWebBluetoothFunctionCall(
502 UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE); 509 UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 668
662 device_chooser_controller_->GetDevice( 669 device_chooser_controller_->GetDevice(
663 std::move(options), 670 std::move(options),
664 base::Bind(&WebBluetoothServiceImpl::OnGetDeviceSuccess, 671 base::Bind(&WebBluetoothServiceImpl::OnGetDeviceSuccess,
665 weak_ptr_factory_.GetWeakPtr(), callback), 672 weak_ptr_factory_.GetWeakPtr(), callback),
666 base::Bind(&WebBluetoothServiceImpl::OnGetDeviceFailed, 673 base::Bind(&WebBluetoothServiceImpl::OnGetDeviceFailed,
667 weak_ptr_factory_.GetWeakPtr(), callback)); 674 weak_ptr_factory_.GetWeakPtr(), callback));
668 } 675 }
669 676
670 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServiceImpl( 677 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServiceImpl(
671 const std::string& service_uuid, 678 std::unique_ptr<BluetoothUUID> service_uuid,
672 const RemoteServerGetPrimaryServiceCallback& callback, 679 const RemoteServerGetPrimaryServiceCallback& callback,
673 device::BluetoothDevice* device) { 680 device::BluetoothDevice* device) {
674 DCHECK_CURRENTLY_ON(BrowserThread::UI); 681 DCHECK_CURRENTLY_ON(BrowserThread::UI);
675 DCHECK(device->IsGattServicesDiscoveryComplete()); 682 DCHECK(device->IsGattServicesDiscoveryComplete());
676 683
677 std::vector<device::BluetoothRemoteGattService*> services = 684 std::vector<device::BluetoothRemoteGattService*> services =
678 GetPrimaryServicesByUUID(device, service_uuid); 685 GetPrimaryServicesByUUID(device, *service_uuid);
679 686
680 if (services.empty()) { 687 if (services.empty()) {
681 VLOG(1) << "Service not found in device."; 688 VLOG(1) << "Service not found in device.";
682 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND); 689 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND);
683 callback.Run(blink::mojom::WebBluetoothError::SERVICE_NOT_FOUND, 690 callback.Run(blink::mojom::WebBluetoothError::SERVICE_NOT_FOUND,
684 nullptr /* service */); 691 nullptr /* service */);
685 return; 692 return;
686 } 693 }
687 694
688 VLOG(1) << "Service found in device."; 695 VLOG(1) << "Service found in device.";
(...skipping 29 matching lines...) Expand all
718 return; 725 return;
719 } 726 }
720 727
721 const std::string device_id_for_origin = 728 const std::string device_id_for_origin =
722 allowed_devices_map_.AddDevice(GetOrigin(), device_address, options); 729 allowed_devices_map_.AddDevice(GetOrigin(), device_address, options);
723 730
724 VLOG(1) << "Device: " << device->GetName(); 731 VLOG(1) << "Device: " << device->GetName();
725 VLOG(1) << "UUIDs: "; 732 VLOG(1) << "UUIDs: ";
726 733
727 mojo::Array<mojo::String> filtered_uuids; 734 mojo::Array<mojo::String> filtered_uuids;
728 for (const device::BluetoothUUID& uuid : device->GetUUIDs()) { 735 for (const BluetoothUUID& uuid : device->GetUUIDs()) {
729 if (allowed_devices_map_.IsOriginAllowedToAccessService( 736 if (allowed_devices_map_.IsOriginAllowedToAccessService(
730 GetOrigin(), device_id_for_origin, uuid.canonical_value())) { 737 GetOrigin(), device_id_for_origin, uuid)) {
731 VLOG(1) << "\t Allowed: " << uuid.canonical_value(); 738 VLOG(1) << "\t Allowed: " << uuid.canonical_value();
732 filtered_uuids.push_back(uuid.canonical_value()); 739 filtered_uuids.push_back(uuid.canonical_value());
733 } else { 740 } else {
734 VLOG(1) << "\t Not Allowed: " << uuid.canonical_value(); 741 VLOG(1) << "\t Not Allowed: " << uuid.canonical_value();
735 } 742 }
736 } 743 }
737 744
738 blink::mojom::WebBluetoothDevicePtr device_ptr = 745 blink::mojom::WebBluetoothDevicePtr device_ptr =
739 blink::mojom::WebBluetoothDevice::New(); 746 blink::mojom::WebBluetoothDevice::New();
740 device_ptr->id = device_id_for_origin; 747 device_ptr->id = device_id_for_origin;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 886
880 CacheQueryResult result = QueryCacheForDevice(device_id); 887 CacheQueryResult result = QueryCacheForDevice(device_id);
881 if (result.outcome != CacheQueryOutcome::SUCCESS) { 888 if (result.outcome != CacheQueryOutcome::SUCCESS) {
882 return result; 889 return result;
883 } 890 }
884 891
885 result.service = result.device->GetGattService(service_instance_id); 892 result.service = result.device->GetGattService(service_instance_id);
886 if (result.service == nullptr) { 893 if (result.service == nullptr) {
887 result.outcome = CacheQueryOutcome::NO_SERVICE; 894 result.outcome = CacheQueryOutcome::NO_SERVICE;
888 } else if (!allowed_devices_map_.IsOriginAllowedToAccessService( 895 } else if (!allowed_devices_map_.IsOriginAllowedToAccessService(
889 GetOrigin(), device_id, 896 GetOrigin(), device_id, result.service->GetUUID())) {
890 result.service->GetUUID().canonical_value())) {
891 CrashRendererAndClosePipe(bad_message::BDH_SERVICE_NOT_ALLOWED_FOR_ORIGIN); 897 CrashRendererAndClosePipe(bad_message::BDH_SERVICE_NOT_ALLOWED_FOR_ORIGIN);
892 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER); 898 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
893 } 899 }
894 return result; 900 return result;
895 } 901 }
896 902
897 CacheQueryResult WebBluetoothServiceImpl::QueryCacheForCharacteristic( 903 CacheQueryResult WebBluetoothServiceImpl::QueryCacheForCharacteristic(
898 const std::string& characteristic_instance_id) { 904 const std::string& characteristic_instance_id) {
899 auto characteristic_iter = 905 auto characteristic_iter =
900 characteristic_id_to_service_id_.find(characteristic_instance_id); 906 characteristic_id_to_service_id_.find(characteristic_instance_id);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 characteristic_id_to_service_id_.clear(); 958 characteristic_id_to_service_id_.clear();
953 service_id_to_device_address_.clear(); 959 service_id_to_device_address_.clear();
954 connected_devices_.reset( 960 connected_devices_.reset(
955 new FrameConnectedBluetoothDevices(render_frame_host_)); 961 new FrameConnectedBluetoothDevices(render_frame_host_));
956 allowed_devices_map_ = BluetoothAllowedDevicesMap(); 962 allowed_devices_map_ = BluetoothAllowedDevicesMap();
957 device_chooser_controller_.reset(); 963 device_chooser_controller_.reset();
958 GetBluetoothAdapterFactoryWrapper()->ReleaseAdapter(this); 964 GetBluetoothAdapterFactoryWrapper()->ReleaseAdapter(this);
959 } 965 }
960 966
961 } // namespace content 967 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698