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 "base/prefs/pref_service.h" | |
14 #include "chromeos/chromeos_export.h" | 13 #include "chromeos/chromeos_export.h" |
15 #include "chromeos/dbus/dbus_thread_manager_observer.h" | 14 #include "chromeos/dbus/dbus_thread_manager_observer.h" |
16 #include "chromeos/dbus/power_manager/policy.pb.h" | 15 #include "chromeos/dbus/power_manager/policy.pb.h" |
17 #include "chromeos/dbus/power_manager_client.h" | 16 #include "chromeos/dbus/power_manager_client.h" |
18 | 17 |
19 namespace chromeos { | 18 namespace chromeos { |
20 | 19 |
21 class DBusThreadManager; | 20 class DBusThreadManager; |
22 | 21 |
23 // PowerPolicyController is responsible for sending Chrome's assorted power | 22 // PowerPolicyController is responsible for sending Chrome's assorted power |
24 // management preferences to the Chrome OS power manager. | 23 // management preferences to the Chrome OS power manager. |
25 class CHROMEOS_EXPORT PowerPolicyController | 24 class CHROMEOS_EXPORT PowerPolicyController |
26 : public DBusThreadManagerObserver, | 25 : public DBusThreadManagerObserver, |
27 public PowerManagerClient::Observer { | 26 public PowerManagerClient::Observer { |
28 public: | 27 public: |
29 // Note: Do not change these values; they are used by preferences. | 28 // Note: Do not change these values; they are used by preferences. |
30 enum Action { | 29 enum Action { |
31 ACTION_SUSPEND = 0, | 30 ACTION_SUSPEND = 0, |
32 ACTION_STOP_SESSION = 1, | 31 ACTION_STOP_SESSION = 1, |
33 ACTION_SHUT_DOWN = 2, | 32 ACTION_SHUT_DOWN = 2, |
34 ACTION_DO_NOTHING = 3, | 33 ACTION_DO_NOTHING = 3, |
35 }; | 34 }; |
36 | 35 |
36 // Values of various power-management-related preferences. | |
37 struct PrefValues { | |
38 PrefValues() | |
39 : ac_screen_dim_delay_ms(-1), | |
bartfab (slow)
2013/04/18 14:17:22
As discussed offline, please add a comment that ex
Daniel Erat
2013/04/18 14:37:10
Done.
| |
40 ac_screen_off_delay_ms(-1), | |
41 ac_screen_lock_delay_ms(-1), | |
42 ac_idle_warning_delay_ms(-1), | |
43 ac_idle_delay_ms(-1), | |
44 battery_screen_dim_delay_ms(-1), | |
45 battery_screen_off_delay_ms(-1), | |
46 battery_screen_lock_delay_ms(-1), | |
47 battery_idle_warning_delay_ms(-1), | |
48 battery_idle_delay_ms(-1), | |
49 idle_action(ACTION_SUSPEND), | |
50 lid_closed_action(ACTION_SUSPEND), | |
51 use_audio_activity(true), | |
52 use_video_activity(true), | |
53 enable_screen_lock(false), | |
54 presentation_idle_delay_factor(2.0) {} | |
55 | |
56 int ac_screen_dim_delay_ms; | |
57 int ac_screen_off_delay_ms; | |
58 int ac_screen_lock_delay_ms; | |
59 int ac_idle_warning_delay_ms; | |
60 int ac_idle_delay_ms; | |
61 int battery_screen_dim_delay_ms; | |
62 int battery_screen_off_delay_ms; | |
63 int battery_screen_lock_delay_ms; | |
64 int battery_idle_warning_delay_ms; | |
65 int battery_idle_delay_ms; | |
66 Action idle_action; | |
67 Action lid_closed_action; | |
68 bool use_audio_activity; | |
69 bool use_video_activity; | |
70 bool enable_screen_lock; | |
71 double presentation_idle_delay_factor; | |
72 }; | |
73 | |
37 PowerPolicyController(DBusThreadManager* manager, PowerManagerClient* client); | 74 PowerPolicyController(DBusThreadManager* manager, PowerManagerClient* client); |
38 virtual ~PowerPolicyController(); | 75 virtual ~PowerPolicyController(); |
39 | 76 |
40 // Sends an updated policy to the power manager based on the current | 77 // Updates |prefs_policy_| with |values| and sends an updated policy. |
41 // values of the passed-in prefs. | 78 void ApplyPrefs(const PrefValues& values); |
42 void UpdatePolicyFromPrefs( | |
43 const PrefService::Preference& ac_screen_dim_delay_ms_pref, | |
44 const PrefService::Preference& ac_screen_off_delay_ms_pref, | |
45 const PrefService::Preference& ac_screen_lock_delay_ms_pref, | |
46 const PrefService::Preference& ac_idle_warning_delay_ms_pref, | |
47 const PrefService::Preference& ac_idle_delay_ms_pref, | |
48 const PrefService::Preference& battery_screen_dim_delay_ms_pref, | |
49 const PrefService::Preference& battery_screen_off_delay_ms_pref, | |
50 const PrefService::Preference& battery_screen_lock_delay_ms_pref, | |
51 const PrefService::Preference& battery_idle_warning_delay_ms_pref, | |
52 const PrefService::Preference& battery_idle_delay_ms_pref, | |
53 const PrefService::Preference& idle_action_pref, | |
54 const PrefService::Preference& lid_closed_action_pref, | |
55 const PrefService::Preference& use_audio_activity_pref, | |
56 const PrefService::Preference& use_video_activity_pref, | |
57 const PrefService::Preference& presentation_idle_delay_factor_pref); | |
58 | 79 |
59 // Registers a request to temporarily prevent the screen from getting | 80 // Registers a request to temporarily prevent the screen from getting |
60 // dimmed or turned off or the system from suspending in response to user | 81 // dimmed or turned off or the system from suspending in response to user |
61 // inactivity. Returns a unique ID that can be passed to RemoveBlock() | 82 // inactivity and sends an updated policy. Returns a unique ID that can |
62 // later. | 83 // be passed to RemoveBlock() later. |
63 int AddScreenBlock(const std::string& reason); | 84 int AddScreenBlock(const std::string& reason); |
64 int AddSuspendBlock(const std::string& reason); | 85 int AddSuspendBlock(const std::string& reason); |
65 | 86 |
66 // Unregisters a request previously created via AddScreenBlock() or | 87 // Unregisters a request previously created via AddScreenBlock() or |
67 // AddSuspendBlock(). | 88 // AddSuspendBlock() and sends an updated policy. |
68 void RemoveBlock(int id); | 89 void RemoveBlock(int id); |
69 | 90 |
70 // DBusThreadManagerObserver implementation: | 91 // DBusThreadManagerObserver implementation: |
71 virtual void OnDBusThreadManagerDestroying(DBusThreadManager* manager) | 92 virtual void OnDBusThreadManagerDestroying(DBusThreadManager* manager) |
72 OVERRIDE; | 93 OVERRIDE; |
73 | 94 |
74 // PowerManagerClient::Observer implementation: | 95 // PowerManagerClient::Observer implementation: |
75 virtual void PowerManagerRestarted() OVERRIDE; | 96 virtual void PowerManagerRestarted() OVERRIDE; |
76 | 97 |
77 private: | 98 private: |
78 typedef std::map<int, std::string> BlockMap; | 99 typedef std::map<int, std::string> BlockMap; |
79 | 100 |
80 // Sends a policy based on |prefs_policy_| to the power manager. | 101 // Sends a policy based on |prefs_policy_| to the power manager. |
81 void SendCurrentPolicy(); | 102 void SendCurrentPolicy(); |
82 | 103 |
83 // Sends an empty policy to the power manager to reset its configuration. | 104 // Sends an empty policy to the power manager to reset its configuration. |
84 void SendEmptyPolicy(); | 105 void SendEmptyPolicy(); |
85 | 106 |
86 DBusThreadManager* manager_; // not owned | 107 DBusThreadManager* manager_; // not owned |
87 PowerManagerClient* client_; // not owned | 108 PowerManagerClient* client_; // not owned |
88 | 109 |
89 // Policy specified by the prefs that were last passed to | 110 // Policy derived from values passed to ApplyPrefs(). |
90 // UpdatePolicyFromPrefs(). | |
91 power_manager::PowerManagementPolicy prefs_policy_; | 111 power_manager::PowerManagementPolicy prefs_policy_; |
92 | 112 |
93 // Are one or more fields set in |prefs_policy_|? | 113 // Was ApplyPrefs() called? |
94 bool prefs_were_set_; | 114 bool prefs_were_set_; |
95 | 115 |
96 // Maps from an ID representing a request to prevent the screen from | 116 // Maps from an ID representing a request to prevent the screen from |
97 // getting dimmed or turned off or to prevent the system from suspending | 117 // getting dimmed or turned off or to prevent the system from suspending |
98 // to the reason for the request. | 118 // to the reason for the request. |
99 BlockMap screen_blocks_; | 119 BlockMap screen_blocks_; |
100 BlockMap suspend_blocks_; | 120 BlockMap suspend_blocks_; |
101 | 121 |
102 // Next ID to be used by AddScreenBlock() or AddSuspendBlock(). | 122 // Next ID to be used by AddScreenBlock() or AddSuspendBlock(). |
103 int next_block_id_; | 123 int next_block_id_; |
104 | 124 |
105 DISALLOW_COPY_AND_ASSIGN(PowerPolicyController); | 125 DISALLOW_COPY_AND_ASSIGN(PowerPolicyController); |
106 }; | 126 }; |
107 | 127 |
108 } // namespace chromeos | 128 } // namespace chromeos |
109 | 129 |
110 #endif // CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_ | 130 #endif // CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_ |
OLD | NEW |