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

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, 6 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 22 matching lines...) Expand all
33 namespace { 33 namespace {
34 34
35 // The frequency with which to poll the adapter for updates. 35 // The frequency with which to poll the adapter for updates.
36 const int kPollIntervalMs = 500; 36 const int kPollIntervalMs = 500;
37 37
38 } // namespace 38 } // namespace
39 39
40 namespace device { 40 namespace device {
41 41
42 // static 42 // static
43 const NSTimeInterval BluetoothAdapterMac::kDiscoveryTimeoutSec =
44 180; // 3 minutes
45
46 // static
47 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter( 43 base::WeakPtr<BluetoothAdapter> BluetoothAdapter::CreateAdapter(
48 const InitCallback& init_callback) { 44 const InitCallback& init_callback) {
49 return BluetoothAdapterMac::CreateAdapter(); 45 return BluetoothAdapterMac::CreateAdapter();
50 } 46 }
51 47
52 // static 48 // static
53 base::WeakPtr<BluetoothAdapterMac> BluetoothAdapterMac::CreateAdapter() { 49 base::WeakPtr<BluetoothAdapterMac> BluetoothAdapterMac::CreateAdapter() {
54 BluetoothAdapterMac* adapter = new BluetoothAdapterMac(); 50 BluetoothAdapterMac* adapter = new BluetoothAdapterMac();
55 adapter->Init(); 51 adapter->Init();
56 return adapter->weak_ptr_factory_.GetWeakPtr(); 52 return adapter->weak_ptr_factory_.GetWeakPtr();
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 VLOG(2) << "LowEnergyDeviceUpdated"; 517 VLOG(2) << "LowEnergyDeviceUpdated";
522 device_mac->Update(advertisement_data, rssi); 518 device_mac->Update(advertisement_data, rssi);
523 // TODO(scheib): Call DeviceChanged only if UUIDs change. crbug.com/547106 519 // TODO(scheib): Call DeviceChanged only if UUIDs change. crbug.com/547106
524 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 520 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
525 DeviceChanged(this, device_mac)); 521 DeviceChanged(this, device_mac));
526 } 522 }
527 523
528 // TODO(krstnmnlsn): Implement. crbug.com/511025 524 // TODO(krstnmnlsn): Implement. crbug.com/511025
529 void BluetoothAdapterMac::LowEnergyCentralManagerUpdatedState() {} 525 void BluetoothAdapterMac::LowEnergyCentralManagerUpdatedState() {}
530 526
531 void BluetoothAdapterMac::RemoveTimedOutDevices() {
532 // Notify observers if any previously seen devices are no longer available,
533 // i.e. if they are no longer paired, connected, nor recently discovered via
534 // an inquiry.
535 std::set<std::string> removed_devices;
536 for (DevicesMap::const_iterator it = devices_.begin(); it != devices_.end();
537 ++it) {
538 BluetoothDevice* device = it->second;
539 if (device->IsPaired() || device->IsConnected())
540 continue;
541
542 NSDate* last_update_time =
543 static_cast<BluetoothDeviceMac*>(device)->GetLastUpdateTime();
544 if (last_update_time &&
545 -[last_update_time timeIntervalSinceNow] < kDiscoveryTimeoutSec)
546 continue;
547
548 FOR_EACH_OBSERVER(
549 BluetoothAdapter::Observer, observers_, DeviceRemoved(this, device));
550 removed_devices.insert(it->first);
551 // The device will be erased from the map in the loop immediately below.
552 }
553 for (const std::string& device_address : removed_devices) {
554 size_t num_removed = devices_.erase(device_address);
555 DCHECK_EQ(num_removed, 1U);
556 }
557 }
558
559 void BluetoothAdapterMac::AddPairedDevices() { 527 void BluetoothAdapterMac::AddPairedDevices() {
560 // Add any new paired devices. 528 // Add any new paired devices.
561 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { 529 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) {
562 ClassicDeviceAdded(device); 530 ClassicDeviceAdded(device);
563 } 531 }
564 } 532 }
565 533
566 void BluetoothAdapterMac::CreateGattConnection( 534 void BluetoothAdapterMac::CreateGattConnection(
567 BluetoothLowEnergyDeviceMac* device_mac) { 535 BluetoothLowEnergyDeviceMac* device_mac) {
568 [low_energy_central_manager_ connectPeripheral:device_mac->peripheral_ 536 [low_energy_central_manager_ connectPeripheral:device_mac->peripheral_
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 std::string device_address = 592 std::string device_address =
625 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); 593 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral);
626 DevicesMap::const_iterator iter = devices_.find(device_address); 594 DevicesMap::const_iterator iter = devices_.find(device_address);
627 if (iter == devices_.end()) { 595 if (iter == devices_.end()) {
628 return nil; 596 return nil;
629 } 597 }
630 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); 598 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second);
631 } 599 }
632 600
633 } // namespace device 601 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698