proximity_auth_profile_pref_manager.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Copyright 2017 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. #ifndef ASH_COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_PROFILE_PREF_MANAGER_H_
  5. #define ASH_COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_PROFILE_PREF_MANAGER_H_
  6. #include "ash/components/proximity_auth/proximity_auth_pref_manager.h"
  7. #include "ash/services/multidevice_setup/public/cpp/multidevice_setup_client.h"
  8. #include "base/memory/weak_ptr.h"
  9. #include "components/account_id/account_id.h"
  10. #include "components/prefs/pref_change_registrar.h"
  11. class PrefService;
  12. namespace base {
  13. class DictionaryValue;
  14. } // namespace base
  15. namespace user_prefs {
  16. class PrefRegistrySyncable;
  17. } // namespace user_prefs
  18. namespace proximity_auth {
  19. // Implementation of ProximityAuthPrefManager for a logged in session with a
  20. // user profile.
  21. class ProximityAuthProfilePrefManager
  22. : public ProximityAuthPrefManager,
  23. public ash::multidevice_setup::MultiDeviceSetupClient::Observer {
  24. public:
  25. // Creates a pref manager backed by preferences registered in
  26. // |pref_service| (persistent across browser restarts). |pref_service| should
  27. // have been registered using RegisterPrefs(). Not owned, must out live this
  28. // instance.
  29. ProximityAuthProfilePrefManager(
  30. PrefService* pref_service,
  31. ash::multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client);
  32. ProximityAuthProfilePrefManager(const ProximityAuthProfilePrefManager&) =
  33. delete;
  34. ProximityAuthProfilePrefManager& operator=(
  35. const ProximityAuthProfilePrefManager&) = delete;
  36. ~ProximityAuthProfilePrefManager() override;
  37. // Initializes the manager to listen to pref changes and sync prefs to the
  38. // user's local state.
  39. void StartSyncingToLocalState(PrefService* local_state,
  40. const AccountId& account_id);
  41. // Registers the prefs used by this class to the given |pref_service|.
  42. static void RegisterPrefs(user_prefs::PrefRegistrySyncable* registry);
  43. // ProximityAuthPrefManager:
  44. bool IsEasyUnlockAllowed() const override;
  45. void SetIsEasyUnlockEnabled(bool is_easy_unlock_enabled) const override;
  46. bool IsEasyUnlockEnabled() const override;
  47. void SetEasyUnlockEnabledStateSet() const override;
  48. bool IsEasyUnlockEnabledStateSet() const override;
  49. void SetLastPromotionCheckTimestampMs(int64_t timestamp_ms) override;
  50. int64_t GetLastPromotionCheckTimestampMs() const override;
  51. void SetPromotionShownCount(int count) override;
  52. int GetPromotionShownCount() const override;
  53. bool IsChromeOSLoginAllowed() const override;
  54. void SetIsChromeOSLoginEnabled(bool is_enabled) override;
  55. bool IsChromeOSLoginEnabled() const override;
  56. void SetHasShownLoginDisabledMessage(bool has_shown) override;
  57. bool HasShownLoginDisabledMessage() const override;
  58. // ash::multidevice_setup::MultiDeviceSetupClient::Observer:
  59. void OnFeatureStatesChanged(
  60. const ash::multidevice_setup::MultiDeviceSetupClient::FeatureStatesMap&
  61. feature_states_map) override;
  62. private:
  63. const base::DictionaryValue* GetRemoteBleDevices() const;
  64. void SyncPrefsToLocalState();
  65. // Contains perferences that outlive the lifetime of this object and across
  66. // process restarts. Not owned and must outlive this instance.
  67. PrefService* pref_service_ = nullptr;
  68. // Listens to pref changes so they can be synced to the local state.
  69. PrefChangeRegistrar registrar_;
  70. // The local state to which to sync the profile prefs.
  71. PrefService* local_state_ = nullptr;
  72. // The account id of the current profile.
  73. AccountId account_id_;
  74. // Used to determine the FeatureState of Smart Lock.
  75. ash::multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client_ =
  76. nullptr;
  77. base::WeakPtrFactory<ProximityAuthProfilePrefManager> weak_ptr_factory_{this};
  78. };
  79. } // namespace proximity_auth
  80. #endif // ASH_COMPONENTS_PROXIMITY_AUTH_PROXIMITY_AUTH_PROFILE_PREF_MANAGER_H_