Chromium Code Reviews| Index: device/bluetooth/bluetooth_adapter.cc |
| diff --git a/device/bluetooth/bluetooth_adapter.cc b/device/bluetooth/bluetooth_adapter.cc |
| index 6153a12d05a53fd9d1da2685feeac66c63c8c6f2..ac6a7f87a57bb7ff8c960ff4fdc4b5d0b7fcedef 100644 |
| --- a/device/bluetooth/bluetooth_adapter.cc |
| +++ b/device/bluetooth/bluetooth_adapter.cc |
| @@ -357,6 +357,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); |
|
scheib
2016/05/06 00:41:50
This line is duplicated above.
|
| + } |
| + |
| + 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) { |
| @@ -373,4 +405,8 @@ void BluetoothAdapter::RecordBluetoothDiscoverySessionStopOutcome( |
| static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT)); |
| } |
| +// static |
| +const base::TimeDelta BluetoothAdapter::timeoutSec = |
| + base::TimeDelta::FromSeconds(180); |
| + |
| } // namespace device |