Index: device/bluetooth/bluetooth_adapter_android.cc |
diff --git a/device/bluetooth/bluetooth_adapter_android.cc b/device/bluetooth/bluetooth_adapter_android.cc |
index 7e749984d1dcdcb305477c50136f4167c9dd745c..3b7be31800e4a9f456d28a77bd203ca7e1986bac 100644 |
--- a/device/bluetooth/bluetooth_adapter_android.cc |
+++ b/device/bluetooth/bluetooth_adapter_android.cc |
@@ -8,6 +8,8 @@ |
#include "base/android/jni_android.h" |
#include "base/android/jni_string.h" |
+#include "base/bind.h" |
+#include "base/location.h" |
#include "base/sequenced_task_runner.h" |
#include "base/single_thread_task_runner.h" |
#include "base/thread_task_runner_handle.h" |
@@ -170,6 +172,7 @@ void BluetoothAdapterAndroid::CreateOrUpdateDeviceOnScan( |
BluetoothDeviceAndroid* device_android = |
BluetoothDeviceAndroid::Create(this, bluetooth_device_wrapper); |
device_android->UpdateAdvertisedUUIDs(advertised_uuids); |
+ device_android->UpdateTimestamp(); |
devices_.add(device_address, |
std::unique_ptr<BluetoothDevice>(device_android)); |
FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
@@ -178,6 +181,7 @@ void BluetoothAdapterAndroid::CreateOrUpdateDeviceOnScan( |
// Existing device. |
BluetoothDeviceAndroid* device_android = |
static_cast<BluetoothDeviceAndroid*>(iter->second); |
+ device_android->UpdateTimestamp(); |
if (device_android->UpdateAdvertisedUUIDs(advertised_uuids)) { |
FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, |
DeviceChanged(this, device_android)); |
@@ -186,6 +190,8 @@ void BluetoothAdapterAndroid::CreateOrUpdateDeviceOnScan( |
} |
BluetoothAdapterAndroid::BluetoothAdapterAndroid() : weak_ptr_factory_(this) { |
+ ui_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
+ PurgeTimedOutDevices(); |
} |
BluetoothAdapterAndroid::~BluetoothAdapterAndroid() { |
@@ -193,6 +199,14 @@ BluetoothAdapterAndroid::~BluetoothAdapterAndroid() { |
AttachCurrentThread(), j_adapter_.obj()); |
} |
+void BluetoothAdapterAndroid::PurgeTimedOutDevices() { |
+ RemoveTimedOutDevices(); |
+ ui_task_runner_->PostDelayedTask( |
+ FROM_HERE, base::Bind(&BluetoothAdapterAndroid::PurgeTimedOutDevices, |
+ weak_ptr_factory_.GetWeakPtr()), |
+ base::TimeDelta::FromMilliseconds(5000)); |
+} |
+ |
void BluetoothAdapterAndroid::AddDiscoverySession( |
BluetoothDiscoveryFilter* discovery_filter, |
const base::Closure& callback, |