1 // Copyright (c) 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.
5 #ifndef CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_
6 #define CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "chromeos/chromeos_export.h"
14 #include "chromeos/dbus/dbus_thread_manager_observer.h"
15 #include "chromeos/dbus/power_manager/policy.pb.h"
16 #include "chromeos/dbus/power_manager_client.h"
20 class DBusThreadManager
;
22 // PowerPolicyController is responsible for sending Chrome's assorted power
23 // management preferences to the Chrome OS power manager.
24 class CHROMEOS_EXPORT PowerPolicyController
25 : public DBusThreadManagerObserver
,
26 public PowerManagerClient::Observer
{
28 // Note: Do not change these values; they are used by preferences.
31 ACTION_STOP_SESSION
= 1,
33 ACTION_DO_NOTHING
= 3,
36 // Values of various power-management-related preferences.
40 int ac_screen_dim_delay_ms
;
41 int ac_screen_off_delay_ms
;
42 int ac_screen_lock_delay_ms
;
43 int ac_idle_warning_delay_ms
;
45 int battery_screen_dim_delay_ms
;
46 int battery_screen_off_delay_ms
;
47 int battery_screen_lock_delay_ms
;
48 int battery_idle_warning_delay_ms
;
49 int battery_idle_delay_ms
;
51 Action lid_closed_action
;
52 bool use_audio_activity
;
53 bool use_video_activity
;
54 bool allow_screen_wake_locks
;
55 bool enable_screen_lock
;
56 double presentation_idle_delay_factor
;
57 double user_activity_screen_dim_delay_factor
;
60 // Returns a string describing |policy|. Useful for tests.
61 static std::string
GetPolicyDebugString(
62 const power_manager::PowerManagementPolicy
& policy
);
64 // Delay in milliseconds between the screen being turned off and the
65 // screen being locked. Used if the |enable_screen_lock| pref is set but
66 // |*_screen_lock_delay_ms| are unset or set to higher values than what
67 // this constant would imply.
68 const static int kScreenLockAfterOffDelayMs
;
70 PowerPolicyController(DBusThreadManager
* manager
, PowerManagerClient
* client
);
71 virtual ~PowerPolicyController();
73 // Updates |prefs_policy_| with |values| and sends an updated policy.
74 void ApplyPrefs(const PrefValues
& values
);
76 // Registers a request to temporarily prevent the screen from getting
77 // dimmed or turned off or the system from suspending in response to user
78 // inactivity and sends an updated policy. |reason| is a human-readable
79 // description of the reason the lock was created. Returns a unique ID
80 // that can be passed to RemoveWakeLock() later.
81 int AddScreenWakeLock(const std::string
& reason
);
82 int AddSystemWakeLock(const std::string
& reason
);
84 // Unregisters a request previously created via AddScreenWakeLock() or
85 // AddSystemWakeLock() and sends an updated policy.
86 void RemoveWakeLock(int id
);
88 // DBusThreadManagerObserver implementation:
89 virtual void OnDBusThreadManagerDestroying(DBusThreadManager
* manager
)
92 // PowerManagerClient::Observer implementation:
93 virtual void PowerManagerRestarted() OVERRIDE
;
96 typedef std::map
<int, std::string
> WakeLockMap
;
98 // Sends a policy based on |prefs_policy_| to the power manager.
99 void SendCurrentPolicy();
101 // Sends an empty policy to the power manager to reset its configuration.
102 void SendEmptyPolicy();
104 DBusThreadManager
* manager_
; // not owned
105 PowerManagerClient
* client_
; // not owned
107 // Policy derived from values passed to ApplyPrefs().
108 power_manager::PowerManagementPolicy prefs_policy_
;
110 // Was ApplyPrefs() called?
111 bool prefs_were_set_
;
113 // Maps from an ID representing a request to prevent the screen from
114 // getting dimmed or turned off or to prevent the system from suspending
115 // to the reason for the request.
116 WakeLockMap screen_wake_locks_
;
117 WakeLockMap system_wake_locks_
;
119 // Should entries in |screen_wake_locks_| be honored? If false, screen
120 // wake locks are just treated as system wake locks instead.
121 bool honor_screen_wake_locks_
;
123 // Next ID to be used by AddScreenWakeLock() or AddSystemWakeLock().
124 int next_wake_lock_id_
;
126 DISALLOW_COPY_AND_ASSIGN(PowerPolicyController
);
129 } // namespace chromeos
131 #endif // CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_