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

Unified Diff: device/bluetooth/bluetooth_adapter_android.cc

Issue 1842223003: Remove outdated devices from Android device chooser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased on master Created 4 years, 8 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_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,

Powered by Google App Engine
This is Rietveld 408576698