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

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

Issue 2019853002: bluetooth: Use WebBluetoothDeviceId instead of string (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-uuid-typemap
Patch Set: Rebase Created 4 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
« no previous file with comments | « content/browser/bluetooth/web_bluetooth_service_impl.h ('k') | content/common/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_blacklist.h" 18 #include "content/browser/bluetooth/bluetooth_blacklist.h"
19 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h" 19 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h"
20 #include "content/browser/bluetooth/bluetooth_metrics.h" 20 #include "content/browser/bluetooth/bluetooth_metrics.h"
21 #include "content/browser/bluetooth/frame_connected_bluetooth_devices.h" 21 #include "content/browser/bluetooth/frame_connected_bluetooth_devices.h"
22 #include "content/browser/renderer_host/render_process_host_impl.h" 22 #include "content/browser/renderer_host/render_process_host_impl.h"
23 #include "content/common/bluetooth/web_bluetooth_device_id.h"
23 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/navigation_handle.h" 25 #include "content/public/browser/navigation_handle.h"
25 #include "content/public/browser/render_frame_host.h" 26 #include "content/public/browser/render_frame_host.h"
26 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
27 #include "device/bluetooth/bluetooth_adapter_factory_wrapper.h" 28 #include "device/bluetooth/bluetooth_adapter_factory_wrapper.h"
28 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" 29 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
29 30
30 using device::BluetoothAdapterFactoryWrapper; 31 using device::BluetoothAdapterFactoryWrapper;
31 using device::BluetoothUUID; 32 using device::BluetoothUUID;
32 33
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 VLOG(1) << "Adding device to device chooser controller: " 231 VLOG(1) << "Adding device to device chooser controller: "
231 << device->GetAddress(); 232 << device->GetAddress();
232 device_chooser_controller_->AddFilteredDevice(*device); 233 device_chooser_controller_->AddFilteredDevice(*device);
233 } 234 }
234 } 235 }
235 236
236 void WebBluetoothServiceImpl::DeviceChanged(device::BluetoothAdapter* adapter, 237 void WebBluetoothServiceImpl::DeviceChanged(device::BluetoothAdapter* adapter,
237 device::BluetoothDevice* device) { 238 device::BluetoothDevice* device) {
238 DCHECK_CURRENTLY_ON(BrowserThread::UI); 239 DCHECK_CURRENTLY_ON(BrowserThread::UI);
239 if (!device->IsGattConnected()) { 240 if (!device->IsGattConnected()) {
240 std::string device_id = 241 base::Optional<WebBluetoothDeviceId> device_id =
241 connected_devices_->CloseConnectionToDeviceWithAddress( 242 connected_devices_->CloseConnectionToDeviceWithAddress(
242 device->GetAddress()); 243 device->GetAddress());
243 if (!device_id.empty()) { 244 if (device_id && client_) {
244 if (client_) { 245 client_->GattServerDisconnected(device_id.value());
245 client_->GattServerDisconnected(device_id);
246 }
247 } 246 }
248 } 247 }
249 } 248 }
250 249
251 void WebBluetoothServiceImpl::GattServicesDiscovered( 250 void WebBluetoothServiceImpl::GattServicesDiscovered(
252 device::BluetoothAdapter* adapter, 251 device::BluetoothAdapter* adapter,
253 device::BluetoothDevice* device) { 252 device::BluetoothDevice* device) {
254 DCHECK_CURRENTLY_ON(BrowserThread::UI); 253 DCHECK_CURRENTLY_ON(BrowserThread::UI);
255 const std::string& device_address = device->GetAddress(); 254 const std::string& device_address = device->GetAddress();
256 VLOG(1) << "Services discovered for device: " << device_address; 255 VLOG(1) << "Services discovered for device: " << device_address;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 323 }
325 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER); 324 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER);
326 callback.Run(blink::mojom::WebBluetoothError::NO_BLUETOOTH_ADAPTER, 325 callback.Run(blink::mojom::WebBluetoothError::NO_BLUETOOTH_ADAPTER,
327 nullptr /* device */); 326 nullptr /* device */);
328 return; 327 return;
329 } 328 }
330 RequestDeviceImpl(std::move(options), callback, GetAdapter()); 329 RequestDeviceImpl(std::move(options), callback, GetAdapter());
331 } 330 }
332 331
333 void WebBluetoothServiceImpl::RemoteServerConnect( 332 void WebBluetoothServiceImpl::RemoteServerConnect(
334 const mojo::String& device_id, 333 const WebBluetoothDeviceId& device_id,
335 const RemoteServerConnectCallback& callback) { 334 const RemoteServerConnectCallback& callback) {
336 DCHECK_CURRENTLY_ON(BrowserThread::UI); 335 DCHECK_CURRENTLY_ON(BrowserThread::UI);
337 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::CONNECT_GATT); 336 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::CONNECT_GATT);
338 337
339 const CacheQueryResult query_result = QueryCacheForDevice(device_id); 338 const CacheQueryResult query_result = QueryCacheForDevice(device_id);
340 339
341 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { 340 if (query_result.outcome != CacheQueryOutcome::SUCCESS) {
342 RecordConnectGATTOutcome(query_result.outcome); 341 RecordConnectGATTOutcome(query_result.outcome);
343 callback.Run(query_result.GetWebError()); 342 callback.Run(query_result.GetWebError());
344 return; 343 return;
(...skipping 13 matching lines...) Expand all
358 // abstraction doesn't currently support checking for pending connections. 357 // abstraction doesn't currently support checking for pending connections.
359 // TODO(ortuno): CHECK that this never happens once the platform 358 // TODO(ortuno): CHECK that this never happens once the platform
360 // abstraction allows to check for pending connections. 359 // abstraction allows to check for pending connections.
361 // http://crbug.com/583544 360 // http://crbug.com/583544
362 const base::TimeTicks start_time = base::TimeTicks::Now(); 361 const base::TimeTicks start_time = base::TimeTicks::Now();
363 query_result.device->CreateGattConnection( 362 query_result.device->CreateGattConnection(
364 base::Bind(&WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess, 363 base::Bind(&WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess,
365 weak_ptr_factory_.GetWeakPtr(), device_id, start_time, 364 weak_ptr_factory_.GetWeakPtr(), device_id, start_time,
366 callback), 365 callback),
367 base::Bind(&WebBluetoothServiceImpl::OnCreateGATTConnectionFailed, 366 base::Bind(&WebBluetoothServiceImpl::OnCreateGATTConnectionFailed,
368 weak_ptr_factory_.GetWeakPtr(), device_id, start_time, 367 weak_ptr_factory_.GetWeakPtr(), start_time, callback));
369 callback));
370 } 368 }
371 369
372 void WebBluetoothServiceImpl::RemoteServerDisconnect( 370 void WebBluetoothServiceImpl::RemoteServerDisconnect(
373 const mojo::String& device_id) { 371 const WebBluetoothDeviceId& device_id) {
374 DCHECK_CURRENTLY_ON(BrowserThread::UI); 372 DCHECK_CURRENTLY_ON(BrowserThread::UI);
375 RecordWebBluetoothFunctionCall( 373 RecordWebBluetoothFunctionCall(
376 UMAWebBluetoothFunction::REMOTE_GATT_SERVER_DISCONNECT); 374 UMAWebBluetoothFunction::REMOTE_GATT_SERVER_DISCONNECT);
377 375
378 if (connected_devices_->IsConnectedToDeviceWithId(device_id)) { 376 if (connected_devices_->IsConnectedToDeviceWithId(device_id)) {
379 VLOG(1) << "Disconnecting device: " << device_id; 377 VLOG(1) << "Disconnecting device: " << device_id.str();
380 connected_devices_->CloseConnectionToDeviceWithId(device_id); 378 connected_devices_->CloseConnectionToDeviceWithId(device_id);
381 } 379 }
382 } 380 }
383 381
384 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices( 382 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices(
385 const mojo::String& device_id, 383 const WebBluetoothDeviceId& device_id,
386 blink::mojom::WebBluetoothGATTQueryQuantity quantity, 384 blink::mojom::WebBluetoothGATTQueryQuantity quantity,
387 const base::Optional<BluetoothUUID>& services_uuid, 385 const base::Optional<BluetoothUUID>& services_uuid,
388 const RemoteServerGetPrimaryServicesCallback& callback) { 386 const RemoteServerGetPrimaryServicesCallback& callback) {
389 DCHECK_CURRENTLY_ON(BrowserThread::UI); 387 DCHECK_CURRENTLY_ON(BrowserThread::UI);
390 RecordWebBluetoothFunctionCall( 388 RecordWebBluetoothFunctionCall(
391 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE 389 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE
392 ? UMAWebBluetoothFunction::GET_PRIMARY_SERVICE 390 ? UMAWebBluetoothFunction::GET_PRIMARY_SERVICE
393 : UMAWebBluetoothFunction::GET_PRIMARY_SERVICES); 391 : UMAWebBluetoothFunction::GET_PRIMARY_SERVICES);
394 RecordGetPrimaryServicesServices(quantity, services_uuid); 392 RecordGetPrimaryServicesServices(quantity, services_uuid);
395 393
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 682
685 device_chooser_controller_->GetDevice( 683 device_chooser_controller_->GetDevice(
686 std::move(options), 684 std::move(options),
687 base::Bind(&WebBluetoothServiceImpl::OnGetDeviceSuccess, 685 base::Bind(&WebBluetoothServiceImpl::OnGetDeviceSuccess,
688 weak_ptr_factory_.GetWeakPtr(), callback), 686 weak_ptr_factory_.GetWeakPtr(), callback),
689 base::Bind(&WebBluetoothServiceImpl::OnGetDeviceFailed, 687 base::Bind(&WebBluetoothServiceImpl::OnGetDeviceFailed,
690 weak_ptr_factory_.GetWeakPtr(), callback)); 688 weak_ptr_factory_.GetWeakPtr(), callback));
691 } 689 }
692 690
693 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl( 691 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl(
694 const mojo::String& device_id, 692 const WebBluetoothDeviceId& device_id,
695 blink::mojom::WebBluetoothGATTQueryQuantity quantity, 693 blink::mojom::WebBluetoothGATTQueryQuantity quantity,
696 const base::Optional<BluetoothUUID>& services_uuid, 694 const base::Optional<BluetoothUUID>& services_uuid,
697 const RemoteServerGetPrimaryServicesCallback& callback, 695 const RemoteServerGetPrimaryServicesCallback& callback,
698 device::BluetoothDevice* device) { 696 device::BluetoothDevice* device) {
699 DCHECK_CURRENTLY_ON(BrowserThread::UI); 697 DCHECK_CURRENTLY_ON(BrowserThread::UI);
700 DCHECK(device->IsGattServicesDiscoveryComplete()); 698 DCHECK(device->IsGattServicesDiscoveryComplete());
701 699
702 std::vector<device::BluetoothRemoteGattService*> services = 700 std::vector<device::BluetoothRemoteGattService*> services =
703 services_uuid ? GetPrimaryServicesByUUID(device, services_uuid.value()) 701 services_uuid ? GetPrimaryServicesByUUID(device, services_uuid.value())
704 : GetPrimaryServices(device); 702 : GetPrimaryServices(device);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 const device::BluetoothDevice* const device = 754 const device::BluetoothDevice* const device =
757 GetAdapter()->GetDevice(device_address); 755 GetAdapter()->GetDevice(device_address);
758 if (device == nullptr) { 756 if (device == nullptr) {
759 VLOG(1) << "Device " << device_address << " no longer in adapter"; 757 VLOG(1) << "Device " << device_address << " no longer in adapter";
760 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::CHOSEN_DEVICE_VANISHED); 758 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::CHOSEN_DEVICE_VANISHED);
761 callback.Run(blink::mojom::WebBluetoothError::CHOSEN_DEVICE_VANISHED, 759 callback.Run(blink::mojom::WebBluetoothError::CHOSEN_DEVICE_VANISHED,
762 nullptr /* device */); 760 nullptr /* device */);
763 return; 761 return;
764 } 762 }
765 763
766 const std::string device_id_for_origin = 764 const WebBluetoothDeviceId device_id_for_origin =
767 allowed_devices_map_.AddDevice(GetOrigin(), device_address, options); 765 allowed_devices_map_.AddDevice(GetOrigin(), device_address, options);
768 766
769 VLOG(1) << "Device: " << device->GetNameForDisplay(); 767 VLOG(1) << "Device: " << device->GetNameForDisplay();
770 VLOG(1) << "UUIDs: "; 768 VLOG(1) << "UUIDs: ";
771 769
772 mojo::Array<mojo::String> filtered_uuids; 770 mojo::Array<mojo::String> filtered_uuids;
773 for (const BluetoothUUID& uuid : device->GetUUIDs()) { 771 for (const BluetoothUUID& uuid : device->GetUUIDs()) {
774 if (allowed_devices_map_.IsOriginAllowedToAccessService( 772 if (allowed_devices_map_.IsOriginAllowedToAccessService(
775 GetOrigin(), device_id_for_origin, uuid)) { 773 GetOrigin(), device_id_for_origin, uuid)) {
776 VLOG(1) << "\t Allowed: " << uuid.canonical_value(); 774 VLOG(1) << "\t Allowed: " << uuid.canonical_value();
(...skipping 16 matching lines...) Expand all
793 791
794 void WebBluetoothServiceImpl::OnGetDeviceFailed( 792 void WebBluetoothServiceImpl::OnGetDeviceFailed(
795 const RequestDeviceCallback& callback, 793 const RequestDeviceCallback& callback,
796 blink::mojom::WebBluetoothError error) { 794 blink::mojom::WebBluetoothError error) {
797 // Errors are recorded by the *device_chooser_controller_. 795 // Errors are recorded by the *device_chooser_controller_.
798 callback.Run(error, nullptr /* device */); 796 callback.Run(error, nullptr /* device */);
799 device_chooser_controller_.reset(); 797 device_chooser_controller_.reset();
800 } 798 }
801 799
802 void WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess( 800 void WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess(
803 const std::string& device_id, 801 const WebBluetoothDeviceId& device_id,
804 base::TimeTicks start_time, 802 base::TimeTicks start_time,
805 const RemoteServerConnectCallback& callback, 803 const RemoteServerConnectCallback& callback,
806 std::unique_ptr<device::BluetoothGattConnection> connection) { 804 std::unique_ptr<device::BluetoothGattConnection> connection) {
807 DCHECK_CURRENTLY_ON(BrowserThread::UI); 805 DCHECK_CURRENTLY_ON(BrowserThread::UI);
808 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time); 806 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time);
809 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS); 807 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS);
810 808
811 connected_devices_->Insert(device_id, std::move(connection)); 809 connected_devices_->Insert(device_id, std::move(connection));
812 callback.Run(blink::mojom::WebBluetoothError::SUCCESS); 810 callback.Run(blink::mojom::WebBluetoothError::SUCCESS);
813 } 811 }
814 812
815 void WebBluetoothServiceImpl::OnCreateGATTConnectionFailed( 813 void WebBluetoothServiceImpl::OnCreateGATTConnectionFailed(
816 const std::string& device_id,
817 base::TimeTicks start_time, 814 base::TimeTicks start_time,
818 const RemoteServerConnectCallback& callback, 815 const RemoteServerConnectCallback& callback,
819 device::BluetoothDevice::ConnectErrorCode error_code) { 816 device::BluetoothDevice::ConnectErrorCode error_code) {
820 DCHECK_CURRENTLY_ON(BrowserThread::UI); 817 DCHECK_CURRENTLY_ON(BrowserThread::UI);
821 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time); 818 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time);
822 callback.Run(TranslateConnectErrorAndRecord(error_code)); 819 callback.Run(TranslateConnectErrorAndRecord(error_code));
823 } 820 }
824 821
825 void WebBluetoothServiceImpl::OnReadValueSuccess( 822 void WebBluetoothServiceImpl::OnReadValueSuccess(
826 const RemoteCharacteristicReadValueCallback& callback, 823 const RemoteCharacteristicReadValueCallback& callback,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 } 875 }
879 876
880 void WebBluetoothServiceImpl::OnStopNotifySessionComplete( 877 void WebBluetoothServiceImpl::OnStopNotifySessionComplete(
881 const std::string& characteristic_instance_id, 878 const std::string& characteristic_instance_id,
882 const RemoteCharacteristicStopNotificationsCallback& callback) { 879 const RemoteCharacteristicStopNotificationsCallback& callback) {
883 characteristic_id_to_notify_session_.erase(characteristic_instance_id); 880 characteristic_id_to_notify_session_.erase(characteristic_instance_id);
884 callback.Run(); 881 callback.Run();
885 } 882 }
886 883
887 CacheQueryResult WebBluetoothServiceImpl::QueryCacheForDevice( 884 CacheQueryResult WebBluetoothServiceImpl::QueryCacheForDevice(
888 const std::string& device_id) { 885 const WebBluetoothDeviceId& device_id) {
889 const std::string& device_address = 886 const std::string& device_address =
890 allowed_devices_map_.GetDeviceAddress(GetOrigin(), device_id); 887 allowed_devices_map_.GetDeviceAddress(GetOrigin(), device_id);
891 if (device_address.empty()) { 888 if (device_address.empty()) {
892 CrashRendererAndClosePipe(bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN); 889 CrashRendererAndClosePipe(bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN);
893 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER); 890 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
894 } 891 }
895 892
896 CacheQueryResult result; 893 CacheQueryResult result;
897 result.device = GetAdapter()->GetDevice(device_address); 894 result.device = GetAdapter()->GetDevice(device_address);
898 895
899 // When a device can't be found in the BluetoothAdapter, that generally 896 // When a device can't be found in the BluetoothAdapter, that generally
900 // indicates that it's gone out of range. We reject with a NetworkError in 897 // indicates that it's gone out of range. We reject with a NetworkError in
901 // that case. 898 // that case.
902 if (result.device == nullptr) { 899 if (result.device == nullptr) {
903 result.outcome = CacheQueryOutcome::NO_DEVICE; 900 result.outcome = CacheQueryOutcome::NO_DEVICE;
904 } 901 }
905 return result; 902 return result;
906 } 903 }
907 904
908 CacheQueryResult WebBluetoothServiceImpl::QueryCacheForService( 905 CacheQueryResult WebBluetoothServiceImpl::QueryCacheForService(
909 const std::string& service_instance_id) { 906 const std::string& service_instance_id) {
910 auto device_iter = service_id_to_device_address_.find(service_instance_id); 907 auto device_iter = service_id_to_device_address_.find(service_instance_id);
911 908
912 // Kill the render, see "ID Not in Map Note" above. 909 // Kill the render, see "ID Not in Map Note" above.
913 if (device_iter == service_id_to_device_address_.end()) { 910 if (device_iter == service_id_to_device_address_.end()) {
914 CrashRendererAndClosePipe(bad_message::BDH_INVALID_SERVICE_ID); 911 CrashRendererAndClosePipe(bad_message::BDH_INVALID_SERVICE_ID);
915 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER); 912 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
916 } 913 }
917 914
918 const std::string& device_id = 915 const WebBluetoothDeviceId* device_id =
919 allowed_devices_map_.GetDeviceId(GetOrigin(), device_iter->second); 916 allowed_devices_map_.GetDeviceId(GetOrigin(), device_iter->second);
920 // Kill the renderer if origin is not allowed to access the device. 917 // Kill the renderer if origin is not allowed to access the device.
921 if (device_id.empty()) { 918 if (device_id == nullptr) {
922 CrashRendererAndClosePipe(bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN); 919 CrashRendererAndClosePipe(bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN);
923 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER); 920 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
924 } 921 }
925 922
926 CacheQueryResult result = QueryCacheForDevice(device_id); 923 CacheQueryResult result = QueryCacheForDevice(*device_id);
927 if (result.outcome != CacheQueryOutcome::SUCCESS) { 924 if (result.outcome != CacheQueryOutcome::SUCCESS) {
928 return result; 925 return result;
929 } 926 }
930 927
931 result.service = result.device->GetGattService(service_instance_id); 928 result.service = result.device->GetGattService(service_instance_id);
932 if (result.service == nullptr) { 929 if (result.service == nullptr) {
933 result.outcome = CacheQueryOutcome::NO_SERVICE; 930 result.outcome = CacheQueryOutcome::NO_SERVICE;
934 } else if (!allowed_devices_map_.IsOriginAllowedToAccessService( 931 } else if (!allowed_devices_map_.IsOriginAllowedToAccessService(
935 GetOrigin(), device_id, result.service->GetUUID())) { 932 GetOrigin(), *device_id, result.service->GetUUID())) {
936 CrashRendererAndClosePipe(bad_message::BDH_SERVICE_NOT_ALLOWED_FOR_ORIGIN); 933 CrashRendererAndClosePipe(bad_message::BDH_SERVICE_NOT_ALLOWED_FOR_ORIGIN);
937 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER); 934 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
938 } 935 }
939 return result; 936 return result;
940 } 937 }
941 938
942 CacheQueryResult WebBluetoothServiceImpl::QueryCacheForCharacteristic( 939 CacheQueryResult WebBluetoothServiceImpl::QueryCacheForCharacteristic(
943 const std::string& characteristic_instance_id) { 940 const std::string& characteristic_instance_id) {
944 auto characteristic_iter = 941 auto characteristic_iter =
945 characteristic_id_to_service_id_.find(characteristic_instance_id); 942 characteristic_id_to_service_id_.find(characteristic_instance_id);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 characteristic_id_to_service_id_.clear(); 987 characteristic_id_to_service_id_.clear();
991 service_id_to_device_address_.clear(); 988 service_id_to_device_address_.clear();
992 connected_devices_.reset( 989 connected_devices_.reset(
993 new FrameConnectedBluetoothDevices(render_frame_host_)); 990 new FrameConnectedBluetoothDevices(render_frame_host_));
994 allowed_devices_map_ = BluetoothAllowedDevicesMap(); 991 allowed_devices_map_ = BluetoothAllowedDevicesMap();
995 device_chooser_controller_.reset(); 992 device_chooser_controller_.reset();
996 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); 993 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this);
997 } 994 }
998 995
999 } // namespace content 996 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/bluetooth/web_bluetooth_service_impl.h ('k') | content/common/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698