OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_discovery_filter.h" | 5 #include "device/bluetooth/bluetooth_discovery_filter.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | |
9 | 8 |
| 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" |
10 #include "device/bluetooth/bluetooth_common.h" | 11 #include "device/bluetooth/bluetooth_common.h" |
11 | 12 |
12 namespace device { | 13 namespace device { |
13 | 14 |
14 BluetoothDiscoveryFilter::BluetoothDiscoveryFilter( | 15 BluetoothDiscoveryFilter::BluetoothDiscoveryFilter( |
15 BluetoothTransport transport) { | 16 BluetoothTransport transport) { |
16 SetTransport(transport); | 17 SetTransport(transport); |
17 } | 18 } |
18 | 19 |
19 BluetoothDiscoveryFilter::~BluetoothDiscoveryFilter() { | 20 BluetoothDiscoveryFilter::~BluetoothDiscoveryFilter() { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 58 |
58 void BluetoothDiscoveryFilter::SetTransport(BluetoothTransport transport) { | 59 void BluetoothDiscoveryFilter::SetTransport(BluetoothTransport transport) { |
59 DCHECK(transport != BLUETOOTH_TRANSPORT_INVALID); | 60 DCHECK(transport != BLUETOOTH_TRANSPORT_INVALID); |
60 transport_ = transport; | 61 transport_ = transport; |
61 } | 62 } |
62 | 63 |
63 void BluetoothDiscoveryFilter::GetUUIDs( | 64 void BluetoothDiscoveryFilter::GetUUIDs( |
64 std::set<device::BluetoothUUID>& out_uuids) const { | 65 std::set<device::BluetoothUUID>& out_uuids) const { |
65 out_uuids.clear(); | 66 out_uuids.clear(); |
66 | 67 |
67 for (auto* uuid : uuids_) | 68 for (const auto& uuid : uuids_) |
68 out_uuids.insert(*uuid); | 69 out_uuids.insert(*uuid); |
69 } | 70 } |
70 | 71 |
71 void BluetoothDiscoveryFilter::AddUUID(const device::BluetoothUUID& uuid) { | 72 void BluetoothDiscoveryFilter::AddUUID(const device::BluetoothUUID& uuid) { |
72 DCHECK(uuid.IsValid()); | 73 DCHECK(uuid.IsValid()); |
73 for (auto* uuid_it : uuids_) { | 74 for (const auto& uuid_it : uuids_) { |
74 if (*uuid_it == uuid) | 75 if (*uuid_it == uuid) |
75 return; | 76 return; |
76 } | 77 } |
77 | 78 |
78 uuids_.push_back(new device::BluetoothUUID(uuid)); | 79 uuids_.push_back(base::MakeUnique<device::BluetoothUUID>(uuid)); |
79 } | 80 } |
80 | 81 |
81 void BluetoothDiscoveryFilter::CopyFrom( | 82 void BluetoothDiscoveryFilter::CopyFrom( |
82 const BluetoothDiscoveryFilter& filter) { | 83 const BluetoothDiscoveryFilter& filter) { |
83 transport_ = filter.transport_; | 84 transport_ = filter.transport_; |
84 | 85 |
85 if (filter.uuids_.size()) { | 86 if (filter.uuids_.size()) { |
86 for (auto* uuid : filter.uuids_) | 87 for (const auto& uuid : filter.uuids_) |
87 AddUUID(*uuid); | 88 AddUUID(*uuid); |
88 } else | 89 } else |
89 uuids_.clear(); | 90 uuids_.clear(); |
90 | 91 |
91 if (filter.rssi_.get()) { | 92 if (filter.rssi_.get()) { |
92 SetRSSI(*filter.rssi_); | 93 SetRSSI(*filter.rssi_); |
93 } else | 94 } else |
94 rssi_.reset(); | 95 rssi_.reset(); |
95 | 96 |
96 if (filter.pathloss_.get()) { | 97 if (filter.pathloss_.get()) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 175 |
175 return true; | 176 return true; |
176 } | 177 } |
177 | 178 |
178 bool BluetoothDiscoveryFilter::IsDefault() const { | 179 bool BluetoothDiscoveryFilter::IsDefault() const { |
179 return !(rssi_.get() || pathloss_.get() || uuids_.size() || | 180 return !(rssi_.get() || pathloss_.get() || uuids_.size() || |
180 transport_ != BLUETOOTH_TRANSPORT_DUAL); | 181 transport_ != BLUETOOTH_TRANSPORT_DUAL); |
181 } | 182 } |
182 | 183 |
183 } // namespace device | 184 } // namespace device |
OLD | NEW |