blob: 76d0db2797fe08d0a15d84f4d4a4d4bc9802cc55 [file] [log] [blame]
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include "ash/ash_export.h"
#include "ash/session/session_observer.h"
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "base/time/tick_clock.h"
#include "chromeos/dbus/power_manager_client.h"
class PrefChangeRegistrar;
class PrefRegistrySimple;
class PrefService;
namespace chromeos {
class PowerPolicyController;
} // namespace chromeos
namespace power_manager {
class ScreenIdleState;
} // namespace power_manager
namespace ash {
// Sends an updated power policy to the |power_policy_controller| whenever one
// of the power-related prefs changes.
class ASH_EXPORT PowerPrefs : public chromeos::PowerManagerClient::Observer,
public SessionObserver {
PowerPrefs(chromeos::PowerPolicyController* power_policy_controller,
chromeos::PowerManagerClient* power_manager_client);
~PowerPrefs() override;
// Registers power prefs with default values applicable to the signin prefs.
static void RegisterSigninProfilePrefs(PrefRegistrySimple* registry,
bool for_test = false);
// Registers power prefs with default values applicable to the user prefs.
static void RegisterUserProfilePrefs(PrefRegistrySimple* registry,
bool for_test = false);
void set_tick_clock_for_test(base::TickClock* clock) { tick_clock_ = clock; }
// chromeos::PowerManagerClient::Observer:
void ScreenIdleStateChanged(
const power_manager::ScreenIdleState& proto) override;
// SessionObserver:
void OnLockStateChanged(bool locked) override;
void OnSigninScreenPrefServiceInitialized(PrefService* prefs) override;
void OnActiveUserPrefServiceChanged(PrefService* prefs) override;
void UpdatePowerPolicyFromPrefs();
// Observes either the signin screen prefs or active user prefs and loads
// initial settings.
void ObservePrefs(PrefService* prefs);
chromeos::PowerPolicyController* const
power_policy_controller_; // Not owned.
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
const base::TickClock* tick_clock_; // Not owned.
// Time at which the screen was locked. Unset if the screen is unlocked.
base::TimeTicks screen_lock_time_;
// Time at which the screen was last turned off due to user inactivity.
// Unset if the screen isn't currently turned off due to user inactivity.
base::TimeTicks screen_idle_off_time_;
} // namespace ash