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

Side by Side Diff: device/bluetooth/bluetooth_adapter_mac.mm

Issue 1842223003: Remove outdated devices from Android device chooser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased on master 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "device/bluetooth/bluetooth_adapter_mac.h" 5 #include "device/bluetooth/bluetooth_adapter_mac.h"
6 6
7 #import <IOBluetooth/objc/IOBluetoothDevice.h> 7 #import <IOBluetooth/objc/IOBluetoothDevice.h>
8 #import <IOBluetooth/objc/IOBluetoothHostController.h> 8 #import <IOBluetooth/objc/IOBluetoothHostController.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 23 matching lines...) Expand all
34 namespace { 34 namespace {
35 35
36 // The frequency with which to poll the adapter for updates. 36 // The frequency with which to poll the adapter for updates.
37 const int kPollIntervalMs = 500; 37 const int kPollIntervalMs = 500;
38 38
39 } // namespace 39 } // namespace
40 40
41 namespace device { 41 namespace device {
42 42
43 // static 43 // static
44 const NSTimeInterval BluetoothAdapterMac::kDiscoveryTimeoutSec =
45 180; // 3 minutes
46
47 // static
48 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( 44 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter(
49 const InitCallback& init_callback) { 45 const InitCallback& init_callback) {
50 return BluetoothAdapterMac::CreateAdapter(); 46 return BluetoothAdapterMac::CreateAdapter();
51 } 47 }
52 48
53 // static 49 // static
54 base::WeakPtr<BluetoothAdapterMac> BluetoothAdapterMac::CreateAdapter() { 50 base::WeakPtr<BluetoothAdapterMac> BluetoothAdapterMac::CreateAdapter() {
55 BluetoothAdapterMac* adapter = new BluetoothAdapterMac(); 51 BluetoothAdapterMac* adapter = new BluetoothAdapterMac();
56 adapter->Init(); 52 adapter->Init();
57 return adapter->weak_ptr_factory_.GetWeakPtr(); 53 return adapter->weak_ptr_factory_.GetWeakPtr();
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 VLOG(2) << "LowEnergyDeviceUpdated"; 505 VLOG(2) << "LowEnergyDeviceUpdated";
510 device_mac->Update(advertisement_data, rssi); 506 device_mac->Update(advertisement_data, rssi);
511 // TODO(scheib): Call DeviceChanged only if UUIDs change. crbug.com/547106 507 // TODO(scheib): Call DeviceChanged only if UUIDs change. crbug.com/547106
512 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 508 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
513 DeviceChanged(this, device_mac)); 509 DeviceChanged(this, device_mac));
514 } 510 }
515 511
516 // TODO(krstnmnlsn): Implement. crbug.com/511025 512 // TODO(krstnmnlsn): Implement. crbug.com/511025
517 void BluetoothAdapterMac::LowEnergyCentralManagerUpdatedState() {} 513 void BluetoothAdapterMac::LowEnergyCentralManagerUpdatedState() {}
518 514
519 void BluetoothAdapterMac::RemoveTimedOutDevices() {
520 // Notify observers if any previously seen devices are no longer available,
521 // i.e. if they are no longer paired, connected, nor recently discovered via
522 // an inquiry.
523 std::set<std::string> removed_devices;
524 for (DevicesMap::const_iterator it = devices_.begin(); it != devices_.end();
525 ++it) {
526 BluetoothDevice* device = it->second;
527 if (device->IsPaired() || device->IsConnected())
528 continue;
529
530 NSDate* last_update_time =
531 static_cast<BluetoothDeviceMac*>(device)->GetLastUpdateTime();
532 if (last_update_time &&
533 -[last_update_time timeIntervalSinceNow] < kDiscoveryTimeoutSec)
534 continue;
535
536 FOR_EACH_OBSERVER(
537 BluetoothAdapter::Observer, observers_, DeviceRemoved(this, device));
538 removed_devices.insert(it->first);
539 // The device will be erased from the map in the loop immediately below.
540 }
541 for (const std::string& device_address : removed_devices) {
542 size_t num_removed = devices_.erase(device_address);
543 DCHECK_EQ(num_removed, 1U);
544 }
545 }
546
547 void BluetoothAdapterMac::AddPairedDevices() { 515 void BluetoothAdapterMac::AddPairedDevices() {
548 // Add any new paired devices. 516 // Add any new paired devices.
549 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { 517 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) {
550 ClassicDeviceAdded(device); 518 ClassicDeviceAdded(device);
551 } 519 }
552 } 520 }
553 521
554 void BluetoothAdapterMac::CreateGattConnection( 522 void BluetoothAdapterMac::CreateGattConnection(
555 BluetoothLowEnergyDeviceMac* device_mac) { 523 BluetoothLowEnergyDeviceMac* device_mac) {
556 [low_energy_central_manager_ connectPeripheral:device_mac->peripheral_ 524 [low_energy_central_manager_ connectPeripheral:device_mac->peripheral_
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 std::string device_address = 579 std::string device_address =
612 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); 580 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral);
613 DevicesMap::const_iterator iter = devices_.find(device_address); 581 DevicesMap::const_iterator iter = devices_.find(device_address);
614 if (iter == devices_.end()) { 582 if (iter == devices_.end()) {
615 return nil; 583 return nil;
616 } 584 }
617 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); 585 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second);
618 } 586 }
619 587
620 } // namespace device 588 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698