| 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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 | 291 |
| 292 // The following data structures are cleaned up when a | 292 // The following data structures are cleaned up when a |
| 293 // device/service/characteristic is removed. | 293 // device/service/characteristic is removed. |
| 294 // Since this can happen after the test is done and the cleanup function is | 294 // Since this can happen after the test is done and the cleanup function is |
| 295 // called, we clean them here. | 295 // called, we clean them here. |
| 296 service_to_device_.clear(); | 296 service_to_device_.clear(); |
| 297 characteristic_to_service_.clear(); | 297 characteristic_to_service_.clear(); |
| 298 characteristic_id_to_notify_session_.clear(); | 298 characteristic_id_to_notify_session_.clear(); |
| 299 active_characteristic_threads_.clear(); | 299 active_characteristic_threads_.clear(); |
| 300 connections_.clear(); | 300 connections_.clear(); |
| 301 devices_with_discovered_services_.clear(); | |
| 302 } | 301 } |
| 303 | 302 |
| 304 set_adapter(std::move(mock_adapter)); | 303 set_adapter(std::move(mock_adapter)); |
| 305 } | 304 } |
| 306 | 305 |
| 307 BluetoothDispatcherHost::~BluetoothDispatcherHost() { | 306 BluetoothDispatcherHost::~BluetoothDispatcherHost() { |
| 308 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 307 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 309 // Clear adapter, releasing observer references. | 308 // Clear adapter, releasing observer references. |
| 310 set_adapter(scoped_refptr<device::BluetoothAdapter>()); | 309 set_adapter(scoped_refptr<device::BluetoothAdapter>()); |
| 311 } | 310 } |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 } | 492 } |
| 494 } | 493 } |
| 495 | 494 |
| 496 void BluetoothDispatcherHost::GattServicesDiscovered( | 495 void BluetoothDispatcherHost::GattServicesDiscovered( |
| 497 device::BluetoothAdapter* adapter, | 496 device::BluetoothAdapter* adapter, |
| 498 device::BluetoothDevice* device) { | 497 device::BluetoothDevice* device) { |
| 499 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 498 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 500 const std::string& device_id = device->GetAddress(); | 499 const std::string& device_id = device->GetAddress(); |
| 501 VLOG(1) << "Services discovered for device: " << device_id; | 500 VLOG(1) << "Services discovered for device: " << device_id; |
| 502 | 501 |
| 503 devices_with_discovered_services_.insert(device_id); | |
| 504 | |
| 505 auto iter = pending_primary_services_requests_.find(device_id); | 502 auto iter = pending_primary_services_requests_.find(device_id); |
| 506 if (iter == pending_primary_services_requests_.end()) { | 503 if (iter == pending_primary_services_requests_.end()) { |
| 507 return; | 504 return; |
| 508 } | 505 } |
| 509 std::vector<PrimaryServicesRequest> requests; | 506 std::vector<PrimaryServicesRequest> requests; |
| 510 requests.swap(iter->second); | 507 requests.swap(iter->second); |
| 511 pending_primary_services_requests_.erase(iter); | 508 pending_primary_services_requests_.erase(iter); |
| 512 | 509 |
| 513 for (const PrimaryServicesRequest& request : requests) { | 510 for (const PrimaryServicesRequest& request : requests) { |
| 514 std::vector<BluetoothGattService*> services = | 511 std::vector<BluetoothGattService*> services = |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 if (!services.empty()) { | 754 if (!services.empty()) { |
| 758 VLOG(1) << "Service found in device."; | 755 VLOG(1) << "Service found in device."; |
| 759 const BluetoothGattService& service = *services[0]; | 756 const BluetoothGattService& service = *services[0]; |
| 760 DCHECK(service.IsPrimary()); | 757 DCHECK(service.IsPrimary()); |
| 761 AddToServicesMapAndSendGetPrimaryServiceSuccess(service, thread_id, | 758 AddToServicesMapAndSendGetPrimaryServiceSuccess(service, thread_id, |
| 762 request_id); | 759 request_id); |
| 763 return; | 760 return; |
| 764 } | 761 } |
| 765 | 762 |
| 766 // 3. | 763 // 3. |
| 767 if (IsServicesDiscoveryCompleteForDevice(device_id)) { | 764 if (query_result.device->IsGattServicesDiscoveryComplete()) { |
| 768 VLOG(1) << "Service not found in device."; | 765 VLOG(1) << "Service not found in device."; |
| 769 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND); | 766 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND); |
| 770 Send(new BluetoothMsg_GetPrimaryServiceError( | 767 Send(new BluetoothMsg_GetPrimaryServiceError( |
| 771 thread_id, request_id, WebBluetoothError::ServiceNotFound)); | 768 thread_id, request_id, WebBluetoothError::ServiceNotFound)); |
| 772 return; | 769 return; |
| 773 } | 770 } |
| 774 | 771 |
| 775 VLOG(1) << "Adding service request to pending requests."; | 772 VLOG(1) << "Adding service request to pending requests."; |
| 776 // 4. | 773 // 4. |
| 777 AddToPendingPrimaryServicesRequest( | 774 AddToPendingPrimaryServicesRequest( |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1314 result.characteristic = | 1311 result.characteristic = |
| 1315 result.service->GetCharacteristic(characteristic_instance_id); | 1312 result.service->GetCharacteristic(characteristic_instance_id); |
| 1316 | 1313 |
| 1317 if (result.characteristic == nullptr) { | 1314 if (result.characteristic == nullptr) { |
| 1318 result.outcome = CacheQueryOutcome::NO_CHARACTERISTIC; | 1315 result.outcome = CacheQueryOutcome::NO_CHARACTERISTIC; |
| 1319 } | 1316 } |
| 1320 | 1317 |
| 1321 return result; | 1318 return result; |
| 1322 } | 1319 } |
| 1323 | 1320 |
| 1324 bool BluetoothDispatcherHost::IsServicesDiscoveryCompleteForDevice( | |
| 1325 const std::string& device_id) { | |
| 1326 return ContainsKey(devices_with_discovered_services_, device_id); | |
| 1327 } | |
| 1328 | |
| 1329 void BluetoothDispatcherHost::AddToPendingPrimaryServicesRequest( | 1321 void BluetoothDispatcherHost::AddToPendingPrimaryServicesRequest( |
| 1330 const std::string& device_id, | 1322 const std::string& device_id, |
| 1331 const PrimaryServicesRequest& request) { | 1323 const PrimaryServicesRequest& request) { |
| 1332 pending_primary_services_requests_[device_id].push_back(request); | 1324 pending_primary_services_requests_[device_id].push_back(request); |
| 1333 } | 1325 } |
| 1334 | 1326 |
| 1335 void BluetoothDispatcherHost::ShowBluetoothOverviewLink() { | 1327 void BluetoothDispatcherHost::ShowBluetoothOverviewLink() { |
| 1336 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1328 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1337 NOTIMPLEMENTED(); | 1329 NOTIMPLEMENTED(); |
| 1338 } | 1330 } |
| 1339 | 1331 |
| 1340 void BluetoothDispatcherHost::ShowBluetoothPairingLink() { | 1332 void BluetoothDispatcherHost::ShowBluetoothPairingLink() { |
| 1341 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1333 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1342 NOTIMPLEMENTED(); | 1334 NOTIMPLEMENTED(); |
| 1343 } | 1335 } |
| 1344 | 1336 |
| 1345 void BluetoothDispatcherHost::ShowBluetoothAdapterOffLink() { | 1337 void BluetoothDispatcherHost::ShowBluetoothAdapterOffLink() { |
| 1346 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1338 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1347 NOTIMPLEMENTED(); | 1339 NOTIMPLEMENTED(); |
| 1348 } | 1340 } |
| 1349 | 1341 |
| 1350 void BluetoothDispatcherHost::ShowNeedLocationLink() { | 1342 void BluetoothDispatcherHost::ShowNeedLocationLink() { |
| 1351 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1343 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1352 NOTIMPLEMENTED(); | 1344 NOTIMPLEMENTED(); |
| 1353 } | 1345 } |
| 1354 | 1346 |
| 1355 } // namespace content | 1347 } // namespace content |
| OLD | NEW |