Chromium Code Reviews| Index: device/bluetooth/bluetooth_adapter.cc |
| diff --git a/device/bluetooth/bluetooth_adapter.cc b/device/bluetooth/bluetooth_adapter.cc |
| index 09127f981cb48ec266570c74a803285da6f33141..d10faea101ab31ce7383bd18f1d58289f5c27b0f 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; |
|
ortuno
2016/06/23 15:42:59
Any special reason why you manually copy and incre
ortuno
2016/06/23 17:57:33
Discussed this with scheib. I see why this is the
|
| + |
| + 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 |