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

Unified Diff: device/bluetooth/bluetooth_adapter.cc

Issue 1842223003: Remove outdated devices from Android device chooser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reverted two small unnecessary changes. 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
« no previous file with comments | « device/bluetooth/bluetooth_adapter.h ('k') | device/bluetooth/bluetooth_adapter_android.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_adapter.cc
diff --git a/device/bluetooth/bluetooth_adapter.cc b/device/bluetooth/bluetooth_adapter.cc
index 19b70d9184e24cf308106a31c4373dfbc90366a0..6d997515ac3162344e91d835b5d74c4a4fc052a5 100644
--- a/device/bluetooth/bluetooth_adapter.cc
+++ b/device/bluetooth/bluetooth_adapter.cc
@@ -365,6 +365,38 @@ BluetoothAdapter::GetMergedDiscoveryFilterHelper(
return result;
}
+void BluetoothAdapter::RemoveTimedOutDevices() {
+ for (DevicesMap::iterator it = devices_.begin(); it != devices_.end();) {
+ BluetoothDevice* device = it->second;
+ if (device->IsPaired() || device->IsConnected() ||
+ device->IsGattConnected()) {
+ ++it;
+ continue;
+ }
+
+ base::Time last_update_time = device->GetLastUpdateTime();
+
+ bool device_expired =
+ (base::Time::NowFromSystemTime() - last_update_time) > timeoutSec;
+ VLOG(1) << "device: " << device->GetAddress()
+ << ", last_update: " << last_update_time
+ << ", exp: " << device_expired;
+
+ if (!device_expired) {
+ ++it;
+ continue;
+ }
+ DevicesMap::iterator next = it;
+ next++;
+ std::unique_ptr<BluetoothDevice> removed_device =
+ devices_.take_and_erase(it);
+ it = next;
+
+ FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
+ DeviceRemoved(this, removed_device.get()));
+ }
+}
+
// static
void BluetoothAdapter::RecordBluetoothDiscoverySessionStartOutcome(
UMABluetoothDiscoverySessionOutcome outcome) {
@@ -381,4 +413,8 @@ void BluetoothAdapter::RecordBluetoothDiscoverySessionStopOutcome(
static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT));
}
+// static
+const base::TimeDelta BluetoothAdapter::timeoutSec =
+ base::TimeDelta::FromSeconds(180);
+
} // namespace device
« no previous file with comments | « device/bluetooth/bluetooth_adapter.h ('k') | device/bluetooth/bluetooth_adapter_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698