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

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

Issue 1592733002: Clear the BLE services list on disconnect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix the bluetooth/getPrimaryService.html timeout issue Created 4 years, 11 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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
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();
326 } 325 }
327 326
328 set_adapter(std::move(mock_adapter)); 327 set_adapter(std::move(mock_adapter));
329 } 328 }
330 329
331 BluetoothDispatcherHost::~BluetoothDispatcherHost() { 330 BluetoothDispatcherHost::~BluetoothDispatcherHost() {
332 DCHECK_CURRENTLY_ON(BrowserThread::UI); 331 DCHECK_CURRENTLY_ON(BrowserThread::UI);
333 // Clear adapter, releasing observer references. 332 // Clear adapter, releasing observer references.
334 set_adapter(scoped_refptr<device::BluetoothAdapter>()); 333 set_adapter(scoped_refptr<device::BluetoothAdapter>());
335 } 334 }
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 } 516 }
518 } 517 }
519 518
520 void BluetoothDispatcherHost::GattServicesDiscovered( 519 void BluetoothDispatcherHost::GattServicesDiscovered(
521 device::BluetoothAdapter* adapter, 520 device::BluetoothAdapter* adapter,
522 device::BluetoothDevice* device) { 521 device::BluetoothDevice* device) {
523 DCHECK_CURRENTLY_ON(BrowserThread::UI); 522 DCHECK_CURRENTLY_ON(BrowserThread::UI);
524 const std::string& device_id = device->GetAddress(); 523 const std::string& device_id = device->GetAddress();
525 VLOG(1) << "Services discovered for device: " << device_id; 524 VLOG(1) << "Services discovered for device: " << device_id;
526 525
527 devices_with_discovered_services_.insert(device_id);
528
529 auto iter = pending_primary_services_requests_.find(device_id); 526 auto iter = pending_primary_services_requests_.find(device_id);
530 if (iter == pending_primary_services_requests_.end()) { 527 if (iter == pending_primary_services_requests_.end()) {
531 return; 528 return;
532 } 529 }
533 std::vector<PrimaryServicesRequest> requests; 530 std::vector<PrimaryServicesRequest> requests;
534 requests.swap(iter->second); 531 requests.swap(iter->second);
535 pending_primary_services_requests_.erase(iter); 532 pending_primary_services_requests_.erase(iter);
536 533
537 for (const PrimaryServicesRequest& request : requests) { 534 for (const PrimaryServicesRequest& request : requests) {
538 std::vector<BluetoothGattService*> services = 535 std::vector<BluetoothGattService*> services =
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 if (!services.empty()) { 778 if (!services.empty()) {
782 VLOG(1) << "Service found in device."; 779 VLOG(1) << "Service found in device.";
783 const BluetoothGattService& service = *services[0]; 780 const BluetoothGattService& service = *services[0];
784 DCHECK(service.IsPrimary()); 781 DCHECK(service.IsPrimary());
785 AddToServicesMapAndSendGetPrimaryServiceSuccess(service, thread_id, 782 AddToServicesMapAndSendGetPrimaryServiceSuccess(service, thread_id,
786 request_id); 783 request_id);
787 return; 784 return;
788 } 785 }
789 786
790 // 3. 787 // 3.
791 if (IsServicesDiscoveryCompleteForDevice(device_id)) { 788 if (query_result.device->IsGattServicesDiscoveryComplete()) {
792 VLOG(1) << "Service not found in device."; 789 VLOG(1) << "Service not found in device.";
793 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND); 790 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND);
794 Send(new BluetoothMsg_GetPrimaryServiceError( 791 Send(new BluetoothMsg_GetPrimaryServiceError(
795 thread_id, request_id, WebBluetoothError::ServiceNotFound)); 792 thread_id, request_id, WebBluetoothError::ServiceNotFound));
796 return; 793 return;
797 } 794 }
798 795
799 VLOG(1) << "Adding service request to pending requests."; 796 VLOG(1) << "Adding service request to pending requests.";
800 // 4. 797 // 4.
801 AddToPendingPrimaryServicesRequest( 798 AddToPendingPrimaryServicesRequest(
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 result.characteristic = 1334 result.characteristic =
1338 result.service->GetCharacteristic(characteristic_instance_id); 1335 result.service->GetCharacteristic(characteristic_instance_id);
1339 1336
1340 if (result.characteristic == nullptr) { 1337 if (result.characteristic == nullptr) {
1341 result.outcome = CacheQueryOutcome::NO_CHARACTERISTIC; 1338 result.outcome = CacheQueryOutcome::NO_CHARACTERISTIC;
1342 } 1339 }
1343 1340
1344 return result; 1341 return result;
1345 } 1342 }
1346 1343
1347 bool BluetoothDispatcherHost::IsServicesDiscoveryCompleteForDevice(
1348 const std::string& device_id) {
1349 return ContainsKey(devices_with_discovered_services_, device_id);
1350 }
1351
1352 void BluetoothDispatcherHost::AddToPendingPrimaryServicesRequest( 1344 void BluetoothDispatcherHost::AddToPendingPrimaryServicesRequest(
1353 const std::string& device_id, 1345 const std::string& device_id,
1354 const PrimaryServicesRequest& request) { 1346 const PrimaryServicesRequest& request) {
1355 pending_primary_services_requests_[device_id].push_back(request); 1347 pending_primary_services_requests_[device_id].push_back(request);
1356 } 1348 }
1357 1349
1358 void BluetoothDispatcherHost::ShowBluetoothOverviewLink() { 1350 void BluetoothDispatcherHost::ShowBluetoothOverviewLink() {
1359 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1351 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1360 NOTIMPLEMENTED(); 1352 NOTIMPLEMENTED();
1361 } 1353 }
1362 1354
1363 void BluetoothDispatcherHost::ShowBluetoothPairingLink() { 1355 void BluetoothDispatcherHost::ShowBluetoothPairingLink() {
1364 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1356 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1365 NOTIMPLEMENTED(); 1357 NOTIMPLEMENTED();
1366 } 1358 }
1367 1359
1368 void BluetoothDispatcherHost::ShowBluetoothAdapterOffLink() { 1360 void BluetoothDispatcherHost::ShowBluetoothAdapterOffLink() {
1369 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1361 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1370 NOTIMPLEMENTED(); 1362 NOTIMPLEMENTED();
1371 } 1363 }
1372 1364
1373 void BluetoothDispatcherHost::ShowNeedLocationLink() { 1365 void BluetoothDispatcherHost::ShowNeedLocationLink() {
1374 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1366 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1375 NOTIMPLEMENTED(); 1367 NOTIMPLEMENTED();
1376 } 1368 }
1377 1369
1378 } // namespace content 1370 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698