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

Side by Side 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: Actually remove device before calling DeviceRemoved. Created 4 years, 5 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 for (DevicesMap::iterator it = devices_.begin(); it != devices_.end();) {
370 BluetoothDevice* device = it->second;
371 if (device->IsPaired() || device->IsConnected() ||
372 device->IsGattConnected()) {
373 ++it;
374 continue;
375 }
376
377 base::Time last_update_time = device->GetLastUpdateTime();
378
379 bool device_expired =
380 (base::Time::NowFromSystemTime() - last_update_time) > timeoutSec;
381 VLOG(1) << "device: " << device->GetAddress()
382 << ", last_update: " << last_update_time
383 << ", exp: " << device_expired;
384
385 if (!device_expired) {
386 ++it;
387 continue;
388 }
389 DevicesMap::iterator next = it;
390 next++;
391 std::unique_ptr<BluetoothDevice> removed_device =
392 devices_.take_and_erase(it);
393 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
394
395 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
396 DeviceRemoved(this, removed_device.get()));
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
OLDNEW
« 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