| OLD | NEW |
| 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 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 } | 384 } |
| 385 | 385 |
| 386 // TODO(krstnmnlsn): This method to be implemented as soon as UpdateDevices can | 386 // TODO(krstnmnlsn): This method to be implemented as soon as UpdateDevices can |
| 387 // handle instances of LowEnergyBluetoothDevice in |devices_|. crbug.com/498009 | 387 // handle instances of LowEnergyBluetoothDevice in |devices_|. crbug.com/498009 |
| 388 void BluetoothAdapterMac::LowEnergyDeviceUpdated( | 388 void BluetoothAdapterMac::LowEnergyDeviceUpdated( |
| 389 CBPeripheral* peripheral, | 389 CBPeripheral* peripheral, |
| 390 NSDictionary* advertisementData, | 390 NSDictionary* advertisementData, |
| 391 int rssi) { | 391 int rssi) { |
| 392 } | 392 } |
| 393 | 393 |
| 394 // TODO(krstnmnlsn): This method assumes all BluetoothDevices in devices_ are | |
| 395 // instances of BluetoothDeviceMac. Add support for low energy devices. | |
| 396 // crbug.com/498009 | |
| 397 void BluetoothAdapterMac::UpdateDevices() { | 394 void BluetoothAdapterMac::UpdateDevices() { |
| 398 // Notify observers if any previously seen devices are no longer available, | 395 // Notify observers if any previously seen devices are no longer available, |
| 399 // i.e. if they are no longer paired, connected, nor recently discovered via | 396 // i.e. if they are no longer paired, connected, nor recently discovered via |
| 400 // an inquiry. | 397 // an inquiry. |
| 401 std::set<std::string> removed_devices; | 398 std::set<std::string> removed_devices; |
| 402 for (DevicesMap::iterator it = devices_.begin(); it != devices_.end(); ++it) { | 399 for (DevicesMap::iterator it = devices_.begin(); it != devices_.end(); ++it) { |
| 403 BluetoothDevice* device = it->second; | 400 BluetoothDevice* device = it->second; |
| 404 if (device->IsPaired() || device->IsConnected()) | 401 if (device->IsPaired() || device->IsConnected()) |
| 405 continue; | 402 continue; |
| 406 | 403 |
| 407 NSDate* last_inquiry_update = | 404 NSDate* last_update_time = |
| 408 static_cast<BluetoothClassicDeviceMac*>(device)->GetLastInquiryUpdate(); | 405 static_cast<BluetoothDeviceMac*>(device)->GetLastUpdateTime(); |
| 409 if (last_inquiry_update && | 406 if (last_update_time && |
| 410 -[last_inquiry_update timeIntervalSinceNow] < kDiscoveryTimeoutSec) | 407 -[last_update_time timeIntervalSinceNow] < kDiscoveryTimeoutSec) |
| 411 continue; | 408 continue; |
| 412 | 409 |
| 413 FOR_EACH_OBSERVER( | 410 FOR_EACH_OBSERVER( |
| 414 BluetoothAdapter::Observer, observers_, DeviceRemoved(this, device)); | 411 BluetoothAdapter::Observer, observers_, DeviceRemoved(this, device)); |
| 415 delete device; | 412 delete device; |
| 416 removed_devices.insert(it->first); | 413 removed_devices.insert(it->first); |
| 417 // The device will be erased from the map in the loop immediately below. | 414 // The device will be erased from the map in the loop immediately below. |
| 418 } | 415 } |
| 419 for (const std::string& device_address : removed_devices) { | 416 for (const std::string& device_address : removed_devices) { |
| 420 size_t num_removed = devices_.erase(device_address); | 417 size_t num_removed = devices_.erase(device_address); |
| 421 DCHECK_EQ(num_removed, 1U); | 418 DCHECK_EQ(num_removed, 1U); |
| 422 } | 419 } |
| 423 | 420 |
| 424 // Add any new paired devices. | 421 // Add any new paired devices. |
| 425 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { | 422 for (IOBluetoothDevice* device in [IOBluetoothDevice pairedDevices]) { |
| 426 ClassicDeviceAdded(device); | 423 ClassicDeviceAdded(device); |
| 427 } | 424 } |
| 428 } | 425 } |
| 429 | 426 |
| 430 } // namespace device | 427 } // namespace device |
| OLD | NEW |