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 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "chromeos/chromeos_export.h" | 13 #include "chromeos/chromeos_export.h" |
| 14 #include "chromeos/dbus/dbus_thread_manager_observer.h" |
14 #include "chromeos/dbus/power_manager/policy.pb.h" | 15 #include "chromeos/dbus/power_manager/policy.pb.h" |
15 #include "chromeos/dbus/power_manager_client.h" | 16 #include "chromeos/dbus/power_manager_client.h" |
16 | 17 |
17 namespace chromeos { | 18 namespace chromeos { |
18 | 19 |
19 class DBusThreadManager; | 20 class DBusThreadManager; |
20 | 21 |
21 // PowerPolicyController is responsible for sending Chrome's assorted power | 22 // PowerPolicyController is responsible for sending Chrome's assorted power |
22 // management preferences to the Chrome OS power manager. | 23 // management preferences to the Chrome OS power manager. |
23 class CHROMEOS_EXPORT PowerPolicyController | 24 class CHROMEOS_EXPORT PowerPolicyController |
24 : public PowerManagerClient::Observer { | 25 : public DBusThreadManagerObserver, |
| 26 public PowerManagerClient::Observer { |
25 public: | 27 public: |
26 // Note: Do not change these values; they are used by preferences. | 28 // Note: Do not change these values; they are used by preferences. |
27 enum Action { | 29 enum Action { |
28 ACTION_SUSPEND = 0, | 30 ACTION_SUSPEND = 0, |
29 ACTION_STOP_SESSION = 1, | 31 ACTION_STOP_SESSION = 1, |
30 ACTION_SHUT_DOWN = 2, | 32 ACTION_SHUT_DOWN = 2, |
31 ACTION_DO_NOTHING = 3, | 33 ACTION_DO_NOTHING = 3, |
32 }; | 34 }; |
33 | 35 |
34 // Values of various power-management-related preferences. | 36 // Values of various power-management-related preferences. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 static const int kScreenLockAfterOffDelayMs; | 72 static const int kScreenLockAfterOffDelayMs; |
71 | 73 |
72 PowerPolicyController(); | 74 PowerPolicyController(); |
73 virtual ~PowerPolicyController(); | 75 virtual ~PowerPolicyController(); |
74 | 76 |
75 void Init(DBusThreadManager* manager); | 77 void Init(DBusThreadManager* manager); |
76 | 78 |
77 // Updates |prefs_policy_| with |values| and sends an updated policy. | 79 // Updates |prefs_policy_| with |values| and sends an updated policy. |
78 void ApplyPrefs(const PrefValues& values); | 80 void ApplyPrefs(const PrefValues& values); |
79 | 81 |
| 82 // Resets |prefs_policy_| to its defaults and sends an updated policy. |
| 83 void ClearPrefs(); |
| 84 |
80 // Registers a request to temporarily prevent the screen from getting | 85 // Registers a request to temporarily prevent the screen from getting |
81 // dimmed or turned off or the system from suspending in response to user | 86 // dimmed or turned off or the system from suspending in response to user |
82 // inactivity and sends an updated policy. |reason| is a human-readable | 87 // inactivity and sends an updated policy. |reason| is a human-readable |
83 // description of the reason the lock was created. Returns a unique ID | 88 // description of the reason the lock was created. Returns a unique ID |
84 // that can be passed to RemoveWakeLock() later. | 89 // that can be passed to RemoveWakeLock() later. |
85 int AddScreenWakeLock(const std::string& reason); | 90 int AddScreenWakeLock(const std::string& reason); |
86 int AddSystemWakeLock(const std::string& reason); | 91 int AddSystemWakeLock(const std::string& reason); |
87 | 92 |
88 // Unregisters a request previously created via AddScreenWakeLock() or | 93 // Unregisters a request previously created via AddScreenWakeLock() or |
89 // AddSystemWakeLock() and sends an updated policy. | 94 // AddSystemWakeLock() and sends an updated policy. |
90 void RemoveWakeLock(int id); | 95 void RemoveWakeLock(int id); |
91 | 96 |
| 97 // DBusThreadManagerObserver implementation: |
| 98 virtual void OnDBusThreadManagerDestroying(DBusThreadManager* manager) |
| 99 OVERRIDE; |
| 100 |
92 // PowerManagerClient::Observer implementation: | 101 // PowerManagerClient::Observer implementation: |
93 virtual void PowerManagerRestarted() OVERRIDE; | 102 virtual void PowerManagerRestarted() OVERRIDE; |
94 | 103 |
95 private: | 104 private: |
96 friend class PowerPrefsTest; | 105 friend class PowerPrefsTest; |
97 | 106 |
98 typedef std::map<int, std::string> WakeLockMap; | 107 typedef std::map<int, std::string> WakeLockMap; |
99 | 108 |
100 // Sends a policy based on |prefs_policy_| to the power manager. | 109 // Sends a policy based on |prefs_policy_| to the power manager. |
101 void SendCurrentPolicy(); | 110 void SendCurrentPolicy(); |
102 | 111 |
103 PowerManagerClient* client_; // weak | 112 // Sends an empty policy to the power manager to reset its configuration. |
| 113 void SendEmptyPolicy(); |
| 114 |
| 115 DBusThreadManager* manager_; // not owned |
| 116 PowerManagerClient* client_; // not owned |
104 | 117 |
105 // Policy derived from values passed to ApplyPrefs(). | 118 // Policy derived from values passed to ApplyPrefs(). |
106 power_manager::PowerManagementPolicy prefs_policy_; | 119 power_manager::PowerManagementPolicy prefs_policy_; |
107 | 120 |
108 // Was ApplyPrefs() called? | 121 // Was ApplyPrefs() called? |
109 bool prefs_were_set_; | 122 bool prefs_were_set_; |
110 | 123 |
111 // Maps from an ID representing a request to prevent the screen from | 124 // Maps from an ID representing a request to prevent the screen from |
112 // getting dimmed or turned off or to prevent the system from suspending | 125 // getting dimmed or turned off or to prevent the system from suspending |
113 // to the reason for the request. | 126 // to the reason for the request. |
114 WakeLockMap screen_wake_locks_; | 127 WakeLockMap screen_wake_locks_; |
115 WakeLockMap system_wake_locks_; | 128 WakeLockMap system_wake_locks_; |
116 | 129 |
117 // Should entries in |screen_wake_locks_| be honored? If false, screen | 130 // Should entries in |screen_wake_locks_| be honored? If false, screen |
118 // wake locks are just treated as system wake locks instead. | 131 // wake locks are just treated as system wake locks instead. |
119 bool honor_screen_wake_locks_; | 132 bool honor_screen_wake_locks_; |
120 | 133 |
121 // Next ID to be used by AddScreenWakeLock() or AddSystemWakeLock(). | 134 // Next ID to be used by AddScreenWakeLock() or AddSystemWakeLock(). |
122 int next_wake_lock_id_; | 135 int next_wake_lock_id_; |
123 | 136 |
124 DISALLOW_COPY_AND_ASSIGN(PowerPolicyController); | 137 DISALLOW_COPY_AND_ASSIGN(PowerPolicyController); |
125 }; | 138 }; |
126 | 139 |
127 } // namespace chromeos | 140 } // namespace chromeos |
128 | 141 |
129 #endif // CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_ | 142 #endif // CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_ |
OLD | NEW |