Chromium Code Reviews| Index: device/bluetooth/bluetooth_adapter_mac.mm |
| diff --git a/device/bluetooth/bluetooth_adapter_mac.mm b/device/bluetooth/bluetooth_adapter_mac.mm |
| index bf6cf4bd40e8625b17a65775aa137f6fdfdccc3e..2506ad61dc8f30c8fa2f5807b8397ed290e4deeb 100644 |
| --- a/device/bluetooth/bluetooth_adapter_mac.mm |
| +++ b/device/bluetooth/bluetooth_adapter_mac.mm |
| @@ -21,7 +21,7 @@ |
| #include "base/strings/sys_string_conversions.h" |
| #include "base/thread_task_runner_handle.h" |
| #include "base/time/time.h" |
| -#include "device/bluetooth/bluetooth_device_mac.h" |
| +#include "device/bluetooth/bluetooth_classic_device_mac.h" |
| #include "device/bluetooth/bluetooth_discovery_session.h" |
| #include "device/bluetooth/bluetooth_socket_mac.h" |
| #include "device/bluetooth/bluetooth_uuid.h" |
| @@ -171,7 +171,7 @@ void BluetoothAdapterMac::DeviceConnected(IOBluetoothDevice* device) { |
| // TODO(isherman): Investigate whether this method can be replaced with a call |
| // to +registerForConnectNotifications:selector:. |
| DVLOG(1) << "Adapter registered a new connection from device with address: " |
| - << BluetoothDeviceMac::GetDeviceAddress(device); |
| + << BluetoothClassicDeviceMac::GetDeviceAddress(device); |
| ClassicDeviceAdded(device); |
| } |
| @@ -370,13 +370,14 @@ void BluetoothAdapterMac::PollAdapter() { |
| } |
| void BluetoothAdapterMac::ClassicDeviceAdded(IOBluetoothDevice* device) { |
| - std::string device_address = BluetoothDeviceMac::GetDeviceAddress(device); |
| + std::string device_address = |
| + BluetoothClassicDeviceMac::GetDeviceAddress(device); |
| // Only notify observers once per device. |
| if (devices_.count(device_address)) |
| return; |
| - devices_[device_address] = new BluetoothDeviceMac(device); |
| + devices_[device_address] = new BluetoothClassicDeviceMac(device); |
| FOR_EACH_OBSERVER(BluetoothAdapter::Observer, |
| observers_, |
| DeviceAdded(this, devices_[device_address])); |
| @@ -390,9 +391,6 @@ void BluetoothAdapterMac::LowEnergyDeviceUpdated( |
| int rssi) { |
| } |
| -// TODO(krstnmnlsn): This method assumes all BluetoothDevices in devices_ are |
| -// instances of BluetoothDeviceMac. Add support for low energy devices. |
| -// crbug.com/498009 |
| void BluetoothAdapterMac::UpdateDevices() { |
| // Notify observers if any previously seen devices are no longer available, |
| // i.e. if they are no longer paired, connected, nor recently discovered via |
| @@ -403,10 +401,24 @@ void BluetoothAdapterMac::UpdateDevices() { |
| if (device->IsPaired() || device->IsConnected()) |
| continue; |
| - NSDate* last_inquiry_update = |
| - static_cast<BluetoothDeviceMac*>(device)->GetLastInquiryUpdate(); |
| - if (last_inquiry_update && |
| - -[last_inquiry_update timeIntervalSinceNow] < kDiscoveryTimeoutSec) |
| + // The device must support exactly one of Classic or Low Energy because this |
| + // indicates to us its class. Run time type checking is required here as |
| + // BluetoothDevice does not currently support giving timing information (it |
|
scheib
2015/06/29 20:44:24
Drop reference to ChromeOS. How about just
"Device
krstnmnlsn
2015/06/30 00:50:35
Done. See https://codereview.chromium.org/12110130
|
| + // was unnecessary on ChromeOS). |
| + DCHECK((device->SupportsClassic() || device->SupportsLowEnergy()) && |
| + !(device->SupportsClassic() && device->SupportsLowEnergy())); |
| + NSDate* last_update = [NSDate dateWithTimeIntervalSince1970:0]; |
| + if (device->SupportsClassic()) { |
| + last_update = static_cast<BluetoothClassicDeviceMac*>(device) |
| + ->GetLastInquiryUpdate(); |
| + } |
| + if (device->SupportsLowEnergy()) { |
| + last_update = static_cast<BluetoothLowEnergyDeviceMac*>(device) |
| + ->GetLastCallToUpdate(); |
| + } |
| + |
| + if (last_update && |
| + -[last_update timeIntervalSinceNow] < kDiscoveryTimeoutSec) |
| continue; |
| FOR_EACH_OBSERVER( |