| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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 COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WHITELIST_H | |
| 6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WHITELIST_H | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 | |
| 14 class PrefRegistrySimple; | |
| 15 class PrefService; | |
| 16 | |
| 17 namespace base { | |
| 18 class DictionaryValue; | |
| 19 } // namespace base | |
| 20 | |
| 21 namespace proximity_auth { | |
| 22 | |
| 23 // This class stores a persistent set of whitelisted bluetooth devices | |
| 24 // represented by pairs (bluetooth_address, public_key). The class enforces a | |
| 25 // bijective mapping: no two device share the same bluetooth_address or | |
| 26 // the same public_key. | |
| 27 class BluetoothLowEnergyDeviceWhitelist { | |
| 28 public: | |
| 29 // Creates a device whitelist backed by preferences registered in | |
| 30 // |pref_service| (persistent across browser restarts). |pref_service| should | |
| 31 // have been registered using RegisterPrefs(). Not owned, must out live this | |
| 32 // instance. | |
| 33 explicit BluetoothLowEnergyDeviceWhitelist(PrefService* pref_service); | |
| 34 virtual ~BluetoothLowEnergyDeviceWhitelist(); | |
| 35 | |
| 36 // Registers the prefs used by this class to the given |pref_service|. | |
| 37 static void RegisterPrefs(PrefRegistrySimple* registry); | |
| 38 | |
| 39 // Virtual for testing | |
| 40 virtual bool HasDeviceWithAddress(const std::string& bluetooth_address) const; | |
| 41 bool HasDeviceWithPublicKey(const std::string& public_key) const; | |
| 42 | |
| 43 std::string GetDevicePublicKey(const std::string& bluetooth_address) const; | |
| 44 std::string GetDeviceAddress(const std::string& public_key) const; | |
| 45 std::vector<std::string> GetPublicKeys() const; | |
| 46 | |
| 47 // Adds a device with |bluetooth_address| and |public_key|. The | |
| 48 // bluetooth_address <-> public_key mapping is unique, i.e. if there is | |
| 49 // another device with same bluetooth address or public key that device will | |
| 50 // be replaced. | |
| 51 void AddOrUpdateDevice(const std::string& bluetooth_address, | |
| 52 const std::string& public_key); | |
| 53 | |
| 54 // Removes the unique device with |bluetooth_address| (|public_key|). Returns | |
| 55 // false if no device was found. | |
| 56 bool RemoveDeviceWithAddress(const std::string& bluetooth_address); | |
| 57 bool RemoveDeviceWithPublicKey(const std::string& public_key); | |
| 58 | |
| 59 private: | |
| 60 const base::DictionaryValue* GetWhitelistPrefs() const; | |
| 61 | |
| 62 // Contains perferences that outlive the lifetime of this object and across | |
| 63 // process restarts. | |
| 64 // Not owned and must outlive this instance. | |
| 65 PrefService* pref_service_; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceWhitelist); | |
| 68 }; | |
| 69 | |
| 70 } // namespace proximity_auth | |
| 71 | |
| 72 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_WHITELIST_H | |
| OLD | NEW |