Chromium Code Reviews| 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/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 Loading... | |
| 79 | 79 |
| 80 bool BluetoothBlacklist::IsExcluded(const BluetoothUUID& uuid) const { | 80 bool BluetoothBlacklist::IsExcluded(const BluetoothUUID& uuid) const { |
| 81 CHECK(uuid.IsValid()); | 81 CHECK(uuid.IsValid()); |
| 82 const auto& it = blacklisted_uuids_.find(uuid); | 82 const auto& it = blacklisted_uuids_.find(uuid); |
| 83 if (it == blacklisted_uuids_.end()) | 83 if (it == blacklisted_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 BluetoothBlacklist::IsExcluded( | 88 bool BluetoothBlacklist::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 for (const BluetoothUUID& service : filter->services.value()) { | |
| 94 if (IsExcluded(service)) | |
|
ortuno
2016/11/22 02:32:20
nit: In general, I would just keep the style (in t
juncai
2016/11/23 20:54:22
Done.
| |
| 93 return true; | 95 return true; |
| 94 } | |
| 95 } | 96 } |
| 96 } | 97 } |
| 97 return false; | 98 return false; |
| 98 } | 99 } |
| 99 | 100 |
| 100 bool BluetoothBlacklist::IsExcludedFromReads(const BluetoothUUID& uuid) const { | 101 bool BluetoothBlacklist::IsExcludedFromReads(const BluetoothUUID& uuid) const { |
| 101 CHECK(uuid.IsValid()); | 102 CHECK(uuid.IsValid()); |
| 102 const auto& it = blacklisted_uuids_.find(uuid); | 103 const auto& it = blacklisted_uuids_.find(uuid); |
| 103 if (it == blacklisted_uuids_.end()) | 104 if (it == blacklisted_uuids_.end()) |
| 104 return false; | 105 return false; |
| 105 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_READS; | 106 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_READS; |
| 106 } | 107 } |
| 107 | 108 |
| 108 bool BluetoothBlacklist::IsExcludedFromWrites(const BluetoothUUID& uuid) const { | 109 bool BluetoothBlacklist::IsExcludedFromWrites(const BluetoothUUID& uuid) const { |
| 109 CHECK(uuid.IsValid()); | 110 CHECK(uuid.IsValid()); |
| 110 const auto& it = blacklisted_uuids_.find(uuid); | 111 const auto& it = blacklisted_uuids_.find(uuid); |
| 111 if (it == blacklisted_uuids_.end()) | 112 if (it == blacklisted_uuids_.end()) |
| 112 return false; | 113 return false; |
| 113 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_WRITES; | 114 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_WRITES; |
| 114 } | 115 } |
| 115 | 116 |
| 116 void BluetoothBlacklist::RemoveExcludedUUIDs( | 117 void BluetoothBlacklist::RemoveExcludedUUIDs( |
| 117 blink::mojom::WebBluetoothRequestDeviceOptions* options) { | 118 blink::mojom::WebBluetoothRequestDeviceOptions* options) { |
| 118 mojo::Array<base::Optional<BluetoothUUID>> | 119 std::vector<device::BluetoothUUID> optional_services_blacklist_filtered; |
| 119 optional_services_blacklist_filtered; | 120 for (const BluetoothUUID& uuid : options->optional_services) { |
| 120 for (const base::Optional<BluetoothUUID>& uuid : options->optional_services) { | 121 if (!IsExcluded(uuid)) |
| 121 if (!IsExcluded(uuid.value())) { | |
| 122 optional_services_blacklist_filtered.push_back(uuid); | 122 optional_services_blacklist_filtered.push_back(uuid); |
| 123 } | |
| 124 } | 123 } |
| 125 options->optional_services = std::move(optional_services_blacklist_filtered); | 124 options->optional_services = std::move(optional_services_blacklist_filtered); |
| 126 } | 125 } |
| 127 | 126 |
| 128 void BluetoothBlacklist::ResetToDefaultValuesForTest() { | 127 void BluetoothBlacklist::ResetToDefaultValuesForTest() { |
| 129 blacklisted_uuids_.clear(); | 128 blacklisted_uuids_.clear(); |
| 130 PopulateWithDefaultValues(); | 129 PopulateWithDefaultValues(); |
| 131 PopulateWithServerProvidedValues(); | 130 PopulateWithServerProvidedValues(); |
| 132 } | 131 } |
| 133 | 132 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 Value::EXCLUDE_READS); | 179 Value::EXCLUDE_READS); |
| 181 } | 180 } |
| 182 | 181 |
| 183 void BluetoothBlacklist::PopulateWithServerProvidedValues() { | 182 void BluetoothBlacklist::PopulateWithServerProvidedValues() { |
| 184 // DCHECK to maybe help debug https://crbug.com/604078. | 183 // DCHECK to maybe help debug https://crbug.com/604078. |
| 185 DCHECK(GetContentClient()); | 184 DCHECK(GetContentClient()); |
| 186 Add(GetContentClient()->browser()->GetWebBluetoothBlacklist()); | 185 Add(GetContentClient()->browser()->GetWebBluetoothBlacklist()); |
| 187 } | 186 } |
| 188 | 187 |
| 189 } // namespace content | 188 } // namespace content |
| OLD | NEW |