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

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, 6 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 c642e03a005a21ed06fa744274e98da7af34edb0..c66afdd4234947caabff017982da7821b805088c 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/threading/thread_task_runner_handle.h"
@@ -38,6 +40,9 @@ base::WeakPtr<BluetoothAdapterAndroid> BluetoothAdapterAndroid::Create(
AttachCurrentThread(), reinterpret_cast<intptr_t>(adapter),
bluetooth_adapter_wrapper));
+ adapter->ui_task_runner_ = base::ThreadTaskRunnerHandle::Get();
+ adapter->PurgeTimedOutDevices();
ortuno 2016/06/14 15:29:33 I don't think we want to be purging devices all th
perja 2016/06/15 13:03:40 Acknowledged.
+
return adapter->weak_ptr_factory_.GetWeakPtr();
}
@@ -175,6 +180,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_,
@@ -183,6 +189,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));
@@ -198,6 +205,18 @@ BluetoothAdapterAndroid::~BluetoothAdapterAndroid() {
AttachCurrentThread(), j_adapter_.obj());
}
+void BluetoothAdapterAndroid::PurgeTimedOutDevices() {
+ RemoveTimedOutDevices();
+ int pollIntervalMs = 11000;
ortuno 2016/06/14 15:29:33 Make these enums: namespace { // TODO add a com
perja 2016/06/15 13:03:40 Acknowledged.
+ if (IsDiscovering()) {
+ pollIntervalMs = 1000;
+ }
+ ui_task_runner_->PostDelayedTask(
ortuno 2016/06/14 15:29:33 I think what Vince was suggesting was that we run
perja 2016/06/15 13:03:40 Acknowledged.
+ FROM_HERE, base::Bind(&BluetoothAdapterAndroid::PurgeTimedOutDevices,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::TimeDelta::FromMilliseconds(pollIntervalMs));
+}
+
void BluetoothAdapterAndroid::AddDiscoverySession(
BluetoothDiscoveryFilter* discovery_filter,
const base::Closure& callback,

Powered by Google App Engine
This is Rietveld 408576698