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

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: Fixed unit test for ItemChooserDialog 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.cc
diff --git a/device/bluetooth/bluetooth_adapter.cc b/device/bluetooth/bluetooth_adapter.cc
index dea3593ff1e0d53d1668b49c16b38e246f4bf3f5..8621c27d5dd6af5a58ba686c7d3651a25c1f0510 100644
--- a/device/bluetooth/bluetooth_adapter.cc
+++ b/device/bluetooth/bluetooth_adapter.cc
@@ -345,6 +345,38 @@ BluetoothAdapter::GetMergedDiscoveryFilterHelper(
return result;
}
+void BluetoothAdapter::RemoveTimedOutDevices() {
+ std::set<std::string> removed_devices;
+ for (DevicesMap::const_iterator it = devices_.begin(); it != devices_.end();
+ ++it) {
+ BluetoothDevice* device = it->second;
+
+ if (device->IsPaired() || device->IsConnected())
+ 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)
+ continue;
+ removed_devices.insert(it->first);
+
+ FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
+ DeviceRemoved(this, device));
+ removed_devices.insert(it->first);
+ }
+
+ for (const std::string& device_address : removed_devices) {
+ size_t num_removed = devices_.erase(device_address);
+ DCHECK_EQ(num_removed, 1U);
+ }
+}
+
// static
void BluetoothAdapter::RecordBluetoothDiscoverySessionStartOutcome(
UMABluetoothDiscoverySessionOutcome outcome) {
@@ -361,4 +393,8 @@ void BluetoothAdapter::RecordBluetoothDiscoverySessionStopOutcome(
static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT));
}
+// static
+const base::TimeDelta BluetoothAdapter::timeoutSec =
+ base::TimeDelta::FromSeconds(30);
scheib 2016/04/07 22:05:02 Why 30? Mac was using 180.
perja 2016/04/08 07:47:35 Only reason for this was that we thought 180 secon
+
} // namespace device

Powered by Google App Engine
This is Rietveld 408576698