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 "content/common/bluetooth/bluetooth_scan_filter.h" | 8 #include "content/common/bluetooth/bluetooth_scan_filter.h" |
9 | 9 |
10 using device::BluetoothUUID; | 10 using device::BluetoothUUID; |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 static base::LazyInstance<content::BluetoothBlacklist>::Leaky g_singleton = | 14 static base::LazyInstance<content::BluetoothBlacklist>::Leaky g_singleton = |
15 LAZY_INSTANCE_INITIALIZER; | 15 LAZY_INSTANCE_INITIALIZER; |
16 | 16 |
17 } // namespace | 17 } // namespace |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
21 BluetoothBlacklist::~BluetoothBlacklist() {} | 21 BluetoothBlacklist::~BluetoothBlacklist() {} |
22 | 22 |
23 // static | 23 // static |
24 BluetoothBlacklist& BluetoothBlacklist::Get() { | 24 BluetoothBlacklist& BluetoothBlacklist::Get() { |
25 return g_singleton.Get(); | 25 return g_singleton.Get(); |
26 } | 26 } |
27 | 27 |
28 void BluetoothBlacklist::AddOrDie(const device::BluetoothUUID& uuid, | 28 void BluetoothBlacklist::AddOrDie(const device::BluetoothUUID& uuid, |
29 Value value) { | 29 Value value) { |
| 30 CHECK(uuid.IsValid()); |
30 auto insert_result = blacklisted_uuids_.insert(std::make_pair(uuid, value)); | 31 auto insert_result = blacklisted_uuids_.insert(std::make_pair(uuid, value)); |
31 CHECK(insert_result.second); | 32 CHECK(insert_result.second); |
32 } | 33 } |
33 | 34 |
34 bool BluetoothBlacklist::IsExcluded(const BluetoothUUID& uuid) const { | 35 bool BluetoothBlacklist::IsExcluded(const BluetoothUUID& uuid) const { |
| 36 CHECK(uuid.IsValid()); |
35 const auto& it = blacklisted_uuids_.find(uuid); | 37 const auto& it = blacklisted_uuids_.find(uuid); |
36 if (it == blacklisted_uuids_.end()) | 38 if (it == blacklisted_uuids_.end()) |
37 return false; | 39 return false; |
38 return it->second == Value::EXCLUDE; | 40 return it->second == Value::EXCLUDE; |
39 } | 41 } |
40 | 42 |
41 bool BluetoothBlacklist::IsExcluded( | 43 bool BluetoothBlacklist::IsExcluded( |
42 const std::vector<content::BluetoothScanFilter>& filters) { | 44 const std::vector<content::BluetoothScanFilter>& filters) { |
43 for (const BluetoothScanFilter& filter : filters) { | 45 for (const BluetoothScanFilter& filter : filters) { |
44 for (const BluetoothUUID& service : filter.services) { | 46 for (const BluetoothUUID& service : filter.services) { |
45 if (IsExcluded(service)) { | 47 if (IsExcluded(service)) { |
46 return true; | 48 return true; |
47 } | 49 } |
48 } | 50 } |
49 } | 51 } |
50 return false; | 52 return false; |
51 } | 53 } |
52 | 54 |
53 bool BluetoothBlacklist::IsExcludedFromReads(const BluetoothUUID& uuid) const { | 55 bool BluetoothBlacklist::IsExcludedFromReads(const BluetoothUUID& uuid) const { |
| 56 CHECK(uuid.IsValid()); |
54 const auto& it = blacklisted_uuids_.find(uuid); | 57 const auto& it = blacklisted_uuids_.find(uuid); |
55 if (it == blacklisted_uuids_.end()) | 58 if (it == blacklisted_uuids_.end()) |
56 return false; | 59 return false; |
57 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_READS; | 60 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_READS; |
58 } | 61 } |
59 | 62 |
60 bool BluetoothBlacklist::IsExcludedFromWrites(const BluetoothUUID& uuid) const { | 63 bool BluetoothBlacklist::IsExcludedFromWrites(const BluetoothUUID& uuid) const { |
| 64 CHECK(uuid.IsValid()); |
61 const auto& it = blacklisted_uuids_.find(uuid); | 65 const auto& it = blacklisted_uuids_.find(uuid); |
62 if (it == blacklisted_uuids_.end()) | 66 if (it == blacklisted_uuids_.end()) |
63 return false; | 67 return false; |
64 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_WRITES; | 68 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_WRITES; |
65 } | 69 } |
66 | 70 |
67 void BluetoothBlacklist::RemoveExcludedUuids( | 71 void BluetoothBlacklist::RemoveExcludedUuids( |
68 std::vector<device::BluetoothUUID>* uuids) { | 72 std::vector<device::BluetoothUUID>* uuids) { |
69 auto it = uuids->begin(); | 73 auto it = uuids->begin(); |
70 while (it != uuids->end()) { | 74 while (it != uuids->end()) { |
(...skipping 27 matching lines...) Expand all Loading... |
98 // ## Characteristics | 102 // ## Characteristics |
99 AddOrDie(BluetoothUUID("2a02"), Value::EXCLUDE_WRITES); | 103 AddOrDie(BluetoothUUID("2a02"), Value::EXCLUDE_WRITES); |
100 AddOrDie(BluetoothUUID("2a03"), Value::EXCLUDE); | 104 AddOrDie(BluetoothUUID("2a03"), Value::EXCLUDE); |
101 AddOrDie(BluetoothUUID("2a25"), Value::EXCLUDE); | 105 AddOrDie(BluetoothUUID("2a25"), Value::EXCLUDE); |
102 // ## Descriptors | 106 // ## Descriptors |
103 AddOrDie(BluetoothUUID("2902"), Value::EXCLUDE_WRITES); | 107 AddOrDie(BluetoothUUID("2902"), Value::EXCLUDE_WRITES); |
104 AddOrDie(BluetoothUUID("2903"), Value::EXCLUDE_WRITES); | 108 AddOrDie(BluetoothUUID("2903"), Value::EXCLUDE_WRITES); |
105 } | 109 } |
106 | 110 |
107 } // namespace content | 111 } // namespace content |
OLD | NEW |