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
3 // found in the LICENSE file.
5 #ifndef CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_
6 #define CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/prefs/pref_service.h"
14 #include "chromeos/chromeos_export.h"
15 #include "chromeos/dbus/dbus_thread_manager_observer.h"
16 #include "chromeos/dbus/power_manager/policy.pb.h"
17 #include "chromeos/dbus/power_manager_client.h"
21 class DBusThreadManager
;
23 // PowerPolicyController is responsible for sending Chrome's assorted power
24 // management preferences to the Chrome OS power manager.
25 class CHROMEOS_EXPORT PowerPolicyController
26 : public DBusThreadManagerObserver
,
27 public PowerManagerClient::Observer
{
29 // Note: Do not change these values; they are used by preferences.
32 ACTION_STOP_SESSION
= 1,
34 ACTION_DO_NOTHING
= 3,
37 PowerPolicyController(DBusThreadManager
* manager
, PowerManagerClient
* client
);
38 virtual ~PowerPolicyController();
40 // Sends an updated policy to the power manager based on the current
41 // values of the passed-in prefs.
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
);
59 // Registers a request to temporarily prevent the screen from getting
60 // 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()
63 int AddScreenBlock(const std::string
& reason
);
64 int AddSuspendBlock(const std::string
& reason
);
66 // Unregisters a request previously created via AddScreenBlock() or
68 void RemoveBlock(int id
);
70 // DBusThreadManagerObserver implementation:
71 virtual void OnDBusThreadManagerDestroying(DBusThreadManager
* manager
)
74 // PowerManagerClient::Observer implementation:
75 virtual void PowerManagerRestarted() OVERRIDE
;
78 typedef std::map
<int, std::string
> BlockMap
;
80 // Sends a policy based on |prefs_policy_| to the power manager.
81 void SendCurrentPolicy();
83 // Sends an empty policy to the power manager to reset its configuration.
84 void SendEmptyPolicy();
86 DBusThreadManager
* manager_
; // not owned
87 PowerManagerClient
* client_
; // not owned
89 // Policy specified by the prefs that were last passed to
90 // UpdatePolicyFromPrefs().
91 power_manager::PowerManagementPolicy prefs_policy_
;
93 // Are one or more fields set in |prefs_policy_|?
96 // 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
98 // to the reason for the request.
99 BlockMap screen_blocks_
;
100 BlockMap suspend_blocks_
;
102 // Next ID to be used by AddScreenBlock() or AddSuspendBlock().
105 DISALLOW_COPY_AND_ASSIGN(PowerPolicyController
);
108 } // namespace chromeos
110 #endif // CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_