| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_PREF_MANAGER_H | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_PREF_MANAGER_H |
| 6 #define COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_PREF_MANAGER_H | 6 #define COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_PREF_MANAGER_H |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 | 13 |
| 14 class PrefRegistrySimple; | |
| 15 class PrefService; | 14 class PrefService; |
| 16 | 15 |
| 17 namespace base { | 16 namespace base { |
| 18 class DictionaryValue; | 17 class DictionaryValue; |
| 19 } // namespace base | 18 } // namespace base |
| 20 | 19 |
| 20 namespace user_prefs { |
| 21 class PrefRegistrySyncable; |
| 22 } // namespace user_prefs |
| 23 |
| 21 namespace proximity_auth { | 24 namespace proximity_auth { |
| 22 | 25 |
| 23 // This class manages the local (persistent) settings used by Smart Lock. It | 26 // This class manages the local (persistent) settings used by Smart Lock. It |
| 24 // provides methods to set and queries the local settings, e.g. the address of | 27 // provides methods to set and queries the local settings, e.g. the address of |
| 25 // BLE devices. | 28 // BLE devices. |
| 26 class ProximityAuthPrefManager { | 29 class ProximityAuthPrefManager { |
| 27 public: | 30 public: |
| 28 // Creates a pref manager backed by preferences registered in | 31 // Creates a pref manager backed by preferences registered in |
| 29 // |pref_service| (persistent across browser restarts). |pref_service| should | 32 // |pref_service| (persistent across browser restarts). |pref_service| should |
| 30 // have been registered using RegisterPrefs(). Not owned, must out live this | 33 // have been registered using RegisterPrefs(). Not owned, must out live this |
| 31 // instance. | 34 // instance. |
| 32 explicit ProximityAuthPrefManager(PrefService* pref_service); | 35 explicit ProximityAuthPrefManager(PrefService* pref_service); |
| 33 virtual ~ProximityAuthPrefManager(); | 36 virtual ~ProximityAuthPrefManager(); |
| 34 | 37 |
| 35 // Registers the prefs used by this class to the given |pref_service|. | 38 // Registers the prefs used by this class to the given |pref_service|. |
| 36 static void RegisterPrefs(PrefRegistrySimple* registry); | 39 static void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry); |
| 37 | 40 |
| 38 // Methods used to handle remote BLE devices stored in prefs | 41 // Methods used to handle remote BLE devices stored in prefs |
| 39 // (kProximityAuthRemoteBleDevices). | 42 // (kProximityAuthRemoteBleDevices). |
| 40 // | 43 // |
| 41 // Each device correspond to a (public_key, bluetooth_address) pair. The | 44 // Each device correspond to a (public_key, bluetooth_address) pair. The |
| 42 // bluetooth_address <-> public_key mapping is unique, i.e. if there is | 45 // bluetooth_address <-> public_key mapping is unique, i.e. if there is |
| 43 // another device with same bluetooth address or public key that device will | 46 // another device with same bluetooth address or public key that device will |
| 44 // be replaced. | 47 // be replaced. |
| 45 void AddOrUpdateDevice(const std::string& bluetooth_address, | 48 void AddOrUpdateDevice(const std::string& bluetooth_address, |
| 46 const std::string& public_key); | 49 const std::string& public_key); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 58 const std::string& bluetooth_address) const; | 61 const std::string& bluetooth_address) const; |
| 59 virtual std::string GetDeviceAddress(const std::string& public_key) const; | 62 virtual std::string GetDeviceAddress(const std::string& public_key) const; |
| 60 virtual std::vector<std::string> GetPublicKeys() const; | 63 virtual std::vector<std::string> GetPublicKeys() const; |
| 61 | 64 |
| 62 // Setter and getter for the timestamp of the last password entry. This | 65 // Setter and getter for the timestamp of the last password entry. This |
| 63 // preference is used to enforce reauthing with the password after a given | 66 // preference is used to enforce reauthing with the password after a given |
| 64 // time period has elapsed. | 67 // time period has elapsed. |
| 65 virtual void SetLastPasswordEntryTimestampMs(int64_t timestamp_ms); | 68 virtual void SetLastPasswordEntryTimestampMs(int64_t timestamp_ms); |
| 66 virtual int64_t GetLastPasswordEntryTimestampMs() const; | 69 virtual int64_t GetLastPasswordEntryTimestampMs() const; |
| 67 | 70 |
| 71 // These are arbitrary labels displayed in the settings page for the user |
| 72 // to select. The actual mapping is done in the ProximityMonitorImpl. |
| 73 enum ProximityThreshold { |
| 74 kVeryClose = 0, |
| 75 kClose = 1, |
| 76 kFar = 2, |
| 77 kVeryFar = 3 |
| 78 }; |
| 79 |
| 80 // Setter and getter for the proximity threshold. This preference is |
| 81 // exposed to the user, allowing him / her to change how close the |
| 82 // phone must for the unlock to be allowed. |
| 83 // Note: These are arbitrary values, |
| 84 virtual void SetProximityThreshold(ProximityThreshold value); |
| 85 virtual ProximityThreshold GetProximityThreshold() const; |
| 86 |
| 68 private: | 87 private: |
| 69 const base::DictionaryValue* GetRemoteBleDevices() const; | 88 const base::DictionaryValue* GetRemoteBleDevices() const; |
| 70 | 89 |
| 71 // Contains perferences that outlive the lifetime of this object and across | 90 // Contains perferences that outlive the lifetime of this object and across |
| 72 // process restarts. Not owned and must outlive this instance. | 91 // process restarts. Not owned and must outlive this instance. |
| 73 PrefService* pref_service_; | 92 PrefService* pref_service_; |
| 74 | 93 |
| 75 DISALLOW_COPY_AND_ASSIGN(ProximityAuthPrefManager); | 94 DISALLOW_COPY_AND_ASSIGN(ProximityAuthPrefManager); |
| 76 }; | 95 }; |
| 77 | 96 |
| 78 } // namespace proximity_auth | 97 } // namespace proximity_auth |
| 79 | 98 |
| 80 #endif // COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_PREF_MANAGER_H | 99 #endif // COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_PREF_MANAGER_H |
| OLD | NEW |