| OLD | NEW |
| 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/public/browser/content_browser_client.h" | 10 #include "content/public/browser/content_browser_client.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 namespace content { | 26 namespace content { |
| 27 | 27 |
| 28 BluetoothBlacklist::~BluetoothBlacklist() {} | 28 BluetoothBlacklist::~BluetoothBlacklist() {} |
| 29 | 29 |
| 30 // static | 30 // static |
| 31 BluetoothBlacklist& BluetoothBlacklist::Get() { | 31 BluetoothBlacklist& BluetoothBlacklist::Get() { |
| 32 return g_singleton.Get(); | 32 return g_singleton.Get(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void BluetoothBlacklist::Add(const device::BluetoothUUID& uuid, Value value) { | 35 void BluetoothBlacklist::Add(const BluetoothUUID& uuid, Value value) { |
| 36 CHECK(uuid.IsValid()); | 36 CHECK(uuid.IsValid()); |
| 37 auto insert_result = blacklisted_uuids_.insert(std::make_pair(uuid, value)); | 37 auto insert_result = blacklisted_uuids_.insert(std::make_pair(uuid, value)); |
| 38 bool inserted = insert_result.second; | 38 bool inserted = insert_result.second; |
| 39 if (!inserted) { | 39 if (!inserted) { |
| 40 Value& stored = insert_result.first->second; | 40 Value& stored = insert_result.first->second; |
| 41 if (stored != value) | 41 if (stored != value) |
| 42 stored = Value::EXCLUDE; | 42 stored = Value::EXCLUDE; |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 | 45 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 CHECK(uuid.IsValid()); | 80 CHECK(uuid.IsValid()); |
| 81 const auto& it = blacklisted_uuids_.find(uuid); | 81 const auto& it = blacklisted_uuids_.find(uuid); |
| 82 if (it == blacklisted_uuids_.end()) | 82 if (it == blacklisted_uuids_.end()) |
| 83 return false; | 83 return false; |
| 84 return it->second == Value::EXCLUDE; | 84 return it->second == Value::EXCLUDE; |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool BluetoothBlacklist::IsExcluded( | 87 bool BluetoothBlacklist::IsExcluded( |
| 88 const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) { | 88 const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) { |
| 89 for (const blink::mojom::WebBluetoothScanFilterPtr& filter : filters) { | 89 for (const blink::mojom::WebBluetoothScanFilterPtr& filter : filters) { |
| 90 for (const std::string& service : filter->services) { | 90 for (const std::unique_ptr<BluetoothUUID>& service : filter->services) { |
| 91 if (IsExcluded(BluetoothUUID(service))) { | 91 if (IsExcluded(*service)) { |
| 92 return true; | 92 return true; |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 return false; | 96 return false; |
| 97 } | 97 } |
| 98 | 98 |
| 99 bool BluetoothBlacklist::IsExcludedFromReads(const BluetoothUUID& uuid) const { | 99 bool BluetoothBlacklist::IsExcludedFromReads(const BluetoothUUID& uuid) const { |
| 100 CHECK(uuid.IsValid()); | 100 CHECK(uuid.IsValid()); |
| 101 const auto& it = blacklisted_uuids_.find(uuid); | 101 const auto& it = blacklisted_uuids_.find(uuid); |
| 102 if (it == blacklisted_uuids_.end()) | 102 if (it == blacklisted_uuids_.end()) |
| 103 return false; | 103 return false; |
| 104 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_READS; | 104 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_READS; |
| 105 } | 105 } |
| 106 | 106 |
| 107 bool BluetoothBlacklist::IsExcludedFromWrites(const BluetoothUUID& uuid) const { | 107 bool BluetoothBlacklist::IsExcludedFromWrites(const BluetoothUUID& uuid) const { |
| 108 CHECK(uuid.IsValid()); | 108 CHECK(uuid.IsValid()); |
| 109 const auto& it = blacklisted_uuids_.find(uuid); | 109 const auto& it = blacklisted_uuids_.find(uuid); |
| 110 if (it == blacklisted_uuids_.end()) | 110 if (it == blacklisted_uuids_.end()) |
| 111 return false; | 111 return false; |
| 112 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_WRITES; | 112 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_WRITES; |
| 113 } | 113 } |
| 114 | 114 |
| 115 void BluetoothBlacklist::RemoveExcludedUUIDs( | 115 void BluetoothBlacklist::RemoveExcludedUUIDs( |
| 116 blink::mojom::WebBluetoothRequestDeviceOptions* options) { | 116 blink::mojom::WebBluetoothRequestDeviceOptions* options) { |
| 117 mojo::Array<mojo::String> optional_services_blacklist_filtered; | 117 mojo::Array<std::unique_ptr<BluetoothUUID>> |
| 118 for (const std::string& uuid : options->optional_services) { | 118 optional_services_blacklist_filtered; |
| 119 if (!IsExcluded(BluetoothUUID(uuid))) { | 119 for (const std::unique_ptr<BluetoothUUID>& uuid : |
| 120 optional_services_blacklist_filtered.push_back(uuid); | 120 options->optional_services) { |
| 121 if (!IsExcluded(*uuid)) { |
| 122 optional_services_blacklist_filtered.push_back( |
| 123 base::WrapUnique(new BluetoothUUID(*uuid))); |
| 121 } | 124 } |
| 122 } | 125 } |
| 123 options->optional_services = std::move(optional_services_blacklist_filtered); | 126 options->optional_services = std::move(optional_services_blacklist_filtered); |
| 124 } | 127 } |
| 125 | 128 |
| 126 void BluetoothBlacklist::ResetToDefaultValuesForTest() { | 129 void BluetoothBlacklist::ResetToDefaultValuesForTest() { |
| 127 blacklisted_uuids_.clear(); | 130 blacklisted_uuids_.clear(); |
| 128 PopulateWithDefaultValues(); | 131 PopulateWithDefaultValues(); |
| 129 PopulateWithServerProvidedValues(); | 132 PopulateWithServerProvidedValues(); |
| 130 } | 133 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 Value::EXCLUDE_READS); | 179 Value::EXCLUDE_READS); |
| 177 } | 180 } |
| 178 | 181 |
| 179 void BluetoothBlacklist::PopulateWithServerProvidedValues() { | 182 void BluetoothBlacklist::PopulateWithServerProvidedValues() { |
| 180 // DCHECK to maybe help debug https://crbug.com/604078. | 183 // DCHECK to maybe help debug https://crbug.com/604078. |
| 181 DCHECK(GetContentClient()); | 184 DCHECK(GetContentClient()); |
| 182 Add(GetContentClient()->browser()->GetWebBluetoothBlacklist()); | 185 Add(GetContentClient()->browser()->GetWebBluetoothBlacklist()); |
| 183 } | 186 } |
| 184 | 187 |
| 185 } // namespace content | 188 } // namespace content |
| OLD | NEW |