Index: device/bluetooth/bluetooth_discovery_manager_mac.mm |
diff --git a/device/bluetooth/bluetooth_discovery_manager_mac.mm b/device/bluetooth/bluetooth_discovery_manager_mac.mm |
index a2a024d777b29c8614ce7e892e7c16c433f3a5d9..0f4eff0ccde2096f698495543776b8f2273d7f82 100644 |
--- a/device/bluetooth/bluetooth_discovery_manager_mac.mm |
+++ b/device/bluetooth/bluetooth_discovery_manager_mac.mm |
@@ -7,10 +7,13 @@ |
#import <IOBluetooth/objc/IOBluetoothDevice.h> |
#import <IOBluetooth/objc/IOBluetoothDeviceInquiry.h> |
+#include "base/bind.h" |
+#include "base/bind_helpers.h" |
#include "base/logging.h" |
#include "base/mac/scoped_nsobject.h" |
#include "base/mac/sdk_forward_declarations.h" |
#include "base/macros.h" |
+#include "base/timer/timer.h" |
namespace device { |
@@ -31,6 +34,10 @@ class BluetoothDiscoveryManagerMacClassic; |
namespace device { |
+// 1 second between cache clean ups is a good compromise between latency and |
+// performance. |
+const int kCleanCacheTimer = 1; |
Jeffrey Yasskin
2016/09/13 20:58:05
I think you can use a global constexpr TimeDelta n
ortuno
2016/09/14 04:48:25
Argh, I always forget that we should use TimeDelta
|
+ |
// ementation of BluetoothDiscoveryManagerMac for Bluetooth classic device |
// discovery, using the IOBluetooth framework. |
class BluetoothDiscoveryManagerMacClassic |
@@ -43,7 +50,16 @@ class BluetoothDiscoveryManagerMacClassic |
inquiry_delegate_( |
[[BluetoothDeviceInquiryDelegate alloc] initWithManager:this]), |
inquiry_([[IOBluetoothDeviceInquiry alloc] |
- initWithDelegate:inquiry_delegate_]) {} |
+ initWithDelegate:inquiry_delegate_]), |
+ clean_cache_timer_( |
+ FROM_HERE, |
+ base::TimeDelta::FromSeconds(kCleanCacheTimer), |
+ base::Bind( |
+ &BluetoothDiscoveryManagerMacClassic::CleanFoundDevicesCache, |
+ // base::Timer guarantees it won't call back after its |
+ // destructor starts. |
+ base::Unretained(this)), |
+ true /* is_repeating */) {} |
~BluetoothDiscoveryManagerMacClassic() override {} |
@@ -74,6 +90,7 @@ class BluetoothDiscoveryManagerMacClassic |
return false; |
} |
+ clean_cache_timer_.Reset(); |
DVLOG(1) << "Device inquiry start was successful"; |
return true; |
} |
@@ -91,6 +108,9 @@ class BluetoothDiscoveryManagerMacClassic |
} |
DVLOG(1) << "Requesting to stop device inquiry"; |
+ CleanFoundDevicesCache(); |
+ clean_cache_timer_.Stop(); |
+ |
IOReturn status = [inquiry_ stop]; |
if (status == kIOReturnSuccess) { |
DVLOG(1) << "Device inquiry stop was successful"; |
@@ -166,6 +186,8 @@ class BluetoothDiscoveryManagerMacClassic |
} |
private: |
+ void CleanFoundDevicesCache() { [inquiry_ clearFoundDevices]; } |
+ |
// The requested discovery state. |
bool should_do_discovery_; |
@@ -176,6 +198,10 @@ class BluetoothDiscoveryManagerMacClassic |
base::scoped_nsobject<BluetoothDeviceInquiryDelegate> inquiry_delegate_; |
base::scoped_nsobject<IOBluetoothDeviceInquiry> inquiry_; |
+ // Timer to clean up the cache. That way we get notified every time a device |
+ // is seen. |
+ base::Timer clean_cache_timer_; |
+ |
DISALLOW_COPY_AND_ASSIGN(BluetoothDiscoveryManagerMacClassic); |
}; |