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

Unified Diff: device/bluetooth/bluetooth_discovery_manager_mac.mm

Issue 2282763004: bluetooth: mac: Improve classic device discovery and update (Closed)
Patch Set: Add comment and fix comment 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
« no previous file with comments | « device/bluetooth/bluetooth_device.h ('k') | device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
};
« no previous file with comments | « device/bluetooth/bluetooth_device.h ('k') | device/bluetooth/bluetooth_low_energy_discovery_manager_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698