power_prefs.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2013 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_SYSTEM_POWER_POWER_PREFS_H_
  5. #define ASH_SYSTEM_POWER_POWER_PREFS_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "ash/public/cpp/session/session_observer.h"
  9. #include "base/scoped_observation.h"
  10. #include "base/time/tick_clock.h"
  11. #include "base/time/time.h"
  12. #include "chromeos/dbus/power/power_manager_client.h"
  13. class PrefChangeRegistrar;
  14. class PrefRegistrySimple;
  15. class PrefService;
  16. namespace chromeos {
  17. class PowerPolicyController;
  18. } // namespace chromeos
  19. namespace power_manager {
  20. class ScreenIdleState;
  21. } // namespace power_manager
  22. namespace ash {
  23. class LockOnLeaveController;
  24. class PowerPrefsTest;
  25. // Sends an updated power policy to the |power_policy_controller| whenever one
  26. // of the power-related prefs changes.
  27. class ASH_EXPORT PowerPrefs : public chromeos::PowerManagerClient::Observer,
  28. public SessionObserver {
  29. public:
  30. PowerPrefs(chromeos::PowerPolicyController* power_policy_controller,
  31. chromeos::PowerManagerClient* power_manager_client,
  32. PrefService* local_state);
  33. PowerPrefs(const PowerPrefs&) = delete;
  34. PowerPrefs& operator=(const PowerPrefs&) = delete;
  35. ~PowerPrefs() override;
  36. // Registers power prefs with default values applicable to the local state
  37. // prefs.
  38. static void RegisterLocalStatePrefs(PrefRegistrySimple* registry);
  39. // Registers power prefs with default values applicable to the signin prefs.
  40. static void RegisterSigninProfilePrefs(PrefRegistrySimple* registry);
  41. // Registers power prefs with default values applicable to the user prefs.
  42. static void RegisterUserProfilePrefs(PrefRegistrySimple* registry);
  43. void set_tick_clock_for_test(base::TickClock* clock) { tick_clock_ = clock; }
  44. private:
  45. friend class PowerPrefsTest;
  46. // chromeos::PowerManagerClient::Observer:
  47. void ScreenIdleStateChanged(
  48. const power_manager::ScreenIdleState& proto) override;
  49. // SessionObserver:
  50. void OnLockStateChanged(bool locked) override;
  51. void OnSigninScreenPrefServiceInitialized(PrefService* prefs) override;
  52. void OnActiveUserPrefServiceChanged(PrefService* prefs) override;
  53. void UpdatePowerPolicyFromPrefs();
  54. void UpdatePowerPolicyFromPrefsChange();
  55. // Observes either the signin screen prefs or active user prefs and loads
  56. // initial settings.
  57. void ObservePrefs(PrefService* prefs);
  58. void ObserveLocalStatePrefs(PrefService* prefs);
  59. chromeos::PowerPolicyController* const
  60. power_policy_controller_; // Not owned.
  61. base::ScopedObservation<chromeos::PowerManagerClient,
  62. chromeos::PowerManagerClient::Observer>
  63. power_manager_client_observation_{this};
  64. std::unique_ptr<PrefChangeRegistrar> profile_registrar_;
  65. std::unique_ptr<PrefChangeRegistrar> local_state_registrar_;
  66. std::unique_ptr<LockOnLeaveController> lock_on_leave_controller_;
  67. const base::TickClock* tick_clock_; // Not owned.
  68. // Time at which the screen was locked. Unset if the screen is unlocked.
  69. base::TimeTicks screen_lock_time_;
  70. // Time at which the screen was last turned off due to user inactivity.
  71. // Unset if the screen isn't currently turned off due to user inactivity.
  72. base::TimeTicks screen_idle_off_time_;
  73. // The last observed quick dim state for the current pref service.
  74. bool quick_dim_pref_enabled_ = false;
  75. PrefService* local_state_ = nullptr; // Not owned.
  76. };
  77. } // namespace ash
  78. #endif // ASH_SYSTEM_POWER_POWER_PREFS_H_