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

Side by Side Diff: device/bluetooth/bluetooth_device.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_device.h" 5 #include "device/bluetooth/bluetooth_device.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 void BluetoothDevice::DeviceUUIDs::UpdateDeviceUUIDs() { 62 void BluetoothDevice::DeviceUUIDs::UpdateDeviceUUIDs() {
63 device_uuids_.clear(); 63 device_uuids_.clear();
64 std::set_union(advertised_uuids_.begin(), advertised_uuids_.end(), 64 std::set_union(advertised_uuids_.begin(), advertised_uuids_.end(),
65 service_uuids_.begin(), service_uuids_.end(), 65 service_uuids_.begin(), service_uuids_.end(),
66 std::inserter(device_uuids_, device_uuids_.begin())); 66 std::inserter(device_uuids_, device_uuids_.begin()));
67 } 67 }
68 68
69 BluetoothDevice::BluetoothDevice(BluetoothAdapter* adapter) 69 BluetoothDevice::BluetoothDevice(BluetoothAdapter* adapter)
70 : adapter_(adapter), 70 : adapter_(adapter),
71 gatt_services_discovery_complete_(false), 71 gatt_services_discovery_complete_(false),
72 gatt_services_shutting_down_(false),
72 last_update_time_(base::Time()) {} 73 last_update_time_(base::Time()) {}
73 74
74 BluetoothDevice::~BluetoothDevice() { 75 BluetoothDevice::~BluetoothDevice() {
75 for (BluetoothGattConnection* connection : gatt_connections_) { 76 for (BluetoothGattConnection* connection : gatt_connections_) {
76 connection->InvalidateConnectionReference(); 77 connection->InvalidateConnectionReference();
77 } 78 }
79 gatt_services_shutting_down_ = true;
80 gatt_services_.clear();
78 } 81 }
79 82
80 BluetoothDevice::ConnectionInfo::ConnectionInfo() 83 BluetoothDevice::ConnectionInfo::ConnectionInfo()
81 : rssi(kUnknownPower), 84 : rssi(kUnknownPower),
82 transmit_power(kUnknownPower), 85 transmit_power(kUnknownPower),
83 max_transmit_power(kUnknownPower) {} 86 max_transmit_power(kUnknownPower) {}
84 87
85 BluetoothDevice::ConnectionInfo::ConnectionInfo( 88 BluetoothDevice::ConnectionInfo::ConnectionInfo(
86 int rssi, int transmit_power, int max_transmit_power) 89 int rssi, int transmit_power, int max_transmit_power)
87 : rssi(rssi), 90 : rssi(rssi),
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 gatt_services_discovery_complete_ = complete; 366 gatt_services_discovery_complete_ = complete;
364 } 367 }
365 368
366 bool BluetoothDevice::IsGattServicesDiscoveryComplete() const { 369 bool BluetoothDevice::IsGattServicesDiscoveryComplete() const {
367 return gatt_services_discovery_complete_; 370 return gatt_services_discovery_complete_;
368 } 371 }
369 372
370 std::vector<BluetoothRemoteGattService*> BluetoothDevice::GetGattServices() 373 std::vector<BluetoothRemoteGattService*> BluetoothDevice::GetGattServices()
371 const { 374 const {
372 std::vector<BluetoothRemoteGattService*> services; 375 std::vector<BluetoothRemoteGattService*> services;
376 if (gatt_services_shutting_down_)
377 return services;
373 for (const auto& iter : gatt_services_) 378 for (const auto& iter : gatt_services_)
374 services.push_back(iter.second); 379 services.push_back(iter.second.get());
375 return services; 380 return services;
376 } 381 }
377 382
378 BluetoothRemoteGattService* BluetoothDevice::GetGattService( 383 BluetoothRemoteGattService* BluetoothDevice::GetGattService(
379 const std::string& identifier) const { 384 const std::string& identifier) const {
380 return gatt_services_.get(identifier); 385 if (gatt_services_shutting_down_)
386 return nullptr;
387 auto it = gatt_services_.find(identifier);
388 if (it == gatt_services_.end())
389 return nullptr;
390 return it->second.get();
381 } 391 }
382 392
383 // static 393 // static
384 std::string BluetoothDevice::CanonicalizeAddress(const std::string& address) { 394 std::string BluetoothDevice::CanonicalizeAddress(const std::string& address) {
385 std::string canonicalized = address; 395 std::string canonicalized = address;
386 if (address.size() == 12) { 396 if (address.size() == 12) {
387 // Might be an address in the format "1A2B3C4D5E6F". Add separators. 397 // Might be an address in the format "1A2B3C4D5E6F". Add separators.
388 for (size_t i = 2; i < canonicalized.size(); i += 3) { 398 for (size_t i = 2; i < canonicalized.size(); i += 3) {
389 canonicalized.insert(i, ":"); 399 canonicalized.insert(i, ":");
390 } 400 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 if (power < INT8_MIN) { 525 if (power < INT8_MIN) {
516 return INT8_MIN; 526 return INT8_MIN;
517 } 527 }
518 if (power > INT8_MAX) { 528 if (power > INT8_MAX) {
519 return INT8_MAX; 529 return INT8_MAX;
520 } 530 }
521 return static_cast<int8_t>(power); 531 return static_cast<int8_t>(power);
522 } 532 }
523 533
524 } // namespace device 534 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698