| OLD | NEW |
| 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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 | 315 |
| 316 // The following data structures are cleaned up when a | 316 // The following data structures are cleaned up when a |
| 317 // device/service/characteristic is removed. | 317 // device/service/characteristic is removed. |
| 318 // Since this can happen after the test is done and the cleanup function is | 318 // Since this can happen after the test is done and the cleanup function is |
| 319 // called, we clean them here. | 319 // called, we clean them here. |
| 320 service_to_device_.clear(); | 320 service_to_device_.clear(); |
| 321 characteristic_to_service_.clear(); | 321 characteristic_to_service_.clear(); |
| 322 characteristic_id_to_notify_session_.clear(); | 322 characteristic_id_to_notify_session_.clear(); |
| 323 active_characteristic_threads_.clear(); | 323 active_characteristic_threads_.clear(); |
| 324 connections_.clear(); | 324 connections_.clear(); |
| 325 devices_with_discovered_services_.clear(); |
| 325 } | 326 } |
| 326 | 327 |
| 327 set_adapter(std::move(mock_adapter)); | 328 set_adapter(std::move(mock_adapter)); |
| 328 } | 329 } |
| 329 | 330 |
| 330 BluetoothDispatcherHost::~BluetoothDispatcherHost() { | 331 BluetoothDispatcherHost::~BluetoothDispatcherHost() { |
| 331 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 332 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 332 // Clear adapter, releasing observer references. | 333 // Clear adapter, releasing observer references. |
| 333 set_adapter(scoped_refptr<device::BluetoothAdapter>()); | 334 set_adapter(scoped_refptr<device::BluetoothAdapter>()); |
| 334 } | 335 } |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 } | 517 } |
| 517 } | 518 } |
| 518 | 519 |
| 519 void BluetoothDispatcherHost::GattServicesDiscovered( | 520 void BluetoothDispatcherHost::GattServicesDiscovered( |
| 520 device::BluetoothAdapter* adapter, | 521 device::BluetoothAdapter* adapter, |
| 521 device::BluetoothDevice* device) { | 522 device::BluetoothDevice* device) { |
| 522 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 523 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 523 const std::string& device_id = device->GetAddress(); | 524 const std::string& device_id = device->GetAddress(); |
| 524 VLOG(1) << "Services discovered for device: " << device_id; | 525 VLOG(1) << "Services discovered for device: " << device_id; |
| 525 | 526 |
| 527 devices_with_discovered_services_.insert(device_id); |
| 528 |
| 526 auto iter = pending_primary_services_requests_.find(device_id); | 529 auto iter = pending_primary_services_requests_.find(device_id); |
| 527 if (iter == pending_primary_services_requests_.end()) { | 530 if (iter == pending_primary_services_requests_.end()) { |
| 528 return; | 531 return; |
| 529 } | 532 } |
| 530 std::vector<PrimaryServicesRequest> requests; | 533 std::vector<PrimaryServicesRequest> requests; |
| 531 requests.swap(iter->second); | 534 requests.swap(iter->second); |
| 532 pending_primary_services_requests_.erase(iter); | 535 pending_primary_services_requests_.erase(iter); |
| 533 | 536 |
| 534 for (const PrimaryServicesRequest& request : requests) { | 537 for (const PrimaryServicesRequest& request : requests) { |
| 535 std::vector<BluetoothGattService*> services = | 538 std::vector<BluetoothGattService*> services = |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 if (!services.empty()) { | 781 if (!services.empty()) { |
| 779 VLOG(1) << "Service found in device."; | 782 VLOG(1) << "Service found in device."; |
| 780 const BluetoothGattService& service = *services[0]; | 783 const BluetoothGattService& service = *services[0]; |
| 781 DCHECK(service.IsPrimary()); | 784 DCHECK(service.IsPrimary()); |
| 782 AddToServicesMapAndSendGetPrimaryServiceSuccess(service, thread_id, | 785 AddToServicesMapAndSendGetPrimaryServiceSuccess(service, thread_id, |
| 783 request_id); | 786 request_id); |
| 784 return; | 787 return; |
| 785 } | 788 } |
| 786 | 789 |
| 787 // 3. | 790 // 3. |
| 788 if (query_result.device->IsGattServicesDiscoveryComplete()) { | 791 if (IsServicesDiscoveryCompleteForDevice(device_id)) { |
| 789 VLOG(1) << "Service not found in device."; | 792 VLOG(1) << "Service not found in device."; |
| 790 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND); | 793 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND); |
| 791 Send(new BluetoothMsg_GetPrimaryServiceError( | 794 Send(new BluetoothMsg_GetPrimaryServiceError( |
| 792 thread_id, request_id, WebBluetoothError::ServiceNotFound)); | 795 thread_id, request_id, WebBluetoothError::ServiceNotFound)); |
| 793 return; | 796 return; |
| 794 } | 797 } |
| 795 | 798 |
| 796 VLOG(1) << "Adding service request to pending requests."; | 799 VLOG(1) << "Adding service request to pending requests."; |
| 797 // 4. | 800 // 4. |
| 798 AddToPendingPrimaryServicesRequest( | 801 AddToPendingPrimaryServicesRequest( |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1334 result.characteristic = | 1337 result.characteristic = |
| 1335 result.service->GetCharacteristic(characteristic_instance_id); | 1338 result.service->GetCharacteristic(characteristic_instance_id); |
| 1336 | 1339 |
| 1337 if (result.characteristic == nullptr) { | 1340 if (result.characteristic == nullptr) { |
| 1338 result.outcome = CacheQueryOutcome::NO_CHARACTERISTIC; | 1341 result.outcome = CacheQueryOutcome::NO_CHARACTERISTIC; |
| 1339 } | 1342 } |
| 1340 | 1343 |
| 1341 return result; | 1344 return result; |
| 1342 } | 1345 } |
| 1343 | 1346 |
| 1347 bool BluetoothDispatcherHost::IsServicesDiscoveryCompleteForDevice( |
| 1348 const std::string& device_id) { |
| 1349 return ContainsKey(devices_with_discovered_services_, device_id); |
| 1350 } |
| 1351 |
| 1344 void BluetoothDispatcherHost::AddToPendingPrimaryServicesRequest( | 1352 void BluetoothDispatcherHost::AddToPendingPrimaryServicesRequest( |
| 1345 const std::string& device_id, | 1353 const std::string& device_id, |
| 1346 const PrimaryServicesRequest& request) { | 1354 const PrimaryServicesRequest& request) { |
| 1347 pending_primary_services_requests_[device_id].push_back(request); | 1355 pending_primary_services_requests_[device_id].push_back(request); |
| 1348 } | 1356 } |
| 1349 | 1357 |
| 1350 void BluetoothDispatcherHost::ShowBluetoothOverviewLink() { | 1358 void BluetoothDispatcherHost::ShowBluetoothOverviewLink() { |
| 1351 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1359 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1352 NOTIMPLEMENTED(); | 1360 NOTIMPLEMENTED(); |
| 1353 } | 1361 } |
| 1354 | 1362 |
| 1355 void BluetoothDispatcherHost::ShowBluetoothPairingLink() { | 1363 void BluetoothDispatcherHost::ShowBluetoothPairingLink() { |
| 1356 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1364 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1357 NOTIMPLEMENTED(); | 1365 NOTIMPLEMENTED(); |
| 1358 } | 1366 } |
| 1359 | 1367 |
| 1360 void BluetoothDispatcherHost::ShowBluetoothAdapterOffLink() { | 1368 void BluetoothDispatcherHost::ShowBluetoothAdapterOffLink() { |
| 1361 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1369 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1362 NOTIMPLEMENTED(); | 1370 NOTIMPLEMENTED(); |
| 1363 } | 1371 } |
| 1364 | 1372 |
| 1365 void BluetoothDispatcherHost::ShowNeedLocationLink() { | 1373 void BluetoothDispatcherHost::ShowNeedLocationLink() { |
| 1366 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1374 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1367 NOTIMPLEMENTED(); | 1375 NOTIMPLEMENTED(); |
| 1368 } | 1376 } |
| 1369 | 1377 |
| 1370 } // namespace content | 1378 } // namespace content |
| OLD | NEW |