Chromium Code Reviews| 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..39bba1e8d215648d6149e71346cd67ef1829721d 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,8 @@ class BluetoothDiscoveryManagerMacClassic; |
| namespace device { |
| +const int kCleanCacheTimer = 1; |
|
scheib
2016/08/29 02:42:32
Comment explaining why we're using 1. And include
ortuno
2016/09/13 08:02:04
Done.
|
| + |
| // ementation of BluetoothDiscoveryManagerMac for Bluetooth classic device |
| // discovery, using the IOBluetooth framework. |
| class BluetoothDiscoveryManagerMacClassic |
| @@ -43,7 +48,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 +88,7 @@ class BluetoothDiscoveryManagerMacClassic |
| return false; |
| } |
| + clean_cache_timer_.Reset(); |
| DVLOG(1) << "Device inquiry start was successful"; |
| return true; |
| } |
| @@ -91,6 +106,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 +184,8 @@ class BluetoothDiscoveryManagerMacClassic |
| } |
| private: |
| + void CleanFoundDevicesCache() { [inquiry_ clearFoundDevices]; } |
| + |
| // The requested discovery state. |
| bool should_do_discovery_; |
| @@ -176,6 +196,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); |
| }; |