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

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

Issue 1922923002: bluetooth: Move requestDevice to mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-separate-tests-request-device
Patch Set: Remove debug log Created 4 years, 7 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_blacklist.h" 5 #include "content/browser/bluetooth/bluetooth_blacklist.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/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "content/common/bluetooth/bluetooth_scan_filter.h"
11 #include "content/public/browser/content_browser_client.h" 10 #include "content/public/browser/content_browser_client.h"
12 11
13 using device::BluetoothUUID; 12 using device::BluetoothUUID;
14 13
15 namespace { 14 namespace {
16 15
17 static base::LazyInstance<content::BluetoothBlacklist>::Leaky g_singleton = 16 static base::LazyInstance<content::BluetoothBlacklist>::Leaky g_singleton =
18 LAZY_INSTANCE_INITIALIZER; 17 LAZY_INSTANCE_INITIALIZER;
19 18
20 void RecordUMAParsedNonEmptyString(bool success) { 19 void RecordUMAParsedNonEmptyString(bool success) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 78
80 bool BluetoothBlacklist::IsExcluded(const BluetoothUUID& uuid) const { 79 bool BluetoothBlacklist::IsExcluded(const BluetoothUUID& uuid) const {
81 CHECK(uuid.IsValid()); 80 CHECK(uuid.IsValid());
82 const auto& it = blacklisted_uuids_.find(uuid); 81 const auto& it = blacklisted_uuids_.find(uuid);
83 if (it == blacklisted_uuids_.end()) 82 if (it == blacklisted_uuids_.end())
84 return false; 83 return false;
85 return it->second == Value::EXCLUDE; 84 return it->second == Value::EXCLUDE;
86 } 85 }
87 86
88 bool BluetoothBlacklist::IsExcluded( 87 bool BluetoothBlacklist::IsExcluded(
89 const std::vector<content::BluetoothScanFilter>& filters) { 88 const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) {
90 for (const BluetoothScanFilter& filter : filters) { 89 for (const blink::mojom::WebBluetoothScanFilterPtr& filter : filters) {
91 for (const BluetoothUUID& service : filter.services) { 90 for (const std::string& service : filter->services) {
92 if (IsExcluded(service)) { 91 if (IsExcluded(BluetoothUUID(service))) {
93 return true; 92 return true;
94 } 93 }
95 } 94 }
96 } 95 }
97 return false; 96 return false;
98 } 97 }
99 98
100 bool BluetoothBlacklist::IsExcludedFromReads(const BluetoothUUID& uuid) const { 99 bool BluetoothBlacklist::IsExcludedFromReads(const BluetoothUUID& uuid) const {
101 CHECK(uuid.IsValid()); 100 CHECK(uuid.IsValid());
102 const auto& it = blacklisted_uuids_.find(uuid); 101 const auto& it = blacklisted_uuids_.find(uuid);
103 if (it == blacklisted_uuids_.end()) 102 if (it == blacklisted_uuids_.end())
104 return false; 103 return false;
105 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_READS; 104 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_READS;
106 } 105 }
107 106
108 bool BluetoothBlacklist::IsExcludedFromWrites(const BluetoothUUID& uuid) const { 107 bool BluetoothBlacklist::IsExcludedFromWrites(const BluetoothUUID& uuid) const {
109 CHECK(uuid.IsValid()); 108 CHECK(uuid.IsValid());
110 const auto& it = blacklisted_uuids_.find(uuid); 109 const auto& it = blacklisted_uuids_.find(uuid);
111 if (it == blacklisted_uuids_.end()) 110 if (it == blacklisted_uuids_.end())
112 return false; 111 return false;
113 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_WRITES; 112 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_WRITES;
114 } 113 }
115 114
116 void BluetoothBlacklist::RemoveExcludedUuids( 115 void BluetoothBlacklist::RemoveExcludedUUIDs(
117 std::vector<device::BluetoothUUID>* uuids) { 116 blink::mojom::WebBluetoothRequestDeviceOptions* options) {
118 auto it = uuids->begin(); 117 mojo::Array<mojo::String> optional_services_blacklist_filtered;
119 while (it != uuids->end()) { 118 for (const std::string& uuid : options->optional_services) {
120 if (IsExcluded(*it)) { 119 if (!IsExcluded(BluetoothUUID(uuid))) {
121 it = uuids->erase(it); 120 optional_services_blacklist_filtered.push_back(uuid);
122 } else {
123 it++;
124 } 121 }
125 } 122 }
123 options->optional_services = std::move(optional_services_blacklist_filtered);
126 } 124 }
127 125
128 void BluetoothBlacklist::ResetToDefaultValuesForTest() { 126 void BluetoothBlacklist::ResetToDefaultValuesForTest() {
129 blacklisted_uuids_.clear(); 127 blacklisted_uuids_.clear();
130 PopulateWithDefaultValues(); 128 PopulateWithDefaultValues();
131 PopulateWithServerProvidedValues(); 129 PopulateWithServerProvidedValues();
132 } 130 }
133 131
134 BluetoothBlacklist::BluetoothBlacklist() { 132 BluetoothBlacklist::BluetoothBlacklist() {
135 PopulateWithDefaultValues(); 133 PopulateWithDefaultValues();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 Value::EXCLUDE_READS); 176 Value::EXCLUDE_READS);
179 } 177 }
180 178
181 void BluetoothBlacklist::PopulateWithServerProvidedValues() { 179 void BluetoothBlacklist::PopulateWithServerProvidedValues() {
182 // DCHECK to maybe help debug https://crbug.com/604078. 180 // DCHECK to maybe help debug https://crbug.com/604078.
183 DCHECK(GetContentClient()); 181 DCHECK(GetContentClient());
184 Add(GetContentClient()->browser()->GetWebBluetoothBlacklist()); 182 Add(GetContentClient()->browser()->GetWebBluetoothBlacklist());
185 } 183 }
186 184
187 } // namespace content 185 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698