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

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: apply review feedback 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
« no previous file with comments | « chrome/browser/chromeos/preferences.cc ('k') | chromeos/dbus/power_policy_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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
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;
44 int ac_idle_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;
50 Action idle_action;
51 Action lid_closed_action;
52 bool use_audio_activity;
53 bool use_video_activity;
54 bool enable_screen_lock;
55 double presentation_idle_delay_factor;
56 };
57
58 // Returns a string describing |policy|. Useful for tests.
59 static std::string GetPolicyDebugString(
60 const power_manager::PowerManagementPolicy& policy);
61
37 PowerPolicyController(DBusThreadManager* manager, PowerManagerClient* client); 62 PowerPolicyController(DBusThreadManager* manager, PowerManagerClient* client);
38 virtual ~PowerPolicyController(); 63 virtual ~PowerPolicyController();
39 64
40 // Sends an updated policy to the power manager based on the current 65 // Updates |prefs_policy_| with |values| and sends an updated policy.
41 // values of the passed-in prefs. 66 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 67
59 // Registers a request to temporarily prevent the screen from getting 68 // Registers a request to temporarily prevent the screen from getting
60 // dimmed or turned off or the system from suspending in response to user 69 // 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() 70 // inactivity and sends an updated policy. Returns a unique ID that can
62 // later. 71 // be passed to RemoveBlock() later.
63 int AddScreenBlock(const std::string& reason); 72 int AddScreenBlock(const std::string& reason);
64 int AddSuspendBlock(const std::string& reason); 73 int AddSuspendBlock(const std::string& reason);
65 74
66 // Unregisters a request previously created via AddScreenBlock() or 75 // Unregisters a request previously created via AddScreenBlock() or
67 // AddSuspendBlock(). 76 // AddSuspendBlock() and sends an updated policy.
68 void RemoveBlock(int id); 77 void RemoveBlock(int id);
69 78
70 // DBusThreadManagerObserver implementation: 79 // DBusThreadManagerObserver implementation:
71 virtual void OnDBusThreadManagerDestroying(DBusThreadManager* manager) 80 virtual void OnDBusThreadManagerDestroying(DBusThreadManager* manager)
72 OVERRIDE; 81 OVERRIDE;
73 82
74 // PowerManagerClient::Observer implementation: 83 // PowerManagerClient::Observer implementation:
75 virtual void PowerManagerRestarted() OVERRIDE; 84 virtual void PowerManagerRestarted() OVERRIDE;
76 85
77 private: 86 private:
78 typedef std::map<int, std::string> BlockMap; 87 typedef std::map<int, std::string> BlockMap;
79 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 // Policy derived from values passed to ApplyPrefs().
90 // UpdatePolicyFromPrefs().
91 power_manager::PowerManagementPolicy prefs_policy_; 99 power_manager::PowerManagementPolicy prefs_policy_;
92 100
93 // Are one or more fields set in |prefs_policy_|? 101 // Was ApplyPrefs() called?
94 bool prefs_were_set_; 102 bool prefs_were_set_;
95 103
96 // Maps from an ID representing a request to prevent the screen from 104 // 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 105 // getting dimmed or turned off or to prevent the system from suspending
98 // to the reason for the request. 106 // to the reason for the request.
99 BlockMap screen_blocks_; 107 BlockMap screen_blocks_;
100 BlockMap suspend_blocks_; 108 BlockMap suspend_blocks_;
101 109
102 // Next ID to be used by AddScreenBlock() or AddSuspendBlock(). 110 // Next ID to be used by AddScreenBlock() or AddSuspendBlock().
103 int next_block_id_; 111 int next_block_id_;
104 112
105 DISALLOW_COPY_AND_ASSIGN(PowerPolicyController); 113 DISALLOW_COPY_AND_ASSIGN(PowerPolicyController);
106 }; 114 };
107 115
108 } // namespace chromeos 116 } // namespace chromeos
109 117
110 #endif // CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_ 118 #endif // CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/preferences.cc ('k') | chromeos/dbus/power_policy_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698