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