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

Side by Side Diff: device/bluetooth/bluetooth_adapter.cc

Issue 2567903004: Replace ScopedVector/ScopedPtrHashMap with std::vector and std::unordered_map (Closed)
Patch Set: Mac bustage Created 3 years, 12 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
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 DeviceList devices; 103 DeviceList devices;
104 for (ConstDeviceList::const_iterator i = const_devices.begin(); 104 for (ConstDeviceList::const_iterator i = const_devices.begin();
105 i != const_devices.end(); ++i) 105 i != const_devices.end(); ++i)
106 devices.push_back(const_cast<BluetoothDevice *>(*i)); 106 devices.push_back(const_cast<BluetoothDevice *>(*i));
107 107
108 return devices; 108 return devices;
109 } 109 }
110 110
111 BluetoothAdapter::ConstDeviceList BluetoothAdapter::GetDevices() const { 111 BluetoothAdapter::ConstDeviceList BluetoothAdapter::GetDevices() const {
112 ConstDeviceList devices; 112 ConstDeviceList devices;
113 for (DevicesMap::const_iterator iter = devices_.begin(); 113 for (auto& device : devices_)
114 iter != devices_.end(); 114 devices.push_back(device.second.get());
115 ++iter)
116 devices.push_back(iter->second);
117 115
118 return devices; 116 return devices;
119 } 117 }
120 118
121 BluetoothDevice* BluetoothAdapter::GetDevice(const std::string& address) { 119 BluetoothDevice* BluetoothAdapter::GetDevice(const std::string& address) {
122 return const_cast<BluetoothDevice *>( 120 return const_cast<BluetoothDevice *>(
123 const_cast<const BluetoothAdapter *>(this)->GetDevice(address)); 121 const_cast<const BluetoothAdapter *>(this)->GetDevice(address));
124 } 122 }
125 123
126 const BluetoothDevice* BluetoothAdapter::GetDevice( 124 const BluetoothDevice* BluetoothAdapter::GetDevice(
127 const std::string& address) const { 125 const std::string& address) const {
128 std::string canonicalized_address = 126 std::string canonicalized_address =
129 BluetoothDevice::CanonicalizeAddress(address); 127 BluetoothDevice::CanonicalizeAddress(address);
130 if (canonicalized_address.empty()) 128 if (canonicalized_address.empty())
131 return nullptr; 129 return nullptr;
132 130
133 DevicesMap::const_iterator iter = devices_.find(canonicalized_address); 131 DevicesMap::const_iterator iter = devices_.find(canonicalized_address);
134 if (iter != devices_.end()) 132 if (iter != devices_.end())
135 return iter->second; 133 return iter->second.get();
136 134
137 return nullptr; 135 return nullptr;
138 } 136 }
139 137
140 void BluetoothAdapter::AddPairingDelegate( 138 void BluetoothAdapter::AddPairingDelegate(
141 BluetoothDevice::PairingDelegate* pairing_delegate, 139 BluetoothDevice::PairingDelegate* pairing_delegate,
142 PairingDelegatePriority priority) { 140 PairingDelegatePriority priority) {
143 // Remove the delegate, if it already exists, before inserting to allow a 141 // Remove the delegate, if it already exists, before inserting to allow a
144 // change of priority. 142 // change of priority.
145 RemovePairingDelegate(pairing_delegate); 143 RemovePairingDelegate(pairing_delegate);
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 } 368 }
371 369
372 result = BluetoothDiscoveryFilter::Merge(result.get(), curr_filter); 370 result = BluetoothDiscoveryFilter::Merge(result.get(), curr_filter);
373 } 371 }
374 372
375 return result; 373 return result;
376 } 374 }
377 375
378 void BluetoothAdapter::RemoveTimedOutDevices() { 376 void BluetoothAdapter::RemoveTimedOutDevices() {
379 for (DevicesMap::iterator it = devices_.begin(); it != devices_.end();) { 377 for (DevicesMap::iterator it = devices_.begin(); it != devices_.end();) {
380 BluetoothDevice* device = it->second; 378 BluetoothDevice* device = it->second.get();
381 if (device->IsPaired() || device->IsConnected() || 379 if (device->IsPaired() || device->IsConnected() ||
382 device->IsGattConnected()) { 380 device->IsGattConnected()) {
383 ++it; 381 ++it;
384 continue; 382 continue;
385 } 383 }
386 384
387 base::Time last_update_time = device->GetLastUpdateTime(); 385 base::Time last_update_time = device->GetLastUpdateTime();
388 386
389 bool device_expired = 387 bool device_expired =
390 (base::Time::NowFromSystemTime() - last_update_time) > timeoutSec; 388 (base::Time::NowFromSystemTime() - last_update_time) > timeoutSec;
391 VLOG(3) << "device: " << device->GetAddress() 389 VLOG(3) << "device: " << device->GetAddress()
392 << ", last_update: " << last_update_time 390 << ", last_update: " << last_update_time
393 << ", exp: " << device_expired; 391 << ", exp: " << device_expired;
394 392
395 if (!device_expired) { 393 if (!device_expired) {
396 ++it; 394 ++it;
397 continue; 395 continue;
398 } 396 }
399 397
400 VLOG(1) << "Removing device: " << device->GetAddress(); 398 VLOG(1) << "Removing device: " << device->GetAddress();
401 DevicesMap::iterator next = it; 399 DevicesMap::iterator next = it;
402 next++; 400 next++;
403 std::unique_ptr<BluetoothDevice> removed_device = 401 std::unique_ptr<BluetoothDevice> removed_device = std::move(it->second);
404 devices_.take_and_erase(it); 402 devices_.erase(it);
405 it = next; 403 it = next;
406 404
407 for (auto& observer : observers_) 405 for (auto& observer : observers_)
408 observer.DeviceRemoved(this, removed_device.get()); 406 observer.DeviceRemoved(this, removed_device.get());
409 } 407 }
410 } 408 }
411 409
412 // static 410 // static
413 void BluetoothAdapter::RecordBluetoothDiscoverySessionStartOutcome( 411 void BluetoothAdapter::RecordBluetoothDiscoverySessionStartOutcome(
414 UMABluetoothDiscoverySessionOutcome outcome) { 412 UMABluetoothDiscoverySessionOutcome outcome) {
415 UMA_HISTOGRAM_ENUMERATION( 413 UMA_HISTOGRAM_ENUMERATION(
416 "Bluetooth.DiscoverySession.Start.Outcome", static_cast<int>(outcome), 414 "Bluetooth.DiscoverySession.Start.Outcome", static_cast<int>(outcome),
417 static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT)); 415 static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT));
418 } 416 }
419 417
420 // static 418 // static
421 void BluetoothAdapter::RecordBluetoothDiscoverySessionStopOutcome( 419 void BluetoothAdapter::RecordBluetoothDiscoverySessionStopOutcome(
422 UMABluetoothDiscoverySessionOutcome outcome) { 420 UMABluetoothDiscoverySessionOutcome outcome) {
423 UMA_HISTOGRAM_ENUMERATION( 421 UMA_HISTOGRAM_ENUMERATION(
424 "Bluetooth.DiscoverySession.Stop.Outcome", static_cast<int>(outcome), 422 "Bluetooth.DiscoverySession.Stop.Outcome", static_cast<int>(outcome),
425 static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT)); 423 static_cast<int>(UMABluetoothDiscoverySessionOutcome::COUNT));
426 } 424 }
427 425
428 // static 426 // static
429 const base::TimeDelta BluetoothAdapter::timeoutSec = 427 const base::TimeDelta BluetoothAdapter::timeoutSec =
430 base::TimeDelta::FromSeconds(180); 428 base::TimeDelta::FromSeconds(180);
431 429
432 } // namespace device 430 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698