summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkrstnmnlsn <krstnmnlsn@chromium.org>2015-07-07 13:19:25 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-07 20:19:56 +0000
commit039c562fb57d67d59d784715bfa42d2120f42108 (patch)
treecb440043f61b0e21a49bbbbe3998ba1d001b41a9
parent5926eb7a2a9718b5b313cb1e6c93d25282bf734f (diff)
downloadchromium_src-039c562fb57d67d59d784715bfa42d2120f42108.zip
chromium_src-039c562fb57d67d59d784715bfa42d2120f42108.tar.gz
chromium_src-039c562fb57d67d59d784715bfa42d2120f42108.tar.bz2
Recreated class BluetoothDeviceMac, now as an interface for both
BluetoothClassicDeviceMac and BluetoothLowEnergyDeviceMac. BluetoothDeviceMac declares pure virtual method NSDate* GetLastUpdateTime() which is implemented distinctly by its two subclasses and used by the bluetooth adapter to remove unconnected devices after a timeout. BUG=498009 Review URL: https://codereview.chromium.org/1211013005 Cr-Commit-Position: refs/heads/master@{#337677}
-rw-r--r--device/bluetooth/BUILD.gn2
-rw-r--r--device/bluetooth/bluetooth.gyp2
-rw-r--r--device/bluetooth/bluetooth_adapter_mac.mm11
-rw-r--r--device/bluetooth/bluetooth_classic_device_mac.h9
-rw-r--r--device/bluetooth/bluetooth_classic_device_mac.mm2
-rw-r--r--device/bluetooth/bluetooth_device_mac.h30
-rw-r--r--device/bluetooth/bluetooth_device_mac.mm15
-rw-r--r--device/bluetooth/bluetooth_low_energy_device_mac.h10
-rw-r--r--device/bluetooth/bluetooth_low_energy_device_mac.mm5
9 files changed, 71 insertions, 15 deletions
diff --git a/device/bluetooth/BUILD.gn b/device/bluetooth/BUILD.gn
index efaa325..5307231 100644
--- a/device/bluetooth/BUILD.gn
+++ b/device/bluetooth/BUILD.gn
@@ -57,6 +57,8 @@ component("bluetooth") {
"bluetooth_device.h",
"bluetooth_device_chromeos.cc",
"bluetooth_device_chromeos.h",
+ "bluetooth_device_mac.h",
+ "bluetooth_device_mac.mm",
"bluetooth_device_win.cc",
"bluetooth_device_win.h",
"bluetooth_discovery_filter.cc",
diff --git a/device/bluetooth/bluetooth.gyp b/device/bluetooth/bluetooth.gyp
index 05c3070..c81a26f 100644
--- a/device/bluetooth/bluetooth.gyp
+++ b/device/bluetooth/bluetooth.gyp
@@ -57,6 +57,8 @@
'bluetooth_device.h',
'bluetooth_device_chromeos.cc',
'bluetooth_device_chromeos.h',
+ 'bluetooth_device_mac.mm',
+ 'bluetooth_device_mac.h',
'bluetooth_device_win.cc',
'bluetooth_device_win.h',
'bluetooth_discovery_filter.cc',
diff --git a/device/bluetooth/bluetooth_adapter_mac.mm b/device/bluetooth/bluetooth_adapter_mac.mm
index 107133e..e9586ad 100644
--- a/device/bluetooth/bluetooth_adapter_mac.mm
+++ b/device/bluetooth/bluetooth_adapter_mac.mm
@@ -391,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
@@ -404,10 +401,10 @@ void BluetoothAdapterMac::UpdateDevices() {
if (device->IsPaired() || device->IsConnected())
continue;
- NSDate* last_inquiry_update =
- static_cast<BluetoothClassicDeviceMac*>(device)->GetLastInquiryUpdate();
- if (last_inquiry_update &&
- -[last_inquiry_update timeIntervalSinceNow] < kDiscoveryTimeoutSec)
+ NSDate* last_update_time =
+ static_cast<BluetoothDeviceMac*>(device)->GetLastUpdateTime();
+ if (last_update_time &&
+ -[last_update_time timeIntervalSinceNow] < kDiscoveryTimeoutSec)
continue;
FOR_EACH_OBSERVER(
diff --git a/device/bluetooth/bluetooth_classic_device_mac.h b/device/bluetooth/bluetooth_classic_device_mac.h
index c0426ec..ba6e806 100644
--- a/device/bluetooth/bluetooth_classic_device_mac.h
+++ b/device/bluetooth/bluetooth_classic_device_mac.h
@@ -12,13 +12,13 @@
#include "base/basictypes.h"
#include "base/mac/scoped_nsobject.h"
#include "base/observer_list.h"
-#include "device/bluetooth/bluetooth_device.h"
+#include "device/bluetooth/bluetooth_device_mac.h"
@class IOBluetoothDevice;
namespace device {
-class BluetoothClassicDeviceMac : public BluetoothDevice {
+class BluetoothClassicDeviceMac : public BluetoothDeviceMac {
public:
explicit BluetoothClassicDeviceMac(IOBluetoothDevice* device);
~BluetoothClassicDeviceMac() override;
@@ -64,9 +64,8 @@ class BluetoothClassicDeviceMac : public BluetoothDevice {
const GattConnectionCallback& callback,
const ConnectErrorCallback& error_callback) override;
- // Returns the timestamp when the device was last seen during an inquiry.
- // Returns nil if the device has never been seen during an inquiry.
- NSDate* GetLastInquiryUpdate();
+ // BluetoothDeviceMac override.
+ NSDate* GetLastUpdateTime() const override;
// Returns the Bluetooth address for the |device|. The returned address has a
// normalized format (see below).
diff --git a/device/bluetooth/bluetooth_classic_device_mac.mm b/device/bluetooth/bluetooth_classic_device_mac.mm
index df2b4c7..e3ceae3 100644
--- a/device/bluetooth/bluetooth_classic_device_mac.mm
+++ b/device/bluetooth/bluetooth_classic_device_mac.mm
@@ -232,7 +232,7 @@ void BluetoothClassicDeviceMac::CreateGattConnection(
error_callback.Run(ERROR_UNSUPPORTED_DEVICE);
}
-NSDate* BluetoothClassicDeviceMac::GetLastInquiryUpdate() {
+NSDate* BluetoothClassicDeviceMac::GetLastUpdateTime() const {
return [device_ getLastInquiryUpdate];
}
diff --git a/device/bluetooth/bluetooth_device_mac.h b/device/bluetooth/bluetooth_device_mac.h
new file mode 100644
index 0000000..19d1c75
--- /dev/null
+++ b/device/bluetooth/bluetooth_device_mac.h
@@ -0,0 +1,30 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_MAC_H_
+#define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_MAC_H_
+
+#include "device/bluetooth/bluetooth_device.h"
+
+@class NSDate;
+
+namespace device {
+
+class BluetoothDeviceMac : public BluetoothDevice {
+ public:
+ ~BluetoothDeviceMac() override;
+
+ // Returns the time of the most recent interaction with the device. Returns
+ // nil if the device has never been seen.
+ virtual NSDate* GetLastUpdateTime() const = 0;
+
+ protected:
+ BluetoothDeviceMac();
+
+ DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceMac);
+};
+
+} // namespace device
+
+#endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_MAC_H_
diff --git a/device/bluetooth/bluetooth_device_mac.mm b/device/bluetooth/bluetooth_device_mac.mm
new file mode 100644
index 0000000..dfd1bff
--- /dev/null
+++ b/device/bluetooth/bluetooth_device_mac.mm
@@ -0,0 +1,15 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "device/bluetooth/bluetooth_device_mac.h"
+
+namespace device {
+
+BluetoothDeviceMac::BluetoothDeviceMac() {
+}
+
+BluetoothDeviceMac::~BluetoothDeviceMac() {
+}
+
+} // namespace device
diff --git a/device/bluetooth/bluetooth_low_energy_device_mac.h b/device/bluetooth/bluetooth_low_energy_device_mac.h
index 5fa4335..d8d62ef 100644
--- a/device/bluetooth/bluetooth_low_energy_device_mac.h
+++ b/device/bluetooth/bluetooth_low_energy_device_mac.h
@@ -13,13 +13,13 @@
#include "base/mac/scoped_nsobject.h"
#include "base/mac/sdk_forward_declarations.h"
-#include "device/bluetooth/bluetooth_device.h"
+#include "device/bluetooth/bluetooth_device_mac.h"
namespace device {
class BluetoothLowEnergyDiscoverManagerMac;
-class BluetoothLowEnergyDeviceMac : public BluetoothDevice {
+class BluetoothLowEnergyDeviceMac : public BluetoothDeviceMac {
public:
BluetoothLowEnergyDeviceMac(CBPeripheral* peripheral,
NSDictionary* advertisementData,
@@ -70,6 +70,9 @@ class BluetoothLowEnergyDeviceMac : public BluetoothDevice {
const GattConnectionCallback& callback,
const ConnectErrorCallback& error_callback) override;
+ // BluetoothDeviceMac override.
+ NSDate* GetLastUpdateTime() const override;
+
protected:
// BluetoothDevice override.
std::string GetDeviceName() const override;
@@ -93,6 +96,9 @@ class BluetoothLowEnergyDeviceMac : public BluetoothDevice {
// Whether the device is connectable.
bool connectable_;
+ // Stores the time of the most recent call to Update().
+ base::scoped_nsobject<NSDate> last_update_time_;
+
DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceMac);
};
diff --git a/device/bluetooth/bluetooth_low_energy_device_mac.mm b/device/bluetooth/bluetooth_low_energy_device_mac.mm
index 0357ad9..cd2823c 100644
--- a/device/bluetooth/bluetooth_low_energy_device_mac.mm
+++ b/device/bluetooth/bluetooth_low_energy_device_mac.mm
@@ -75,6 +75,7 @@ BluetoothLowEnergyDeviceMac::~BluetoothLowEnergyDeviceMac() {
void BluetoothLowEnergyDeviceMac::Update(CBPeripheral* peripheral,
NSDictionary* advertisementData,
int rssi) {
+ last_update_time_.reset([[NSDate date] retain]);
peripheral_.reset([peripheral retain]);
rssi_ = rssi;
ClearServiceData();
@@ -226,6 +227,10 @@ void BluetoothLowEnergyDeviceMac::CreateGattConnection(
NOTIMPLEMENTED();
}
+NSDate* BluetoothLowEnergyDeviceMac::GetLastUpdateTime() const {
+ return last_update_time_.get();
+}
+
std::string BluetoothLowEnergyDeviceMac::GetDeviceName() const {
return base::SysNSStringToUTF8([peripheral_ name]);
}