Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / chromeos / dbus / power_policy_controller.h
blob3d45769b3e8384e90f2b00b829d835466481ea69
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_
8 #include <map>
9 #include <string>
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"
19 namespace chromeos {
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 {
28 public:
29 // Note: Do not change these values; they are used by preferences.
30 enum Action {
31 ACTION_SUSPEND = 0,
32 ACTION_STOP_SESSION = 1,
33 ACTION_SHUT_DOWN = 2,
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()
62 // later.
63 int AddScreenBlock(const std::string& reason);
64 int AddSuspendBlock(const std::string& reason);
66 // Unregisters a request previously created via AddScreenBlock() or
67 // AddSuspendBlock().
68 void RemoveBlock(int id);
70 // DBusThreadManagerObserver implementation:
71 virtual void OnDBusThreadManagerDestroying(DBusThreadManager* manager)
72 OVERRIDE;
74 // PowerManagerClient::Observer implementation:
75 virtual void PowerManagerRestarted() OVERRIDE;
77 private:
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_|?
94 bool prefs_were_set_;
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().
103 int next_block_id_;
105 DISALLOW_COPY_AND_ASSIGN(PowerPolicyController);
108 } // namespace chromeos
110 #endif // CHROMEOS_DBUS_POWER_POLICY_CONTROLLER_H_