| OLD | NEW | 
|---|
|  | (Empty) | 
| 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 |  | 
| 3 // found in the LICENSE file. |  | 
| 4 |  | 
| 5 #ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_BLACKLIST_H_ |  | 
| 6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_BLACKLIST_H_ |  | 
| 7 |  | 
| 8 #include <map> |  | 
| 9 #include <vector> |  | 
| 10 |  | 
| 11 #include "base/lazy_instance.h" |  | 
| 12 #include "base/macros.h" |  | 
| 13 #include "base/strings/string_piece.h" |  | 
| 14 #include "content/common/content_export.h" |  | 
| 15 #include "device/bluetooth/bluetooth_uuid.h" |  | 
| 16 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj
     om.h" |  | 
| 17 |  | 
| 18 namespace content { |  | 
| 19 |  | 
| 20 // Implements the Web Bluetooth Blacklist policy as defined in the Web Bluetooth |  | 
| 21 // specification: |  | 
| 22 // https://webbluetoothcg.github.io/web-bluetooth/#the-gatt-blacklist |  | 
| 23 // |  | 
| 24 // Client code may query UUIDs to determine if they are excluded from use by the |  | 
| 25 // blacklist. |  | 
| 26 // |  | 
| 27 // Singleton access via Get() enforces only one copy of blacklist. |  | 
| 28 class CONTENT_EXPORT BluetoothBlacklist final { |  | 
| 29  public: |  | 
| 30   // Blacklist value terminology from Web Bluetooth specification: |  | 
| 31   // https://webbluetoothcg.github.io/web-bluetooth/#the-gatt-blacklist |  | 
| 32   enum class Value { |  | 
| 33     EXCLUDE,        // Implies EXCLUDE_READS and EXCLUDE_WRITES. |  | 
| 34     EXCLUDE_READS,  // Excluded from read operations. |  | 
| 35     EXCLUDE_WRITES  // Excluded from write operations. |  | 
| 36   }; |  | 
| 37 |  | 
| 38   ~BluetoothBlacklist(); |  | 
| 39 |  | 
| 40   // Returns a singleton instance of the blacklist. |  | 
| 41   static BluetoothBlacklist& Get(); |  | 
| 42 |  | 
| 43   // Adds a UUID to the blacklist to be excluded from operations, merging with |  | 
| 44   // any previous value and resulting in the strictest exclusion rule from the |  | 
| 45   // combination of the two, E.G.: |  | 
| 46   //   Add(uuid, EXCLUDE_READS); |  | 
| 47   //   Add(uuid, EXCLUDE_WRITES); |  | 
| 48   //   IsExcluded(uuid);  // true. |  | 
| 49   // Requires UUID to be valid. |  | 
| 50   void Add(const device::BluetoothUUID&, Value); |  | 
| 51 |  | 
| 52   // Adds UUIDs to the blacklist by parsing a blacklist string and calling |  | 
| 53   // Add(uuid, value). |  | 
| 54   // |  | 
| 55   // The blacklist string format is defined at |  | 
| 56   // ContentBrowserClient::GetWebBluetoothBlacklist(). |  | 
| 57   // |  | 
| 58   // Malformed pairs in the string are ignored, including invalid UUID or |  | 
| 59   // exclusion values. Duplicate UUIDs follow Add()'s merging rule. |  | 
| 60   void Add(base::StringPiece blacklist_string); |  | 
| 61 |  | 
| 62   // Returns if a UUID is excluded from all operations. UUID must be valid. |  | 
| 63   bool IsExcluded(const device::BluetoothUUID&) const; |  | 
| 64 |  | 
| 65   // Returns if any UUID in a set of filters is excluded from all operations. |  | 
| 66   // UUID must be valid. |  | 
| 67   bool IsExcluded( |  | 
| 68       const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters); |  | 
| 69 |  | 
| 70   // Returns if a UUID is excluded from read operations. UUID must be valid. |  | 
| 71   bool IsExcludedFromReads(const device::BluetoothUUID&) const; |  | 
| 72 |  | 
| 73   // Returns if a UUID is excluded from write operations. UUID must be valid. |  | 
| 74   bool IsExcludedFromWrites(const device::BluetoothUUID&) const; |  | 
| 75 |  | 
| 76   // Modifies |options->optional_services|, removing any UUIDs with |  | 
| 77   // Value::EXCLUDE. |  | 
| 78   void RemoveExcludedUUIDs( |  | 
| 79       blink::mojom::WebBluetoothRequestDeviceOptions* options); |  | 
| 80 |  | 
| 81   // Size of blacklist. |  | 
| 82   size_t size() { return blacklisted_uuids_.size(); } |  | 
| 83 |  | 
| 84   void ResetToDefaultValuesForTest(); |  | 
| 85 |  | 
| 86  private: |  | 
| 87   // friend LazyInstance to permit access to private constructor. |  | 
| 88   friend base::DefaultLazyInstanceTraits<BluetoothBlacklist>; |  | 
| 89 |  | 
| 90   BluetoothBlacklist(); |  | 
| 91 |  | 
| 92   void PopulateWithDefaultValues(); |  | 
| 93 |  | 
| 94   // Populates blacklist with values obtained dynamically from a server, able |  | 
| 95   // to be updated without shipping new executable versions. |  | 
| 96   void PopulateWithServerProvidedValues(); |  | 
| 97 |  | 
| 98   // Map of UUID to blacklisted value. |  | 
| 99   std::map<device::BluetoothUUID, Value> blacklisted_uuids_; |  | 
| 100 |  | 
| 101   DISALLOW_COPY_AND_ASSIGN(BluetoothBlacklist); |  | 
| 102 }; |  | 
| 103 |  | 
| 104 }  // namespace content |  | 
| 105 |  | 
| 106 #endif  // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_BLACKLIST_H_ |  | 
| OLD | NEW | 
|---|