OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_ | 5 #ifndef CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_ |
6 #define CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_ | 6 #define CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... | |
25 | 25 |
26 // Returns true if the global instance has been initialized. | 26 // Returns true if the global instance has been initialized. |
27 static bool IsInitialized(); | 27 static bool IsInitialized(); |
28 | 28 |
29 // Destroys the global instance. | 29 // Destroys the global instance. |
30 static void Shutdown(); | 30 static void Shutdown(); |
31 | 31 |
32 // Returns the global instance. Initialize() must be called first. | 32 // Returns the global instance. Initialize() must be called first. |
33 static PowerPolicyController* Get(); | 33 static PowerPolicyController* Get(); |
34 | 34 |
35 // Reasons why a wake lock may be added. | |
36 enum WakeLockReason { | |
37 REASON_AUDIO_PLAYBACK, | |
38 REASON_VIDEO_PLAYBACK, | |
39 REASON_OTHER, | |
40 }; | |
41 | |
35 // Note: Do not change these values; they are used by preferences. | 42 // Note: Do not change these values; they are used by preferences. |
36 enum Action { | 43 enum Action { |
37 ACTION_SUSPEND = 0, | 44 ACTION_SUSPEND = 0, |
38 ACTION_STOP_SESSION = 1, | 45 ACTION_STOP_SESSION = 1, |
39 ACTION_SHUT_DOWN = 2, | 46 ACTION_SHUT_DOWN = 2, |
40 ACTION_DO_NOTHING = 3, | 47 ACTION_DO_NOTHING = 3, |
41 }; | 48 }; |
42 | 49 |
43 // Values of various power-management-related preferences. | 50 // Values of various power-management-related preferences. |
44 struct PrefValues { | 51 struct PrefValues { |
(...skipping 27 matching lines...) Expand all Loading... | |
72 // Returns a string describing |policy|. Useful for tests. | 79 // Returns a string describing |policy|. Useful for tests. |
73 static std::string GetPolicyDebugString( | 80 static std::string GetPolicyDebugString( |
74 const power_manager::PowerManagementPolicy& policy); | 81 const power_manager::PowerManagementPolicy& policy); |
75 | 82 |
76 // Delay in milliseconds between the screen being turned off and the screen | 83 // Delay in milliseconds between the screen being turned off and the screen |
77 // being locked. Used if the |enable_auto_screen_lock| pref is set but | 84 // being locked. Used if the |enable_auto_screen_lock| pref is set but |
78 // |*_screen_lock_delay_ms| are unset or set to higher values than what this | 85 // |*_screen_lock_delay_ms| are unset or set to higher values than what this |
79 // constant would imply. | 86 // constant would imply. |
80 static const int kScreenLockAfterOffDelayMs; | 87 static const int kScreenLockAfterOffDelayMs; |
81 | 88 |
89 // String added to a PowerManagementPolicy |reason| field if the policy has | |
90 // been modified by preferences. | |
91 static const char kPrefsReason[]; | |
92 | |
82 // Updates |prefs_policy_| with |values| and sends an updated policy. | 93 // Updates |prefs_policy_| with |values| and sends an updated policy. |
83 void ApplyPrefs(const PrefValues& values); | 94 void ApplyPrefs(const PrefValues& values); |
84 | 95 |
85 // Registers a request to temporarily prevent the screen from getting | 96 // Registers a request to temporarily prevent the screen from getting dimmed |
86 // dimmed or turned off or the system from suspending in response to user | 97 // or turned off or the system from suspending in response to user inactivity |
87 // inactivity and sends an updated policy. |reason| is a human-readable | 98 // and sends an updated policy. |description| is a human-readable description |
88 // description of the reason the lock was created. Returns a unique ID | 99 // of the reason the lock was created. Returns a unique ID that can be passed |
89 // that can be passed to RemoveWakeLock() later. | 100 // to RemoveWakeLock() later. |
90 int AddScreenWakeLock(const std::string& reason); | 101 int AddScreenWakeLock(WakeLockReason reason, const std::string& description); |
91 int AddSystemWakeLock(const std::string& reason); | 102 int AddSystemWakeLock(WakeLockReason reason, const std::string& description); |
92 | 103 |
93 // Unregisters a request previously created via AddScreenWakeLock() or | 104 // Unregisters a request previously created via AddScreenWakeLock() or |
94 // AddSystemWakeLock() and sends an updated policy. | 105 // AddSystemWakeLock() and sends an updated policy. |
95 void RemoveWakeLock(int id); | 106 void RemoveWakeLock(int id); |
96 | 107 |
97 // PowerManagerClient::Observer implementation: | 108 // PowerManagerClient::Observer implementation: |
98 void PowerManagerRestarted() override; | 109 void PowerManagerRestarted() override; |
99 | 110 |
100 private: | 111 private: |
101 explicit PowerPolicyController(PowerManagerClient* client); | 112 explicit PowerPolicyController(PowerManagerClient* client); |
102 ~PowerPolicyController() override; | 113 ~PowerPolicyController() override; |
103 | 114 |
104 friend class PowerPrefsTest; | 115 friend class PowerPrefsTest; |
105 | 116 |
106 typedef std::map<int, std::string> WakeLockMap; | 117 // Details about a wake lock added via AddScreenWakeLock() or |
118 // AddSystemWakeLock(). | |
119 struct WakeLock { | |
120 enum Type { | |
121 TYPE_SCREEN, | |
122 TYPE_SYSTEM, | |
123 }; | |
124 | |
125 WakeLock(Type type, WakeLockReason reason, const std::string& description); | |
126 ~WakeLock(); | |
127 | |
128 Type type; | |
bartfab (slow)
2015/02/23 13:56:49
Nit: const.
Daniel Erat
2015/02/23 16:34:05
Done.
| |
129 WakeLockReason reason; | |
bartfab (slow)
2015/02/23 13:56:49
Nit: const.
Daniel Erat
2015/02/23 16:34:05
Done.
| |
130 std::string description; | |
bartfab (slow)
2015/02/23 13:56:49
Nit: const.
Daniel Erat
2015/02/23 16:34:05
Done.
| |
131 }; | |
132 | |
133 typedef std::map<int, WakeLock> WakeLockMap; | |
bartfab (slow)
2015/02/23 13:56:49
Nit: Use C++11 using= instead of typedef.
Daniel Erat
2015/02/23 16:34:05
Done.
| |
134 | |
135 // Helper method for AddScreenWakeLock() and AddSystemWakeLock(). | |
136 int AddWakeLockInternal(WakeLock::Type type, | |
137 WakeLockReason reason, | |
138 const std::string& description); | |
107 | 139 |
108 // Sends a policy based on |prefs_policy_| to the power manager. | 140 // Sends a policy based on |prefs_policy_| to the power manager. |
109 void SendCurrentPolicy(); | 141 void SendCurrentPolicy(); |
110 | 142 |
111 PowerManagerClient* client_; // weak | 143 PowerManagerClient* client_; // weak |
112 | 144 |
113 // Policy derived from values passed to ApplyPrefs(). | 145 // Policy derived from values passed to ApplyPrefs(). |
114 power_manager::PowerManagementPolicy prefs_policy_; | 146 power_manager::PowerManagementPolicy prefs_policy_; |
115 | 147 |
116 // Was ApplyPrefs() called? | 148 // Was ApplyPrefs() called? |
117 bool prefs_were_set_; | 149 bool prefs_were_set_; |
118 | 150 |
119 // Maps from an ID representing a request to prevent the screen from | 151 // Maps from an ID representing a request to prevent the screen from |
120 // getting dimmed or turned off or to prevent the system from suspending | 152 // getting dimmed or turned off or to prevent the system from suspending |
121 // to the reason for the request. | 153 // to details about the request. |
122 WakeLockMap screen_wake_locks_; | 154 WakeLockMap wake_locks_; |
123 WakeLockMap system_wake_locks_; | |
124 | 155 |
125 // Should entries in |screen_wake_locks_| be honored? If false, screen | 156 // Should TYPE_SCREEN entries in |wake_locks_| be honored? If false, screen |
126 // wake locks are just treated as system wake locks instead. | 157 // wake locks are just treated as TYPE_SYSTEM instead. |
127 bool honor_screen_wake_locks_; | 158 bool honor_screen_wake_locks_; |
128 | 159 |
129 // Next ID to be used by AddScreenWakeLock() or AddSystemWakeLock(). | 160 // Next ID to be used by AddScreenWakeLock() or AddSystemWakeLock(). |
130 int next_wake_lock_id_; | 161 int next_wake_lock_id_; |
131 | 162 |
132 DISALLOW_COPY_AND_ASSIGN(PowerPolicyController); | 163 DISALLOW_COPY_AND_ASSIGN(PowerPolicyController); |
133 }; | 164 }; |
134 | 165 |
135 } // namespace chromeos | 166 } // namespace chromeos |
136 | 167 |
137 #endif // CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_ | 168 #endif // CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_ |
OLD | NEW |