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

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

Issue 1723723002: bluetooth: Implement Service.getCharacteristics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Merge with ToT Created 4 years, 9 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 // 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 // BluetoothDispatcherHost map [service_to_device_, characteristic_to_service_, 7 // BluetoothDispatcherHost map [service_to_device_, characteristic_to_service_,
8 // descriptor_to_characteristic_] implies a hostile renderer because a renderer 8 // descriptor_to_characteristic_] implies a hostile renderer because a renderer
9 // obtains the corresponding ID from this class and it will be added to the map 9 // obtains the corresponding ID from this class and it will be added to the map
10 // at that time. 10 // at that time.
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) { 300 bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) {
301 DCHECK_CURRENTLY_ON(BrowserThread::UI); 301 DCHECK_CURRENTLY_ON(BrowserThread::UI);
302 bool handled = true; 302 bool handled = true;
303 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcherHost, message) 303 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcherHost, message)
304 IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice) 304 IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice)
305 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GATTServerConnect, OnGATTServerConnect) 305 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GATTServerConnect, OnGATTServerConnect)
306 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GATTServerDisconnect, 306 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GATTServerDisconnect,
307 OnGATTServerDisconnect) 307 OnGATTServerDisconnect)
308 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetPrimaryService, OnGetPrimaryService) 308 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetPrimaryService, OnGetPrimaryService)
309 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristic, OnGetCharacteristic) 309 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristic, OnGetCharacteristic)
310 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristics, OnGetCharacteristics)
310 IPC_MESSAGE_HANDLER(BluetoothHostMsg_ReadValue, OnReadValue) 311 IPC_MESSAGE_HANDLER(BluetoothHostMsg_ReadValue, OnReadValue)
311 IPC_MESSAGE_HANDLER(BluetoothHostMsg_WriteValue, OnWriteValue) 312 IPC_MESSAGE_HANDLER(BluetoothHostMsg_WriteValue, OnWriteValue)
312 IPC_MESSAGE_HANDLER(BluetoothHostMsg_StartNotifications, OnStartNotifications) 313 IPC_MESSAGE_HANDLER(BluetoothHostMsg_StartNotifications, OnStartNotifications)
313 IPC_MESSAGE_HANDLER(BluetoothHostMsg_StopNotifications, OnStopNotifications) 314 IPC_MESSAGE_HANDLER(BluetoothHostMsg_StopNotifications, OnStopNotifications)
314 IPC_MESSAGE_HANDLER(BluetoothHostMsg_RegisterCharacteristic, 315 IPC_MESSAGE_HANDLER(BluetoothHostMsg_RegisterCharacteristic,
315 OnRegisterCharacteristicObject); 316 OnRegisterCharacteristicObject);
316 IPC_MESSAGE_HANDLER(BluetoothHostMsg_UnregisterCharacteristic, 317 IPC_MESSAGE_HANDLER(BluetoothHostMsg_UnregisterCharacteristic,
317 OnUnregisterCharacteristicObject); 318 OnUnregisterCharacteristicObject);
318 IPC_MESSAGE_UNHANDLED(handled = false) 319 IPC_MESSAGE_UNHANDLED(handled = false)
319 IPC_END_MESSAGE_MAP() 320 IPC_END_MESSAGE_MAP()
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 thread_id, request_id, characteristic_instance_id, 837 thread_id, request_id, characteristic_instance_id,
837 static_cast<uint32_t>(characteristic->GetProperties()))); 838 static_cast<uint32_t>(characteristic->GetProperties())));
838 return; 839 return;
839 } 840 }
840 } 841 }
841 RecordGetCharacteristicOutcome(UMAGetCharacteristicOutcome::NOT_FOUND); 842 RecordGetCharacteristicOutcome(UMAGetCharacteristicOutcome::NOT_FOUND);
842 Send(new BluetoothMsg_GetCharacteristicError( 843 Send(new BluetoothMsg_GetCharacteristicError(
843 thread_id, request_id, WebBluetoothError::CharacteristicNotFound)); 844 thread_id, request_id, WebBluetoothError::CharacteristicNotFound));
844 } 845 }
845 846
847 void BluetoothDispatcherHost::OnGetCharacteristics(
848 int thread_id,
849 int request_id,
850 int frame_routing_id,
851 const std::string& service_instance_id,
852 const std::string& characteristics_uuid) {
853 DCHECK_CURRENTLY_ON(BrowserThread::UI);
854 RecordWebBluetoothFunctionCall(
855 UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTICS);
856 RecordGetCharacteristicsCharacteristic(characteristics_uuid);
857
858 // Check Blacklist for characteristics_uuid.
859 if (!characteristics_uuid.empty() &&
860 BluetoothBlacklist::Get().IsExcluded(
861 BluetoothUUID(characteristics_uuid))) {
862 RecordGetCharacteristicsOutcome(UMAGetCharacteristicOutcome::BLACKLISTED);
863 Send(new BluetoothMsg_GetCharacteristicsError(
864 thread_id, request_id,
865 WebBluetoothError::BlacklistedCharacteristicUUID));
866 return;
867 }
868
869 const CacheQueryResult query_result =
870 QueryCacheForService(GetOrigin(frame_routing_id), service_instance_id);
871
872 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) {
873 return;
874 }
875
876 if (query_result.outcome != CacheQueryOutcome::SUCCESS) {
877 RecordGetCharacteristicsOutcome(query_result.outcome);
878 Send(new BluetoothMsg_GetCharacteristicsError(thread_id, request_id,
879 query_result.GetWebError()));
880 return;
881 }
882
883 std::vector<std::string> characteristics_instance_ids;
884 std::vector<std::string> characteristics_uuids;
885 std::vector<uint32_t> characteristics_properties;
886
887 for (BluetoothGattCharacteristic* characteristic :
888 query_result.service->GetCharacteristics()) {
889 if (!BluetoothBlacklist::Get().IsExcluded(characteristic->GetUUID()) &&
890 (characteristics_uuid.empty() ||
891 characteristics_uuid == characteristic->GetUUID().canonical_value())) {
892 const std::string& characteristic_instance_id =
893 characteristic->GetIdentifier();
894
895 characteristics_instance_ids.push_back(characteristic_instance_id);
896 characteristics_uuids.push_back(
897 characteristic->GetUUID().canonical_value());
898 characteristics_properties.push_back(
899 static_cast<uint32_t>(characteristic->GetProperties()));
900
901 auto insert_result = characteristic_to_service_.insert(
902 make_pair(characteristic_instance_id, service_instance_id));
903
904 // If value is already in map, DCHECK it's valid.
905 if (!insert_result.second)
906 DCHECK(insert_result.first->second == service_instance_id);
907 }
908 }
909
910 if (!characteristics_instance_ids.empty()) {
911 RecordGetCharacteristicsOutcome(UMAGetCharacteristicOutcome::SUCCESS);
912 Send(new BluetoothMsg_GetCharacteristicsSuccess(
913 thread_id, request_id, characteristics_instance_ids,
914 characteristics_uuids, characteristics_properties));
915 return;
916 }
917 RecordGetCharacteristicsOutcome(
918 characteristics_uuid.empty()
919 ? UMAGetCharacteristicOutcome::NO_CHARACTERISTICS
920 : UMAGetCharacteristicOutcome::NOT_FOUND);
921 Send(new BluetoothMsg_GetCharacteristicsError(
922 thread_id, request_id, characteristics_uuid.empty()
923 ? WebBluetoothError::NoCharacteristicsFound
924 : WebBluetoothError::CharacteristicNotFound));
925 }
926
846 void BluetoothDispatcherHost::OnReadValue( 927 void BluetoothDispatcherHost::OnReadValue(
847 int thread_id, 928 int thread_id,
848 int request_id, 929 int request_id,
849 int frame_routing_id, 930 int frame_routing_id,
850 const std::string& characteristic_instance_id) { 931 const std::string& characteristic_instance_id) {
851 DCHECK_CURRENTLY_ON(BrowserThread::UI); 932 DCHECK_CURRENTLY_ON(BrowserThread::UI);
852 RecordWebBluetoothFunctionCall( 933 RecordWebBluetoothFunctionCall(
853 UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE); 934 UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE);
854 935
855 const CacheQueryResult query_result = QueryCacheForCharacteristic( 936 const CacheQueryResult query_result = QueryCacheForCharacteristic(
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 1638
1558 bool BluetoothDispatcherHost::CanFrameAccessCharacteristicInstance( 1639 bool BluetoothDispatcherHost::CanFrameAccessCharacteristicInstance(
1559 int frame_routing_id, 1640 int frame_routing_id,
1560 const std::string& characteristic_instance_id) { 1641 const std::string& characteristic_instance_id) {
1561 return QueryCacheForCharacteristic(GetOrigin(frame_routing_id), 1642 return QueryCacheForCharacteristic(GetOrigin(frame_routing_id),
1562 characteristic_instance_id) 1643 characteristic_instance_id)
1563 .outcome != CacheQueryOutcome::BAD_RENDERER; 1644 .outcome != CacheQueryOutcome::BAD_RENDERER;
1564 } 1645 }
1565 1646
1566 } // namespace content 1647 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/bluetooth/bluetooth_dispatcher_host.h ('k') | content/browser/bluetooth/bluetooth_metrics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698