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.
5 #ifndef COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WHITELIST_H
6 #define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WHITELIST_H
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
14 class PrefRegistrySimple
;
18 class DictionaryValue
;
21 namespace proximity_auth
{
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
{
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
33 explicit BluetoothLowEnergyDeviceWhitelist(PrefService
* pref_service
);
34 virtual ~BluetoothLowEnergyDeviceWhitelist();
36 // Registers the prefs used by this class to the given |pref_service|.
37 static void RegisterPrefs(PrefRegistrySimple
* registry
);
39 // Virtual for testing
40 virtual bool HasDeviceWithAddress(const std::string
& bluetooth_address
) const;
41 bool HasDeviceWithPublicKey(const std::string
& public_key
) const;
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;
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
51 void AddOrUpdateDevice(const std::string
& bluetooth_address
,
52 const std::string
& public_key
);
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
);
60 const base::DictionaryValue
* GetWhitelistPrefs() const;
62 // Contains perferences that outlive the lifetime of this object and across
64 // Not owned and must outlive this instance.
65 PrefService
* pref_service_
;
67 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceWhitelist
);
70 } // namespace proximity_auth
72 #endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_WHITELIST_H