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

Side by Side Diff: content/browser/bluetooth/bluetooth_device_chooser_controller.cc

Issue 2789243002: Rename BluetoothScanFilterInit to BluetoothLEScanFilterInit (Closed)
Patch Set: Codereview: nit Created 3 years, 8 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/browser/bluetooth/bluetooth_device_chooser_controller.h" 5 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <unordered_set> 9 #include <unordered_set>
10 10
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 DVLOG(1) << "Services: "; 108 DVLOG(1) << "Services: ";
109 DVLOG(1) << "\t["; 109 DVLOG(1) << "\t[";
110 for (const auto& service : filter->services.value()) 110 for (const auto& service : filter->services.value())
111 DVLOG(1) << "\t\t" << service.canonical_value(); 111 DVLOG(1) << "\t\t" << service.canonical_value();
112 DVLOG(1) << "\t]"; 112 DVLOG(1) << "\t]";
113 } 113 }
114 } 114 }
115 } 115 }
116 116
117 bool IsEmptyOrInvalidFilter( 117 bool IsEmptyOrInvalidFilter(
118 const blink::mojom::WebBluetoothScanFilterPtr& filter) { 118 const blink::mojom::WebBluetoothLeScanFilterPtr& filter) {
119 // At least one member needs to be present. 119 // At least one member needs to be present.
120 if (!filter->name && !filter->name_prefix && !filter->services) 120 if (!filter->name && !filter->name_prefix && !filter->services)
121 return true; 121 return true;
122 122
123 // The renderer will never send a name or a name_prefix longer than 123 // The renderer will never send a name or a name_prefix longer than
124 // kMaxLengthForDeviceName. 124 // kMaxLengthForDeviceName.
125 if (filter->name && filter->name->size() > kMaxLengthForDeviceName) 125 if (filter->name && filter->name->size() > kMaxLengthForDeviceName)
126 return true; 126 return true;
127 if (filter->name_prefix && filter->name_prefix->size() == 0) 127 if (filter->name_prefix && filter->name_prefix->size() == 0)
128 return true; 128 return true;
129 if (filter->name_prefix && 129 if (filter->name_prefix &&
130 filter->name_prefix->size() > kMaxLengthForDeviceName) 130 filter->name_prefix->size() > kMaxLengthForDeviceName)
131 return true; 131 return true;
132 132
133 return false; 133 return false;
134 } 134 }
135 135
136 bool HasEmptyOrInvalidFilter( 136 bool HasEmptyOrInvalidFilter(
137 const base::Optional<std::vector<blink::mojom::WebBluetoothScanFilterPtr>>& 137 const base::Optional<
138 filters) { 138 std::vector<blink::mojom::WebBluetoothLeScanFilterPtr>>& filters) {
139 if (!filters) { 139 if (!filters) {
140 return true; 140 return true;
141 } 141 }
142 142
143 return filters->empty() 143 return filters->empty()
144 ? true 144 ? true
145 : filters->end() != std::find_if(filters->begin(), filters->end(), 145 : filters->end() != std::find_if(filters->begin(), filters->end(),
146 IsEmptyOrInvalidFilter); 146 IsEmptyOrInvalidFilter);
147 } 147 }
148 148
149 bool IsOptionsInvalid( 149 bool IsOptionsInvalid(
150 const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options) { 150 const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options) {
151 if (options->accept_all_devices) { 151 if (options->accept_all_devices) {
152 return options->filters.has_value(); 152 return options->filters.has_value();
153 } else { 153 } else {
154 return HasEmptyOrInvalidFilter(options->filters); 154 return HasEmptyOrInvalidFilter(options->filters);
155 } 155 }
156 } 156 }
157 157
158 bool MatchesFilter(const std::string* device_name, 158 bool MatchesFilter(const std::string* device_name,
159 const UUIDSet& device_uuids, 159 const UUIDSet& device_uuids,
160 const blink::mojom::WebBluetoothScanFilterPtr& filter) { 160 const blink::mojom::WebBluetoothLeScanFilterPtr& filter) {
161 if (filter->name) { 161 if (filter->name) {
162 if (device_name == nullptr) 162 if (device_name == nullptr)
163 return false; 163 return false;
164 if (filter->name.value() != *device_name) 164 if (filter->name.value() != *device_name)
165 return false; 165 return false;
166 } 166 }
167 167
168 if (filter->name_prefix && filter->name_prefix->size()) { 168 if (filter->name_prefix && filter->name_prefix->size()) {
169 if (device_name == nullptr) 169 if (device_name == nullptr)
170 return false; 170 return false;
171 if (!base::StartsWith(*device_name, filter->name_prefix.value(), 171 if (!base::StartsWith(*device_name, filter->name_prefix.value(),
172 base::CompareCase::SENSITIVE)) 172 base::CompareCase::SENSITIVE))
173 return false; 173 return false;
174 } 174 }
175 175
176 if (filter->services) { 176 if (filter->services) {
177 for (const auto& service : filter->services.value()) { 177 for (const auto& service : filter->services.value()) {
178 if (!base::ContainsKey(device_uuids, service)) { 178 if (!base::ContainsKey(device_uuids, service)) {
179 return false; 179 return false;
180 } 180 }
181 } 181 }
182 } 182 }
183 183
184 return true; 184 return true;
185 } 185 }
186 186
187 bool MatchesFilters( 187 bool MatchesFilters(
188 const std::string* device_name, 188 const std::string* device_name,
189 const UUIDSet& device_uuids, 189 const UUIDSet& device_uuids,
190 const base::Optional<std::vector<blink::mojom::WebBluetoothScanFilterPtr>>& 190 const base::Optional<
191 filters) { 191 std::vector<blink::mojom::WebBluetoothLeScanFilterPtr>>& filters) {
192 DCHECK(!HasEmptyOrInvalidFilter(filters)); 192 DCHECK(!HasEmptyOrInvalidFilter(filters));
193 for (const auto& filter : filters.value()) { 193 for (const auto& filter : filters.value()) {
194 if (MatchesFilter(device_name, device_uuids, filter)) { 194 if (MatchesFilter(device_name, device_uuids, filter)) {
195 return true; 195 return true;
196 } 196 }
197 } 197 }
198 return false; 198 return false;
199 } 199 }
200 200
201 std::unique_ptr<device::BluetoothDiscoveryFilter> ComputeScanFilter( 201 std::unique_ptr<device::BluetoothDiscoveryFilter> ComputeScanFilter(
202 const base::Optional<std::vector<blink::mojom::WebBluetoothScanFilterPtr>>& 202 const base::Optional<
203 filters) { 203 std::vector<blink::mojom::WebBluetoothLeScanFilterPtr>>& filters) {
204 std::unordered_set<BluetoothUUID, device::BluetoothUUIDHash> services; 204 std::unordered_set<BluetoothUUID, device::BluetoothUUIDHash> services;
205 205
206 if (filters) { 206 if (filters) {
207 for (const auto& filter : filters.value()) { 207 for (const auto& filter : filters.value()) {
208 if (!filter->services) { 208 if (!filter->services) {
209 continue; 209 continue;
210 } 210 }
211 for (const auto& service : filter->services.value()) { 211 for (const auto& service : filter->services.value()) {
212 services.insert(service); 212 services.insert(service);
213 } 213 }
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 617
618 void BluetoothDeviceChooserController::PostErrorCallback( 618 void BluetoothDeviceChooserController::PostErrorCallback(
619 blink::mojom::WebBluetoothResult error) { 619 blink::mojom::WebBluetoothResult error) {
620 if (!base::ThreadTaskRunnerHandle::Get()->PostTask( 620 if (!base::ThreadTaskRunnerHandle::Get()->PostTask(
621 FROM_HERE, base::Bind(error_callback_, error))) { 621 FROM_HERE, base::Bind(error_callback_, error))) {
622 LOG(WARNING) << "No TaskRunner."; 622 LOG(WARNING) << "No TaskRunner.";
623 } 623 }
624 } 624 }
625 625
626 } // namespace content 626 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/bluetooth/bluetooth_blocklist_unittest.cc ('k') | content/browser/bluetooth/bluetooth_metrics.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698