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

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

Issue 1861013005: bluetooth: Move GetCharacteristic(s) over to Mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-separate-tests-read-value
Patch Set: Address palmer's comments Created 4 years, 7 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.
11 11
12 #include "content/browser/bluetooth/bluetooth_dispatcher_host.h" 12 #include "content/browser/bluetooth/bluetooth_dispatcher_host.h"
13 13
14 #include <stddef.h> 14 #include <stddef.h>
15 15
16 #include <utility> 16 #include <utility>
17 17
18 #include "base/bind.h" 18 #include "base/bind.h"
19 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "base/thread_task_runner_handle.h" 21 #include "base/thread_task_runner_handle.h"
22 #include "content/browser/bad_message.h" 22 #include "content/browser/bad_message.h"
23 #include "content/browser/bluetooth/bluetooth_blacklist.h" 23 #include "content/browser/bluetooth/bluetooth_blacklist.h"
24 #include "content/browser/bluetooth/bluetooth_metrics.h"
25 #include "content/browser/bluetooth/cache_query_result.h"
24 #include "content/browser/bluetooth/first_device_bluetooth_chooser.h" 26 #include "content/browser/bluetooth/first_device_bluetooth_chooser.h"
25 #include "content/browser/frame_host/render_frame_host_impl.h" 27 #include "content/browser/frame_host/render_frame_host_impl.h"
26 #include "content/browser/web_contents/web_contents_impl.h" 28 #include "content/browser/web_contents/web_contents_impl.h"
27 #include "content/public/browser/content_browser_client.h" 29 #include "content/public/browser/content_browser_client.h"
28 #include "content/public/browser/web_contents.h" 30 #include "content/public/browser/web_contents.h"
29 #include "content/public/browser/web_contents_delegate.h" 31 #include "content/public/browser/web_contents_delegate.h"
30 #include "device/bluetooth/bluetooth_adapter.h" 32 #include "device/bluetooth/bluetooth_adapter.h"
31 #include "device/bluetooth/bluetooth_adapter_factory.h" 33 #include "device/bluetooth/bluetooth_adapter_factory.h"
32 #include "device/bluetooth/bluetooth_device.h" 34 #include "device/bluetooth/bluetooth_device.h"
33 #include "device/bluetooth/bluetooth_discovery_session.h" 35 #include "device/bluetooth/bluetooth_discovery_session.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 264
263 bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) { 265 bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) {
264 DCHECK_CURRENTLY_ON(BrowserThread::UI); 266 DCHECK_CURRENTLY_ON(BrowserThread::UI);
265 bool handled = true; 267 bool handled = true;
266 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcherHost, message) 268 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcherHost, message)
267 IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice) 269 IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice)
268 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GATTServerConnect, OnGATTServerConnect) 270 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GATTServerConnect, OnGATTServerConnect)
269 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GATTServerDisconnect, 271 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GATTServerDisconnect,
270 OnGATTServerDisconnect) 272 OnGATTServerDisconnect)
271 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetPrimaryService, OnGetPrimaryService) 273 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetPrimaryService, OnGetPrimaryService)
272 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristic, OnGetCharacteristic)
273 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristics, OnGetCharacteristics)
274 IPC_MESSAGE_UNHANDLED(handled = false) 274 IPC_MESSAGE_UNHANDLED(handled = false)
275 IPC_END_MESSAGE_MAP() 275 IPC_END_MESSAGE_MAP()
276 return handled; 276 return handled;
277 } 277 }
278 278
279 void BluetoothDispatcherHost::SetBluetoothAdapterForTesting( 279 void BluetoothDispatcherHost::SetBluetoothAdapterForTesting(
280 scoped_refptr<device::BluetoothAdapter> mock_adapter) { 280 scoped_refptr<device::BluetoothAdapter> mock_adapter) {
281 DCHECK_CURRENTLY_ON(BrowserThread::UI); 281 DCHECK_CURRENTLY_ON(BrowserThread::UI);
282 282
283 if (mock_adapter.get()) { 283 if (mock_adapter.get()) {
284 current_delay_time_ = kTestingDelayTime; 284 current_delay_time_ = kTestingDelayTime;
285 // Reset the discovery session timer to use the new delay time. 285 // Reset the discovery session timer to use the new delay time.
286 discovery_session_timer_.Start( 286 discovery_session_timer_.Start(
287 FROM_HERE, base::TimeDelta::FromSecondsD(current_delay_time_), 287 FROM_HERE, base::TimeDelta::FromSecondsD(current_delay_time_),
288 base::Bind(&BluetoothDispatcherHost::StopDeviceDiscovery, 288 base::Bind(&BluetoothDispatcherHost::StopDeviceDiscovery,
289 // base::Timer guarantees it won't call back after its 289 // base::Timer guarantees it won't call back after its
290 // destructor starts. 290 // destructor starts.
291 base::Unretained(this))); 291 base::Unretained(this)));
292 } else { 292 } else {
293 // The following data structures are used to store pending operations. 293 // The following data structures are used to store pending operations.
294 // They should never contain elements at the end of a test. 294 // They should never contain elements at the end of a test.
295 DCHECK(request_device_sessions_.IsEmpty()); 295 DCHECK(request_device_sessions_.IsEmpty());
296 DCHECK(pending_primary_services_requests_.empty()); 296 DCHECK(pending_primary_services_requests_.empty());
297 297
298 // The following data structures are cleaned up when a 298 // The following data structures are cleaned up when a
299 // device/service/characteristic is removed. 299 // device/service/characteristic is removed.
300 // Since this can happen after the test is done and the cleanup function is 300 // Since this can happen after the test is done and the cleanup function is
301 // called, we clean them here. 301 // called, we clean them here.
302 service_to_device_.clear(); 302 service_to_device_.clear();
303 characteristic_to_service_.clear();
304 connected_devices_map_.reset(new ConnectedDevicesMap(render_process_id_)); 303 connected_devices_map_.reset(new ConnectedDevicesMap(render_process_id_));
305 allowed_devices_map_ = BluetoothAllowedDevicesMap(); 304 allowed_devices_map_ = BluetoothAllowedDevicesMap();
306 } 305 }
307 306
308 set_adapter(std::move(mock_adapter)); 307 set_adapter(std::move(mock_adapter));
309 } 308 }
310 309
311 BluetoothDispatcherHost::~BluetoothDispatcherHost() { 310 BluetoothDispatcherHost::~BluetoothDispatcherHost() {
312 DCHECK_CURRENTLY_ON(BrowserThread::UI); 311 DCHECK_CURRENTLY_ON(BrowserThread::UI);
313 // Clear adapter, releasing observer references. 312 // Clear adapter, releasing observer references.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 350
352 const int thread_id; 351 const int thread_id;
353 const int request_id; 352 const int request_id;
354 const url::Origin origin; 353 const url::Origin origin;
355 const std::vector<BluetoothScanFilter> filters; 354 const std::vector<BluetoothScanFilter> filters;
356 const std::vector<BluetoothUUID> optional_services; 355 const std::vector<BluetoothUUID> optional_services;
357 std::unique_ptr<BluetoothChooser> chooser; 356 std::unique_ptr<BluetoothChooser> chooser;
358 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session; 357 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session;
359 }; 358 };
360 359
361 BluetoothDispatcherHost::CacheQueryResult::CacheQueryResult() {}
362
363 BluetoothDispatcherHost::CacheQueryResult::CacheQueryResult(
364 CacheQueryOutcome outcome)
365 : outcome(outcome) {}
366
367 BluetoothDispatcherHost::CacheQueryResult::~CacheQueryResult() {}
368
369 WebBluetoothError BluetoothDispatcherHost::CacheQueryResult::GetWebError()
370 const {
371 switch (outcome) {
372 case CacheQueryOutcome::SUCCESS:
373 case CacheQueryOutcome::BAD_RENDERER:
374 NOTREACHED();
375 return WebBluetoothError::DEVICE_NO_LONGER_IN_RANGE;
376 case CacheQueryOutcome::NO_DEVICE:
377 return WebBluetoothError::DEVICE_NO_LONGER_IN_RANGE;
378 case CacheQueryOutcome::NO_SERVICE:
379 return WebBluetoothError::SERVICE_NO_LONGER_EXISTS;
380 case CacheQueryOutcome::NO_CHARACTERISTIC:
381 return WebBluetoothError::CHARACTERISTIC_NO_LONGER_EXISTS;
382 }
383 NOTREACHED();
384 return WebBluetoothError::DEVICE_NO_LONGER_IN_RANGE;
385 }
386
387 struct BluetoothDispatcherHost::PrimaryServicesRequest { 360 struct BluetoothDispatcherHost::PrimaryServicesRequest {
388 enum CallingFunction { GET_PRIMARY_SERVICE, GET_PRIMARY_SERVICES }; 361 enum CallingFunction { GET_PRIMARY_SERVICE, GET_PRIMARY_SERVICES };
389 362
390 PrimaryServicesRequest(int thread_id, 363 PrimaryServicesRequest(int thread_id,
391 int request_id, 364 int request_id,
392 const std::string& service_uuid, 365 const std::string& service_uuid,
393 PrimaryServicesRequest::CallingFunction func) 366 PrimaryServicesRequest::CallingFunction func)
394 : thread_id(thread_id), 367 : thread_id(thread_id),
395 request_id(request_id), 368 request_id(request_id),
396 service_uuid(service_uuid), 369 service_uuid(service_uuid),
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 } 745 }
773 746
774 VLOG(1) << "Adding service request to pending requests."; 747 VLOG(1) << "Adding service request to pending requests.";
775 // 4. 748 // 4.
776 AddToPendingPrimaryServicesRequest( 749 AddToPendingPrimaryServicesRequest(
777 query_result.device->GetAddress(), 750 query_result.device->GetAddress(),
778 PrimaryServicesRequest(thread_id, request_id, service_uuid, 751 PrimaryServicesRequest(thread_id, request_id, service_uuid,
779 PrimaryServicesRequest::GET_PRIMARY_SERVICE)); 752 PrimaryServicesRequest::GET_PRIMARY_SERVICE));
780 } 753 }
781 754
782 void BluetoothDispatcherHost::OnGetCharacteristic(
783 int thread_id,
784 int request_id,
785 int frame_routing_id,
786 const std::string& service_instance_id,
787 const std::string& characteristic_uuid) {
788 DCHECK_CURRENTLY_ON(BrowserThread::UI);
789 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_CHARACTERISTIC);
790 RecordGetCharacteristicCharacteristic(characteristic_uuid);
791
792 // Check Blacklist for characteristic_uuid.
793 if (BluetoothBlacklist::Get().IsExcluded(
794 BluetoothUUID(characteristic_uuid))) {
795 RecordGetCharacteristicOutcome(UMAGetCharacteristicOutcome::BLACKLISTED);
796 Send(new BluetoothMsg_GetCharacteristicError(
797 thread_id, request_id,
798 WebBluetoothError::BLACKLISTED_CHARACTERISTIC_UUID));
799 return;
800 }
801
802 const CacheQueryResult query_result =
803 QueryCacheForService(GetOrigin(frame_routing_id), service_instance_id);
804
805 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) {
806 return;
807 }
808
809 if (query_result.outcome != CacheQueryOutcome::SUCCESS) {
810 RecordGetCharacteristicOutcome(query_result.outcome);
811 Send(new BluetoothMsg_GetCharacteristicError(thread_id, request_id,
812 query_result.GetWebError()));
813 return;
814 }
815
816 for (BluetoothRemoteGattCharacteristic* characteristic :
817 query_result.service->GetCharacteristics()) {
818 if (characteristic->GetUUID().canonical_value() == characteristic_uuid) {
819 const std::string& characteristic_instance_id =
820 characteristic->GetIdentifier();
821
822 auto insert_result = characteristic_to_service_.insert(
823 make_pair(characteristic_instance_id, service_instance_id));
824
825 // If value is already in map, DCHECK it's valid.
826 if (!insert_result.second)
827 DCHECK(insert_result.first->second == service_instance_id);
828
829 RecordGetCharacteristicOutcome(UMAGetCharacteristicOutcome::SUCCESS);
830 // TODO(ortuno): Use generated instance ID instead.
831 // https://crbug.com/495379
832 Send(new BluetoothMsg_GetCharacteristicSuccess(
833 thread_id, request_id, characteristic_instance_id,
834 static_cast<uint32_t>(characteristic->GetProperties())));
835 return;
836 }
837 }
838 RecordGetCharacteristicOutcome(UMAGetCharacteristicOutcome::NOT_FOUND);
839 Send(new BluetoothMsg_GetCharacteristicError(
840 thread_id, request_id, WebBluetoothError::CHARACTERISTIC_NOT_FOUND));
841 }
842
843 void BluetoothDispatcherHost::OnGetCharacteristics(
844 int thread_id,
845 int request_id,
846 int frame_routing_id,
847 const std::string& service_instance_id,
848 const std::string& characteristics_uuid) {
849 DCHECK_CURRENTLY_ON(BrowserThread::UI);
850 RecordWebBluetoothFunctionCall(
851 UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTICS);
852 RecordGetCharacteristicsCharacteristic(characteristics_uuid);
853
854 // Check Blacklist for characteristics_uuid.
855 if (!characteristics_uuid.empty() &&
856 BluetoothBlacklist::Get().IsExcluded(
857 BluetoothUUID(characteristics_uuid))) {
858 RecordGetCharacteristicsOutcome(UMAGetCharacteristicOutcome::BLACKLISTED);
859 Send(new BluetoothMsg_GetCharacteristicsError(
860 thread_id, request_id,
861 WebBluetoothError::BLACKLISTED_CHARACTERISTIC_UUID));
862 return;
863 }
864
865 const CacheQueryResult query_result =
866 QueryCacheForService(GetOrigin(frame_routing_id), service_instance_id);
867
868 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) {
869 return;
870 }
871
872 if (query_result.outcome != CacheQueryOutcome::SUCCESS) {
873 RecordGetCharacteristicsOutcome(query_result.outcome);
874 Send(new BluetoothMsg_GetCharacteristicsError(thread_id, request_id,
875 query_result.GetWebError()));
876 return;
877 }
878
879 std::vector<std::string> characteristics_instance_ids;
880 std::vector<std::string> characteristics_uuids;
881 std::vector<uint32_t> characteristics_properties;
882
883 for (BluetoothRemoteGattCharacteristic* characteristic :
884 query_result.service->GetCharacteristics()) {
885 if (!BluetoothBlacklist::Get().IsExcluded(characteristic->GetUUID()) &&
886 (characteristics_uuid.empty() ||
887 characteristics_uuid == characteristic->GetUUID().canonical_value())) {
888 const std::string& characteristic_instance_id =
889 characteristic->GetIdentifier();
890
891 characteristics_instance_ids.push_back(characteristic_instance_id);
892 characteristics_uuids.push_back(
893 characteristic->GetUUID().canonical_value());
894 characteristics_properties.push_back(
895 static_cast<uint32_t>(characteristic->GetProperties()));
896
897 auto insert_result = characteristic_to_service_.insert(
898 make_pair(characteristic_instance_id, service_instance_id));
899
900 // If value is already in map, DCHECK it's valid.
901 if (!insert_result.second)
902 DCHECK(insert_result.first->second == service_instance_id);
903 }
904 }
905
906 if (!characteristics_instance_ids.empty()) {
907 RecordGetCharacteristicsOutcome(UMAGetCharacteristicOutcome::SUCCESS);
908 Send(new BluetoothMsg_GetCharacteristicsSuccess(
909 thread_id, request_id, characteristics_instance_ids,
910 characteristics_uuids, characteristics_properties));
911 return;
912 }
913 RecordGetCharacteristicsOutcome(
914 characteristics_uuid.empty()
915 ? UMAGetCharacteristicOutcome::NO_CHARACTERISTICS
916 : UMAGetCharacteristicOutcome::NOT_FOUND);
917 Send(new BluetoothMsg_GetCharacteristicsError(
918 thread_id, request_id,
919 characteristics_uuid.empty()
920 ? WebBluetoothError::NO_CHARACTERISTICS_FOUND
921 : WebBluetoothError::CHARACTERISTIC_NOT_FOUND));
922 }
923
924 void BluetoothDispatcherHost::OnGetAdapter( 755 void BluetoothDispatcherHost::OnGetAdapter(
925 base::Closure continuation, 756 base::Closure continuation,
926 scoped_refptr<device::BluetoothAdapter> adapter) { 757 scoped_refptr<device::BluetoothAdapter> adapter) {
927 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 758 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
928 set_adapter(adapter); 759 set_adapter(adapter);
929 continuation.Run(); 760 continuation.Run();
930 } 761 }
931 762
932 void BluetoothDispatcherHost::OnRequestDeviceImpl( 763 void BluetoothDispatcherHost::OnRequestDeviceImpl(
933 int thread_id, 764 int thread_id,
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 1127
1297 // If a value is already in map, DCHECK it's valid. 1128 // If a value is already in map, DCHECK it's valid.
1298 if (!insert_result.second) 1129 if (!insert_result.second)
1299 DCHECK_EQ(insert_result.first->second, device_address); 1130 DCHECK_EQ(insert_result.first->second, device_address);
1300 1131
1301 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::SUCCESS); 1132 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::SUCCESS);
1302 Send(new BluetoothMsg_GetPrimaryServiceSuccess(thread_id, request_id, 1133 Send(new BluetoothMsg_GetPrimaryServiceSuccess(thread_id, request_id,
1303 service_identifier)); 1134 service_identifier));
1304 } 1135 }
1305 1136
1306 BluetoothDispatcherHost::CacheQueryResult 1137 CacheQueryResult BluetoothDispatcherHost::QueryCacheForDevice(
1307 BluetoothDispatcherHost::QueryCacheForDevice(const url::Origin& origin, 1138 const url::Origin& origin,
1308 const std::string& device_id) { 1139 const std::string& device_id) {
1309 const std::string& device_address = 1140 const std::string& device_address =
1310 allowed_devices_map_.GetDeviceAddress(origin, device_id); 1141 allowed_devices_map_.GetDeviceAddress(origin, device_id);
1311 if (device_address.empty()) { 1142 if (device_address.empty()) {
1312 bad_message::ReceivedBadMessage( 1143 bad_message::ReceivedBadMessage(
1313 this, bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN); 1144 this, bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN);
1314 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER); 1145 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
1315 } 1146 }
1316 1147
1317 CacheQueryResult result; 1148 CacheQueryResult result;
1318 result.device = adapter_->GetDevice(device_address); 1149 result.device = adapter_->GetDevice(device_address);
1319 1150
1320 // When a device can't be found in the BluetoothAdapter, that generally 1151 // When a device can't be found in the BluetoothAdapter, that generally
1321 // indicates that it's gone out of range. We reject with a NetworkError in 1152 // indicates that it's gone out of range. We reject with a NetworkError in
1322 // that case. 1153 // that case.
1323 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-con nectgatt 1154 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-con nectgatt
1324 if (result.device == nullptr) { 1155 if (result.device == nullptr) {
1325 result.outcome = CacheQueryOutcome::NO_DEVICE; 1156 result.outcome = CacheQueryOutcome::NO_DEVICE;
1326 } 1157 }
1327 return result; 1158 return result;
1328 } 1159 }
1329 1160
1330 BluetoothDispatcherHost::CacheQueryResult 1161 CacheQueryResult BluetoothDispatcherHost::QueryCacheForService(
1331 BluetoothDispatcherHost::QueryCacheForService(
1332 const url::Origin& origin, 1162 const url::Origin& origin,
1333 const std::string& service_instance_id) { 1163 const std::string& service_instance_id) {
1334 auto device_iter = service_to_device_.find(service_instance_id); 1164 auto device_iter = service_to_device_.find(service_instance_id);
1335 1165
1336 // Kill the renderer, see "ID Not In Map Note" above. 1166 // Kill the renderer, see "ID Not In Map Note" above.
1337 if (device_iter == service_to_device_.end()) { 1167 if (device_iter == service_to_device_.end()) {
1338 bad_message::ReceivedBadMessage(this, bad_message::BDH_INVALID_SERVICE_ID); 1168 bad_message::ReceivedBadMessage(this, bad_message::BDH_INVALID_SERVICE_ID);
1339 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER); 1169 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
1340 } 1170 }
1341 1171
(...skipping 18 matching lines...) Expand all
1360 } else if (!allowed_devices_map_.IsOriginAllowedToAccessService( 1190 } else if (!allowed_devices_map_.IsOriginAllowedToAccessService(
1361 origin, device_id, 1191 origin, device_id,
1362 result.service->GetUUID().canonical_value())) { 1192 result.service->GetUUID().canonical_value())) {
1363 bad_message::ReceivedBadMessage( 1193 bad_message::ReceivedBadMessage(
1364 this, bad_message::BDH_SERVICE_NOT_ALLOWED_FOR_ORIGIN); 1194 this, bad_message::BDH_SERVICE_NOT_ALLOWED_FOR_ORIGIN);
1365 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER); 1195 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
1366 } 1196 }
1367 return result; 1197 return result;
1368 } 1198 }
1369 1199
1370 BluetoothDispatcherHost::CacheQueryResult
1371 BluetoothDispatcherHost::QueryCacheForCharacteristic(
1372 const url::Origin& origin,
1373 const std::string& characteristic_instance_id) {
1374 auto characteristic_iter =
1375 characteristic_to_service_.find(characteristic_instance_id);
1376
1377 // Kill the renderer, see "ID Not In Map Note" above.
1378 if (characteristic_iter == characteristic_to_service_.end()) {
1379 bad_message::ReceivedBadMessage(this,
1380 bad_message::BDH_INVALID_CHARACTERISTIC_ID);
1381 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
1382 }
1383
1384 CacheQueryResult result =
1385 QueryCacheForService(origin, characteristic_iter->second);
1386 if (result.outcome != CacheQueryOutcome::SUCCESS) {
1387 return result;
1388 }
1389
1390 result.characteristic =
1391 result.service->GetCharacteristic(characteristic_instance_id);
1392
1393 if (result.characteristic == nullptr) {
1394 result.outcome = CacheQueryOutcome::NO_CHARACTERISTIC;
1395 }
1396
1397 return result;
1398 }
1399
1400 void BluetoothDispatcherHost::AddAdapterObserver( 1200 void BluetoothDispatcherHost::AddAdapterObserver(
1401 device::BluetoothAdapter::Observer* observer) { 1201 device::BluetoothAdapter::Observer* observer) {
1402 adapter_observers_.insert(observer); 1202 adapter_observers_.insert(observer);
1403 if (adapter_) { 1203 if (adapter_) {
1404 adapter_->AddObserver(observer); 1204 adapter_->AddObserver(observer);
1405 } 1205 }
1406 } 1206 }
1407 1207
1408 void BluetoothDispatcherHost::RemoveAdapterObserver( 1208 void BluetoothDispatcherHost::RemoveAdapterObserver(
1409 device::BluetoothAdapter::Observer* observer) { 1209 device::BluetoothAdapter::Observer* observer) {
1410 DCHECK(adapter_observers_.erase(observer)); 1210 DCHECK(adapter_observers_.erase(observer));
1411 if (adapter_) { 1211 if (adapter_) {
1412 adapter_->RemoveObserver(observer); 1212 adapter_->RemoveObserver(observer);
1413 } 1213 }
1414 } 1214 }
1415 1215
1416 void BluetoothDispatcherHost::AddToPendingPrimaryServicesRequest( 1216 void BluetoothDispatcherHost::AddToPendingPrimaryServicesRequest(
1417 const std::string& device_address, 1217 const std::string& device_address,
1418 const PrimaryServicesRequest& request) { 1218 const PrimaryServicesRequest& request) {
1419 pending_primary_services_requests_[device_address].push_back(request); 1219 pending_primary_services_requests_[device_address].push_back(request);
1420 } 1220 }
1421 1221
1422 url::Origin BluetoothDispatcherHost::GetOrigin(int frame_routing_id) { 1222 url::Origin BluetoothDispatcherHost::GetOrigin(int frame_routing_id) {
1423 return RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id) 1223 return RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id)
1424 ->GetLastCommittedOrigin(); 1224 ->GetLastCommittedOrigin();
1425 } 1225 }
1426 1226
1427 } // namespace content 1227 } // 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