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

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

Issue 2506813003: Use new wrapper types for web_bluetooth.mojom (Closed)
Patch Set: merge master and resolve conflicts Created 4 years 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_blocklist.h" 5 #include "content/browser/bluetooth/bluetooth_blocklist.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/optional.h" 9 #include "base/optional.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 bool BluetoothBlocklist::IsExcluded(const BluetoothUUID& uuid) const { 80 bool BluetoothBlocklist::IsExcluded(const BluetoothUUID& uuid) const {
81 CHECK(uuid.IsValid()); 81 CHECK(uuid.IsValid());
82 const auto& it = blocklisted_uuids_.find(uuid); 82 const auto& it = blocklisted_uuids_.find(uuid);
83 if (it == blocklisted_uuids_.end()) 83 if (it == blocklisted_uuids_.end())
84 return false; 84 return false;
85 return it->second == Value::EXCLUDE; 85 return it->second == Value::EXCLUDE;
86 } 86 }
87 87
88 bool BluetoothBlocklist::IsExcluded( 88 bool BluetoothBlocklist::IsExcluded(
89 const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) { 89 const std::vector<blink::mojom::WebBluetoothScanFilterPtr>& filters) {
90 for (const blink::mojom::WebBluetoothScanFilterPtr& filter : filters) { 90 for (const blink::mojom::WebBluetoothScanFilterPtr& filter : filters) {
91 for (const base::Optional<BluetoothUUID>& service : filter->services) { 91 if (!filter->services) {
92 if (IsExcluded(service.value())) { 92 continue;
93 }
94 for (const BluetoothUUID& service : filter->services.value()) {
95 if (IsExcluded(service)) {
93 return true; 96 return true;
94 } 97 }
95 } 98 }
96 } 99 }
97 return false; 100 return false;
98 } 101 }
99 102
100 bool BluetoothBlocklist::IsExcludedFromReads(const BluetoothUUID& uuid) const { 103 bool BluetoothBlocklist::IsExcludedFromReads(const BluetoothUUID& uuid) const {
101 CHECK(uuid.IsValid()); 104 CHECK(uuid.IsValid());
102 const auto& it = blocklisted_uuids_.find(uuid); 105 const auto& it = blocklisted_uuids_.find(uuid);
103 if (it == blocklisted_uuids_.end()) 106 if (it == blocklisted_uuids_.end())
104 return false; 107 return false;
105 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_READS; 108 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_READS;
106 } 109 }
107 110
108 bool BluetoothBlocklist::IsExcludedFromWrites(const BluetoothUUID& uuid) const { 111 bool BluetoothBlocklist::IsExcludedFromWrites(const BluetoothUUID& uuid) const {
109 CHECK(uuid.IsValid()); 112 CHECK(uuid.IsValid());
110 const auto& it = blocklisted_uuids_.find(uuid); 113 const auto& it = blocklisted_uuids_.find(uuid);
111 if (it == blocklisted_uuids_.end()) 114 if (it == blocklisted_uuids_.end())
112 return false; 115 return false;
113 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_WRITES; 116 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_WRITES;
114 } 117 }
115 118
116 void BluetoothBlocklist::RemoveExcludedUUIDs( 119 void BluetoothBlocklist::RemoveExcludedUUIDs(
117 blink::mojom::WebBluetoothRequestDeviceOptions* options) { 120 blink::mojom::WebBluetoothRequestDeviceOptions* options) {
118 mojo::Array<base::Optional<BluetoothUUID>> 121 std::vector<device::BluetoothUUID> optional_services_blocklist_filtered;
119 optional_services_blocklist_filtered; 122 for (const BluetoothUUID& uuid : options->optional_services) {
120 for (const base::Optional<BluetoothUUID>& uuid : options->optional_services) { 123 if (!IsExcluded(uuid)) {
121 if (!IsExcluded(uuid.value())) {
122 optional_services_blocklist_filtered.push_back(uuid); 124 optional_services_blocklist_filtered.push_back(uuid);
123 } 125 }
124 } 126 }
125 options->optional_services = std::move(optional_services_blocklist_filtered); 127 options->optional_services = std::move(optional_services_blocklist_filtered);
126 } 128 }
127 129
128 void BluetoothBlocklist::ResetToDefaultValuesForTest() { 130 void BluetoothBlocklist::ResetToDefaultValuesForTest() {
129 blocklisted_uuids_.clear(); 131 blocklisted_uuids_.clear();
130 PopulateWithDefaultValues(); 132 PopulateWithDefaultValues();
131 PopulateWithServerProvidedValues(); 133 PopulateWithServerProvidedValues();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 Value::EXCLUDE_READS); 182 Value::EXCLUDE_READS);
181 } 183 }
182 184
183 void BluetoothBlocklist::PopulateWithServerProvidedValues() { 185 void BluetoothBlocklist::PopulateWithServerProvidedValues() {
184 // DCHECK to maybe help debug https://crbug.com/604078. 186 // DCHECK to maybe help debug https://crbug.com/604078.
185 DCHECK(GetContentClient()); 187 DCHECK(GetContentClient());
186 Add(GetContentClient()->browser()->GetWebBluetoothBlocklist()); 188 Add(GetContentClient()->browser()->GetWebBluetoothBlocklist());
187 } 189 }
188 190
189 } // namespace content 191 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698