Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/bluetooth/bluetooth_adapter.h" | 5 #include "device/bluetooth/bluetooth_adapter.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 } | 358 } |
| 359 continue; | 359 continue; |
| 360 } | 360 } |
| 361 | 361 |
| 362 result = BluetoothDiscoveryFilter::Merge(result.get(), curr_filter); | 362 result = BluetoothDiscoveryFilter::Merge(result.get(), curr_filter); |
| 363 } | 363 } |
| 364 | 364 |
| 365 return result; | 365 return result; |
| 366 } | 366 } |
| 367 | 367 |
| 368 void BluetoothAdapter::RemoveTimedOutDevices() { | |
| 369 std::set<std::string> removed_devices; | |
| 370 for (DevicesMap::const_iterator it = devices_.begin(); it != devices_.end(); | |
| 371 ++it) { | |
| 372 BluetoothDevice* device = it->second; | |
| 373 | |
| 374 if (device->IsPaired() || device->IsConnected() || | |
| 375 device->IsGattConnected()) | |
| 376 continue; | |
| 377 | |
| 378 base::Time last_update_time = device->GetLastUpdateTime(); | |
| 379 | |
| 380 bool device_expired = | |
| 381 (base::Time::NowFromSystemTime() - last_update_time) > timeoutSec; | |
| 382 VLOG(1) << "device: " << device->GetAddress() | |
| 383 << ", last_update: " << last_update_time | |
| 384 << ", exp: " << device_expired; | |
| 385 | |
| 386 if (!device_expired) | |
| 387 continue; | |
| 388 removed_devices.insert(it->first); | |
|
ortuno
2016/06/22 17:23:11
nit: I would change removed_devices to be a std::v
perja
2016/06/23 14:31:25
I used a slightly different approach. Please take
| |
| 389 | |
| 390 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, | |
| 391 DeviceRemoved(this, device)); | |
| 392 } | |
| 393 | |
| 394 for (const std::string& device_address : removed_devices) { | |
| 395 size_t num_removed = devices_.erase(device_address); | |
| 396 DCHECK_EQ(num_removed, 1U); | |
| 397 } | |
| 398 } | |
| 399 | |
| 368 // static | 400 // static |
| 369 void BluetoothAdapter::RecordBluetoothDiscoverySessionStartOutcome( | 401 void BluetoothAdapter::RecordBluetoothDiscoverySessionStartOutcome( |
| 370 UMABluetoothDiscoverySessionOutcome outcome) { | 402 UMABluetoothDiscoverySessionOutcome outcome) { |
| 371 UMA_HISTOGRAM_ENUMERATION( | 403 UMA_HISTOGRAM_ENUMERATION( |
| 372 "Bluetooth.DiscoverySession.Start.Outcome", static_cast<int>(outcome), | 404 "Bluetooth.DiscoverySession.Start.Outcome", static_cast<int>(outcome), |
| 373 static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT)); | 405 static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT)); |
| 374 } | 406 } |
| 375 | 407 |
| 376 // static | 408 // static |
| 377 void BluetoothAdapter::RecordBluetoothDiscoverySessionStopOutcome( | 409 void BluetoothAdapter::RecordBluetoothDiscoverySessionStopOutcome( |
| 378 UMABluetoothDiscoverySessionOutcome outcome) { | 410 UMABluetoothDiscoverySessionOutcome outcome) { |
| 379 UMA_HISTOGRAM_ENUMERATION( | 411 UMA_HISTOGRAM_ENUMERATION( |
| 380 "Bluetooth.DiscoverySession.Stop.Outcome", static_cast<int>(outcome), | 412 "Bluetooth.DiscoverySession.Stop.Outcome", static_cast<int>(outcome), |
| 381 static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT)); | 413 static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT)); |
| 382 } | 414 } |
| 383 | 415 |
| 416 // static | |
| 417 const base::TimeDelta BluetoothAdapter::timeoutSec = | |
| 418 base::TimeDelta::FromSeconds(180); | |
| 419 | |
| 384 } // namespace device | 420 } // namespace device |
| OLD | NEW |