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 "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; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 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 auto insert_result = blacklisted_uuids_.insert(std::make_pair(uuid, value)); | 30 auto insert_result = blacklisted_uuids_.insert(std::make_pair(uuid, value)); |
| 31 CHECK(insert_result.second); | 31 CHECK(insert_result.second); |
| 32 } | 32 } |
| 33 | 33 |
| 34 bool BluetoothBlacklist::IsExcluded(const BluetoothUUID& uuid) const { | 34 bool BluetoothBlacklist::IsExcluded(const BluetoothUUID& uuid) const { |
| 35 CHECK(uuid.IsValid()); | |
| 35 const auto& it = blacklisted_uuids_.find(uuid); | 36 const auto& it = blacklisted_uuids_.find(uuid); |
| 36 if (it == blacklisted_uuids_.end()) | 37 if (it == blacklisted_uuids_.end()) |
| 37 return false; | 38 return false; |
| 38 return it->second == Value::EXCLUDE; | 39 return it->second == Value::EXCLUDE; |
| 39 } | 40 } |
| 40 | 41 |
| 41 bool BluetoothBlacklist::IsExcluded( | 42 bool BluetoothBlacklist::IsExcluded( |
| 42 const std::vector<content::BluetoothScanFilter>& filters) { | 43 const std::vector<content::BluetoothScanFilter>& filters) { |
| 43 for (const BluetoothScanFilter& filter : filters) { | 44 for (const BluetoothScanFilter& filter : filters) { |
| 44 for (const BluetoothUUID& service : filter.services) { | 45 for (const BluetoothUUID& service : filter.services) { |
| 45 if (IsExcluded(service)) { | 46 if (IsExcluded(service)) { |
| 46 return true; | 47 return true; |
| 47 } | 48 } |
| 48 } | 49 } |
| 49 } | 50 } |
| 50 return false; | 51 return false; |
| 51 } | 52 } |
| 52 | 53 |
| 53 bool BluetoothBlacklist::IsExcludedFromReads(const BluetoothUUID& uuid) const { | 54 bool BluetoothBlacklist::IsExcludedFromReads(const BluetoothUUID& uuid) const { |
| 55 CHECK(uuid.IsValid()); | |
|
ortuno
2016/02/19 20:54:51
Why not check that added UUIDs are valid as well?
scheib
2016/02/22 20:27:12
Done.
| |
| 54 const auto& it = blacklisted_uuids_.find(uuid); | 56 const auto& it = blacklisted_uuids_.find(uuid); |
| 55 if (it == blacklisted_uuids_.end()) | 57 if (it == blacklisted_uuids_.end()) |
| 56 return false; | 58 return false; |
| 57 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_READS; | 59 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_READS; |
| 58 } | 60 } |
| 59 | 61 |
| 60 bool BluetoothBlacklist::IsExcludedFromWrites(const BluetoothUUID& uuid) const { | 62 bool BluetoothBlacklist::IsExcludedFromWrites(const BluetoothUUID& uuid) const { |
| 63 CHECK(uuid.IsValid()); | |
| 61 const auto& it = blacklisted_uuids_.find(uuid); | 64 const auto& it = blacklisted_uuids_.find(uuid); |
| 62 if (it == blacklisted_uuids_.end()) | 65 if (it == blacklisted_uuids_.end()) |
| 63 return false; | 66 return false; |
| 64 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_WRITES; | 67 return it->second == Value::EXCLUDE || it->second == Value::EXCLUDE_WRITES; |
| 65 } | 68 } |
| 66 | 69 |
| 67 void BluetoothBlacklist::RemoveExcludedUuids( | 70 void BluetoothBlacklist::RemoveExcludedUuids( |
| 68 std::vector<device::BluetoothUUID>* uuids) { | 71 std::vector<device::BluetoothUUID>* uuids) { |
| 69 auto it = uuids->begin(); | 72 auto it = uuids->begin(); |
| 70 while (it != uuids->end()) { | 73 while (it != uuids->end()) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 98 // ## Characteristics | 101 // ## Characteristics |
| 99 AddOrDie(BluetoothUUID("2a02"), Value::EXCLUDE_WRITES); | 102 AddOrDie(BluetoothUUID("2a02"), Value::EXCLUDE_WRITES); |
| 100 AddOrDie(BluetoothUUID("2a03"), Value::EXCLUDE); | 103 AddOrDie(BluetoothUUID("2a03"), Value::EXCLUDE); |
| 101 AddOrDie(BluetoothUUID("2a25"), Value::EXCLUDE); | 104 AddOrDie(BluetoothUUID("2a25"), Value::EXCLUDE); |
| 102 // ## Descriptors | 105 // ## Descriptors |
| 103 AddOrDie(BluetoothUUID("2902"), Value::EXCLUDE_WRITES); | 106 AddOrDie(BluetoothUUID("2902"), Value::EXCLUDE_WRITES); |
| 104 AddOrDie(BluetoothUUID("2903"), Value::EXCLUDE_WRITES); | 107 AddOrDie(BluetoothUUID("2903"), Value::EXCLUDE_WRITES); |
| 105 } | 108 } |
| 106 | 109 |
| 107 } // namespace content | 110 } // namespace content |
| OLD | NEW |