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

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

Issue 2015463004: bluetooth: Use BluetoothUUID instead of string when sending uuids (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-mojo-request-device
Patch Set: Fix merge conflict Created 4 years, 6 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/optional.h"
9 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
10 #include "content/public/browser/content_browser_client.h" 11 #include "content/public/browser/content_browser_client.h"
11 12
12 using device::BluetoothUUID; 13 using device::BluetoothUUID;
13 14
14 namespace { 15 namespace {
15 16
16 static base::LazyInstance<content::BluetoothBlacklist>::Leaky g_singleton = 17 static base::LazyInstance<content::BluetoothBlacklist>::Leaky g_singleton =
17 LAZY_INSTANCE_INITIALIZER; 18 LAZY_INSTANCE_INITIALIZER;
18 19
19 void RecordUMAParsedNonEmptyString(bool success) { 20 void RecordUMAParsedNonEmptyString(bool success) {
20 UMA_HISTOGRAM_BOOLEAN("Bluetooth.Web.Blacklist.ParsedNonEmptyString", 21 UMA_HISTOGRAM_BOOLEAN("Bluetooth.Web.Blacklist.ParsedNonEmptyString",
21 success); 22 success);
22 } 23 }
23 24
24 } // namespace 25 } // namespace
25 26
26 namespace content { 27 namespace content {
27 28
28 BluetoothBlacklist::~BluetoothBlacklist() {} 29 BluetoothBlacklist::~BluetoothBlacklist() {}
29 30
30 // static 31 // static
31 BluetoothBlacklist& BluetoothBlacklist::Get() { 32 BluetoothBlacklist& BluetoothBlacklist::Get() {
32 return g_singleton.Get(); 33 return g_singleton.Get();
33 } 34 }
34 35
35 void BluetoothBlacklist::Add(const device::BluetoothUUID& uuid, Value value) { 36 void BluetoothBlacklist::Add(const BluetoothUUID& uuid, Value value) {
36 CHECK(uuid.IsValid()); 37 CHECK(uuid.IsValid());
37 auto insert_result = blacklisted_uuids_.insert(std::make_pair(uuid, value)); 38 auto insert_result = blacklisted_uuids_.insert(std::make_pair(uuid, value));
38 bool inserted = insert_result.second; 39 bool inserted = insert_result.second;
39 if (!inserted) { 40 if (!inserted) {
40 Value& stored = insert_result.first->second; 41 Value& stored = insert_result.first->second;
41 if (stored != value) 42 if (stored != value)
42 stored = Value::EXCLUDE; 43 stored = Value::EXCLUDE;
43 } 44 }
44 } 45 }
45 46
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 CHECK(uuid.IsValid()); 81 CHECK(uuid.IsValid());
81 const auto& it = blacklisted_uuids_.find(uuid); 82 const auto& it = blacklisted_uuids_.find(uuid);
82 if (it == blacklisted_uuids_.end()) 83 if (it == blacklisted_uuids_.end())
83 return false; 84 return false;
84 return it->second == Value::EXCLUDE; 85 return it->second == Value::EXCLUDE;
85 } 86 }
86 87
87 bool BluetoothBlacklist::IsExcluded( 88 bool BluetoothBlacklist::IsExcluded(
88 const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) { 89 const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) {
89 for (const blink::mojom::WebBluetoothScanFilterPtr& filter : filters) { 90 for (const blink::mojom::WebBluetoothScanFilterPtr& filter : filters) {
90 for (const std::string& service : filter->services) { 91 for (const base::Optional<BluetoothUUID>& service : filter->services) {
91 if (IsExcluded(BluetoothUUID(service))) { 92 if (IsExcluded(service.value())) {
92 return true; 93 return true;
93 } 94 }
94 } 95 }
95 } 96 }
96 return false; 97 return false;
97 } 98 }
98 99
99 bool BluetoothBlacklist::IsExcludedFromReads(const BluetoothUUID& uuid) const { 100 bool BluetoothBlacklist::IsExcludedFromReads(const BluetoothUUID& uuid) const {
100 CHECK(uuid.IsValid()); 101 CHECK(uuid.IsValid());
101 const auto& it = blacklisted_uuids_.find(uuid); 102 const auto& it = blacklisted_uuids_.find(uuid);
102 if (it == blacklisted_uuids_.end()) 103 if (it == blacklisted_uuids_.end())
103 return false; 104 return false;
104 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_READS; 105 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_READS;
105 } 106 }
106 107
107 bool BluetoothBlacklist::IsExcludedFromWrites(const BluetoothUUID& uuid) const { 108 bool BluetoothBlacklist::IsExcludedFromWrites(const BluetoothUUID& uuid) const {
108 CHECK(uuid.IsValid()); 109 CHECK(uuid.IsValid());
109 const auto& it = blacklisted_uuids_.find(uuid); 110 const auto& it = blacklisted_uuids_.find(uuid);
110 if (it == blacklisted_uuids_.end()) 111 if (it == blacklisted_uuids_.end())
111 return false; 112 return false;
112 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_WRITES; 113 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_WRITES;
113 } 114 }
114 115
115 void BluetoothBlacklist::RemoveExcludedUUIDs( 116 void BluetoothBlacklist::RemoveExcludedUUIDs(
116 blink::mojom::WebBluetoothRequestDeviceOptions* options) { 117 blink::mojom::WebBluetoothRequestDeviceOptions* options) {
117 mojo::Array<mojo::String> optional_services_blacklist_filtered; 118 mojo::Array<base::Optional<BluetoothUUID>>
118 for (const std::string& uuid : options->optional_services) { 119 optional_services_blacklist_filtered;
119 if (!IsExcluded(BluetoothUUID(uuid))) { 120 for (const base::Optional<BluetoothUUID>& uuid : options->optional_services) {
121 if (!IsExcluded(uuid.value())) {
120 optional_services_blacklist_filtered.push_back(uuid); 122 optional_services_blacklist_filtered.push_back(uuid);
121 } 123 }
122 } 124 }
123 options->optional_services = std::move(optional_services_blacklist_filtered); 125 options->optional_services = std::move(optional_services_blacklist_filtered);
124 } 126 }
125 127
126 void BluetoothBlacklist::ResetToDefaultValuesForTest() { 128 void BluetoothBlacklist::ResetToDefaultValuesForTest() {
127 blacklisted_uuids_.clear(); 129 blacklisted_uuids_.clear();
128 PopulateWithDefaultValues(); 130 PopulateWithDefaultValues();
129 PopulateWithServerProvidedValues(); 131 PopulateWithServerProvidedValues();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 Value::EXCLUDE_READS); 178 Value::EXCLUDE_READS);
177 } 179 }
178 180
179 void BluetoothBlacklist::PopulateWithServerProvidedValues() { 181 void BluetoothBlacklist::PopulateWithServerProvidedValues() {
180 // DCHECK to maybe help debug https://crbug.com/604078. 182 // DCHECK to maybe help debug https://crbug.com/604078.
181 DCHECK(GetContentClient()); 183 DCHECK(GetContentClient());
182 Add(GetContentClient()->browser()->GetWebBluetoothBlacklist()); 184 Add(GetContentClient()->browser()->GetWebBluetoothBlacklist());
183 } 185 }
184 186
185 } // namespace content 187 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698