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

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: Fixed unit test for ItemChooserDialog Created 4 years, 8 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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 VLOG(2) << "LowEnergyDeviceUpdated"; 504 VLOG(2) << "LowEnergyDeviceUpdated";
509 device_mac->Update(advertisement_data, rssi); 505 device_mac->Update(advertisement_data, rssi);
510 // TODO(scheib): Call DeviceChanged only if UUIDs change. crbug.com/547106 506 // TODO(scheib): Call DeviceChanged only if UUIDs change. crbug.com/547106
511 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, 507 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
512 DeviceChanged(this, device_mac)); 508 DeviceChanged(this, device_mac));
513 } 509 }
514 510
515 // TODO(krstnmnlsn): Implement. crbug.com/511025 511 // TODO(krstnmnlsn): Implement. crbug.com/511025
516 void BluetoothAdapterMac::LowEnergyCentralManagerUpdatedState() {} 512 void BluetoothAdapterMac::LowEnergyCentralManagerUpdatedState() {}
517 513
518 void BluetoothAdapterMac::RemoveTimedOutDevices() {
519 // Notify observers if any previously seen devices are no longer available,
520 // i.e. if they are no longer paired, connected, nor recently discovered via
521 // an inquiry.
522 std::set<std::string> removed_devices;
523 for (DevicesMap::const_iterator it = devices_.begin(); it != devices_.end();
524 ++it) {
525 BluetoothDevice* device = it->second;
526 if (device->IsPaired() || device->IsConnected())
527 continue;
528
529 NSDate* last_update_time =
530 static_cast<BluetoothDeviceMac*>(device)->GetLastUpdateTime();
531 if (last_update_time &&
532 -[last_update_time timeIntervalSinceNow] < kDiscoveryTimeoutSec)
533 continue;
534
535 FOR_EACH_OBSERVER(
536 BluetoothAdapter::Observer, observers_, DeviceRemoved(this, device));
537 removed_devices.insert(it->first);
538 // The device will be erased from the map in the loop immediately below.
539 }
540 for (const std::string& device_address : removed_devices) {
541 size_t num_removed = devices_.erase(device_address);
542 DCHECK_EQ(num_removed, 1U);
543 }
544 }
545
546 void BluetoothAdapterMac::AddPairedDevices() { 514 void BluetoothAdapterMac::AddPairedDevices() {
547 // Add any new paired devices. 515 // Add any new paired devices.
548 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { 516 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) {
549 ClassicDeviceAdded(device); 517 ClassicDeviceAdded(device);
550 } 518 }
551 } 519 }
552 520
553 void BluetoothAdapterMac::CreateGattConnection( 521 void BluetoothAdapterMac::CreateGattConnection(
554 BluetoothLowEnergyDeviceMac* device_mac) { 522 BluetoothLowEnergyDeviceMac* device_mac) {
555 [low_energy_central_manager_ connectPeripheral:device_mac->peripheral_ 523 [low_energy_central_manager_ connectPeripheral:device_mac->peripheral_
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 std::string device_address = 578 std::string device_address =
611 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral); 579 BluetoothLowEnergyDeviceMac::GetPeripheralHashAddress(peripheral);
612 DevicesMap::const_iterator iter = devices_.find(device_address); 580 DevicesMap::const_iterator iter = devices_.find(device_address);
613 if (iter == devices_.end()) { 581 if (iter == devices_.end()) {
614 return nil; 582 return nil;
615 } 583 }
616 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second); 584 return static_cast<BluetoothLowEnergyDeviceMac*>(iter->second);
617 } 585 }
618 586
619 } // namespace device 587 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698