Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: chromeos/dbus/power_policy_controller.h

Issue 14134004: chromeos: Move default power management policy into Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: change char pointers in PrefNames to std::strings Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_member.h"
13 #include "base/prefs/pref_service.h" 14 #include "base/prefs/pref_service.h"
bartfab (slow) 2013/04/17 11:51:12 Nit: It would be sufficient to forward-declare Pol
Daniel Erat 2013/04/18 03:59:16 n/a
14 #include "chromeos/chromeos_export.h" 15 #include "chromeos/chromeos_export.h"
15 #include "chromeos/dbus/dbus_thread_manager_observer.h" 16 #include "chromeos/dbus/dbus_thread_manager_observer.h"
16 #include "chromeos/dbus/power_manager/policy.pb.h" 17 #include "chromeos/dbus/power_manager/policy.pb.h"
17 #include "chromeos/dbus/power_manager_client.h" 18 #include "chromeos/dbus/power_manager_client.h"
18 19
19 namespace chromeos { 20 namespace chromeos {
20 21
21 class DBusThreadManager; 22 class DBusThreadManager;
22 23
23 // PowerPolicyController is responsible for sending Chrome's assorted power 24 // PowerPolicyController is responsible for sending Chrome's assorted power
24 // management preferences to the Chrome OS power manager. 25 // management preferences to the Chrome OS power manager.
25 class CHROMEOS_EXPORT PowerPolicyController 26 class CHROMEOS_EXPORT PowerPolicyController
26 : public DBusThreadManagerObserver, 27 : public DBusThreadManagerObserver,
27 public PowerManagerClient::Observer { 28 public PowerManagerClient::Observer {
28 public: 29 public:
29 // Note: Do not change these values; they are used by preferences. 30 // Note: Do not change these values; they are used by preferences.
30 enum Action { 31 enum Action {
31 ACTION_SUSPEND = 0, 32 ACTION_SUSPEND = 0,
32 ACTION_STOP_SESSION = 1, 33 ACTION_STOP_SESSION = 1,
33 ACTION_SHUT_DOWN = 2, 34 ACTION_SHUT_DOWN = 2,
34 ACTION_DO_NOTHING = 3, 35 ACTION_DO_NOTHING = 3,
35 }; 36 };
36 37
38 // Names of various power-management-related preferences. Used to
39 // initialize |*_pref_| members.
40 struct PrefNames {
41 std::string ac_screen_dim_delay_ms;
42 std::string ac_screen_off_delay_ms;
43 std::string ac_screen_lock_delay_ms;
44 std::string ac_idle_warning_delay_ms;
45 std::string ac_idle_delay_ms;
46 std::string battery_screen_dim_delay_ms;
47 std::string battery_screen_off_delay_ms;
48 std::string battery_screen_lock_delay_ms;
49 std::string battery_idle_warning_delay_ms;
50 std::string battery_idle_delay_ms;
51 std::string idle_action;
52 std::string lid_closed_action;
53 std::string use_audio_activity;
54 std::string use_video_activity;
55 std::string enable_screen_lock;
56 std::string presentation_idle_delay_factor;
57 };
58
37 PowerPolicyController(DBusThreadManager* manager, PowerManagerClient* client); 59 PowerPolicyController(DBusThreadManager* manager, PowerManagerClient* client);
38 virtual ~PowerPolicyController(); 60 virtual ~PowerPolicyController();
39 61
40 // Sends an updated policy to the power manager based on the current 62 // Initializes |*_prefs_| members.
41 // values of the passed-in prefs. 63 void InitPrefs(PrefService* pref_service, const PrefNames& pref_names);
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 64
59 // Registers a request to temporarily prevent the screen from getting 65 // Registers a request to temporarily prevent the screen from getting
60 // dimmed or turned off or the system from suspending in response to user 66 // 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() 67 // inactivity. Returns a unique ID that can be passed to RemoveBlock()
62 // later. 68 // later.
63 int AddScreenBlock(const std::string& reason); 69 int AddScreenBlock(const std::string& reason);
64 int AddSuspendBlock(const std::string& reason); 70 int AddSuspendBlock(const std::string& reason);
65 71
66 // Unregisters a request previously created via AddScreenBlock() or 72 // Unregisters a request previously created via AddScreenBlock() or
67 // AddSuspendBlock(). 73 // AddSuspendBlock().
68 void RemoveBlock(int id); 74 void RemoveBlock(int id);
69 75
70 // DBusThreadManagerObserver implementation: 76 // DBusThreadManagerObserver implementation:
71 virtual void OnDBusThreadManagerDestroying(DBusThreadManager* manager) 77 virtual void OnDBusThreadManagerDestroying(DBusThreadManager* manager)
72 OVERRIDE; 78 OVERRIDE;
73 79
74 // PowerManagerClient::Observer implementation: 80 // PowerManagerClient::Observer implementation:
75 virtual void PowerManagerRestarted() OVERRIDE; 81 virtual void PowerManagerRestarted() OVERRIDE;
76 82
77 private: 83 private:
78 typedef std::map<int, std::string> BlockMap; 84 typedef std::map<int, std::string> BlockMap;
79 85
86 // Called when |*_pref_| members' values change.
87 void OnPrefChanged(const std::string& pref_name);
88
80 // Sends a policy based on |prefs_policy_| to the power manager. 89 // Sends a policy based on |prefs_policy_| to the power manager.
81 void SendCurrentPolicy(); 90 void SendCurrentPolicy();
82 91
83 // Sends an empty policy to the power manager to reset its configuration. 92 // Sends an empty policy to the power manager to reset its configuration.
84 void SendEmptyPolicy(); 93 void SendEmptyPolicy();
85 94
86 DBusThreadManager* manager_; // not owned 95 DBusThreadManager* manager_; // not owned
87 PowerManagerClient* client_; // not owned 96 PowerManagerClient* client_; // not owned
88 97
89 // Policy specified by the prefs that were last passed to 98 // NULL until InitPrefs() has been called.
90 // UpdatePolicyFromPrefs(). 99 PrefService* pref_service_;
91 power_manager::PowerManagementPolicy prefs_policy_; 100 PrefNames pref_names_;
bartfab (slow) 2013/04/17 11:51:12 I don't think managing the PrefMembers in this cla
Daniel Erat 2013/04/17 13:52:13 What's your preference for how this should work in
92 101
93 // Are one or more fields set in |prefs_policy_|? 102 // Used to watch for changes to prefs.
94 bool prefs_were_set_; 103 IntegerPrefMember ac_screen_dim_delay_ms_pref_;
104 IntegerPrefMember ac_screen_off_delay_ms_pref_;
105 IntegerPrefMember ac_screen_lock_delay_ms_pref_;
106 IntegerPrefMember ac_idle_warning_delay_ms_pref_;
107 IntegerPrefMember ac_idle_delay_ms_pref_;
108 IntegerPrefMember battery_screen_dim_delay_ms_pref_;
109 IntegerPrefMember battery_screen_off_delay_ms_pref_;
110 IntegerPrefMember battery_screen_lock_delay_ms_pref_;
111 IntegerPrefMember battery_idle_warning_delay_ms_pref_;
112 IntegerPrefMember battery_idle_delay_ms_pref_;
113 IntegerPrefMember idle_action_pref_;
114 IntegerPrefMember lid_closed_action_pref_;
115 BooleanPrefMember use_audio_activity_pref_;
116 BooleanPrefMember use_video_activity_pref_;
117 BooleanPrefMember enable_screen_lock_pref_;
118 DoublePrefMember presentation_idle_delay_factor_pref_;
95 119
96 // Maps from an ID representing a request to prevent the screen from 120 // 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 121 // getting dimmed or turned off or to prevent the system from suspending
98 // to the reason for the request. 122 // to the reason for the request.
99 BlockMap screen_blocks_; 123 BlockMap screen_blocks_;
100 BlockMap suspend_blocks_; 124 BlockMap suspend_blocks_;
101 125
102 // Next ID to be used by AddScreenBlock() or AddSuspendBlock(). 126 // Next ID to be used by AddScreenBlock() or AddSuspendBlock().
103 int next_block_id_; 127 int next_block_id_;
104 128
129 base::WeakPtrFactory<PowerPolicyController> weak_ptr_factory_;
bartfab (slow) 2013/04/17 11:51:12 Nit: Move the #include "base/memory/weak_ptr.h" fr
Daniel Erat 2013/04/18 03:59:16 n/a
130
105 DISALLOW_COPY_AND_ASSIGN(PowerPolicyController); 131 DISALLOW_COPY_AND_ASSIGN(PowerPolicyController);
106 }; 132 };
107 133
108 } // namespace chromeos 134 } // namespace chromeos
109 135
110 #endif // CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_ 136 #endif // CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698