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

Unified Diff: device/bluetooth/bluetooth_discovery_manager_mac.mm

Issue 2282763004: bluetooth: mac: Improve classic device discovery and update (Closed)
Patch Set: Override getlastupdate and make constexpr Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
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..5a066833e403f573cdc475d0763d13f6b1ad2d4a 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.
+constexpr base::TimeDelta kCleanCacheDelay = base::TimeDelta::FromSeconds(1);
+
// 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,
+ kCleanCacheDelay,
+ 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,8 @@ class BluetoothDiscoveryManagerMacClassic
return false;
}
+ CleanFoundDevicesCache();
+ clean_cache_timer_.Reset();
DVLOG(1) << "Device inquiry start was successful";
return true;
}
@@ -91,6 +109,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 +187,8 @@ class BluetoothDiscoveryManagerMacClassic
}
private:
+ void CleanFoundDevicesCache() { [inquiry_ clearFoundDevices]; }
+
// The requested discovery state.
bool should_do_discovery_;
@@ -176,6 +199,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);
};

Powered by Google App Engine
This is Rietveld 408576698