OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_DEVICE_POWER_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_DEVICE_POWER_HANDLER_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_DEVICE_POWER_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_DEVICE_POWER_HANDLER_H_ |
7 | 7 |
8 #include <memory> | |
9 | |
8 #include "ash/system/power/power_status.h" | 10 #include "ash/system/power/power_status.h" |
9 #include "base/macros.h" | 11 #include "base/macros.h" |
10 #include "base/scoped_observer.h" | 12 #include "base/scoped_observer.h" |
11 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
12 #include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h" | 14 #include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h" |
13 | 15 |
16 class PrefChangeRegistrar; | |
17 class PrefService; | |
18 | |
14 namespace base { | 19 namespace base { |
15 class ListValue; | 20 class ListValue; |
16 } | 21 } |
17 | 22 |
18 namespace chromeos { | 23 namespace chromeos { |
19 namespace settings { | 24 namespace settings { |
20 | 25 |
21 // Chrome OS battery status and power settings handler. | 26 // Chrome OS battery status and power settings handler. |
22 class PowerHandler : public ::settings::SettingsPageUIHandler, | 27 class PowerHandler : public ::settings::SettingsPageUIHandler, |
23 public ash::PowerStatus::Observer { | 28 public ash::PowerStatus::Observer { |
24 public: | 29 public: |
25 PowerHandler(); | 30 explicit PowerHandler(PrefService* prefs); |
26 ~PowerHandler() override; | 31 ~PowerHandler() override; |
27 | 32 |
28 // SettingsPageUIHandler implementation. | 33 // SettingsPageUIHandler implementation. |
29 void RegisterMessages() override; | 34 void RegisterMessages() override; |
30 void OnJavascriptAllowed() override; | 35 void OnJavascriptAllowed() override; |
31 void OnJavascriptDisallowed() override; | 36 void OnJavascriptDisallowed() override; |
32 | 37 |
33 // ash::PowerStatus::Observer implementation. | 38 // ash::PowerStatus::Observer implementation. |
34 void OnPowerStatusChanged() override; | 39 void OnPowerStatusChanged() override; |
35 | 40 |
36 private: | 41 private: |
42 // Idle behaviors presented in the UI. These are mapped to preferences by | |
43 // HandleSetIdleBehavior(). Values are shared with JS. | |
44 enum class IdleBehavior { | |
45 DISPLAY_OFF_SLEEP = 0, | |
michaelpg
2017/05/04 17:36:26
Do these have to be defined in the .h file? (versu
Daniel Erat
2017/05/06 00:15:48
i've shuffled this around a bit.
LidClosedBehavio
| |
46 DISPLAY_OFF_STAY_AWAKE = 1, | |
47 DISPLAY_ON = 2, | |
48 }; | |
49 | |
50 // Lid-closed behaviors presented in the UI. These are mapped to preferences | |
51 // by HandleSetLidClosedBehavior(). Values are shared with JS. | |
52 enum class LidClosedBehavior { | |
53 SLEEP = 0, | |
54 STAY_AWAKE = 1, | |
55 }; | |
56 | |
37 // Handler to request updating the power status. | 57 // Handler to request updating the power status. |
38 void HandleUpdatePowerStatus(const base::ListValue* args); | 58 void HandleUpdatePowerStatus(const base::ListValue* args); |
39 | 59 |
40 // Handler to change the power source. | 60 // Handler to change the power source. |
41 void HandleSetPowerSource(const base::ListValue* args); | 61 void HandleSetPowerSource(const base::ListValue* args); |
42 | 62 |
63 // Handler to request the current power management settings. Just calls | |
64 // SendPowerManagementSettings(). | |
65 void HandleRequestPowerManagementSettings(const base::ListValue* args); | |
66 | |
67 // Handlers to change the idle and lid-closed behaviors. | |
68 void HandleSetIdleBehavior(const base::ListValue* args); | |
69 void HandleSetLidClosedBehavior(const base::ListValue* args); | |
70 | |
43 // Updates the UI with the current battery status. | 71 // Updates the UI with the current battery status. |
44 void SendBatteryStatus(); | 72 void SendBatteryStatus(); |
45 | 73 |
46 // Updates the UI with a list of available dual-role power sources. | 74 // Updates the UI with a list of available dual-role power sources. |
47 void SendPowerSources(); | 75 void SendPowerSources(); |
48 | 76 |
49 ash::PowerStatus* power_status_; | 77 // Updates the UI to display the current power management settings. If the |
78 // settings didn't change since the previous call, nothing is sent unless | |
79 // |force| is true. | |
80 void SendPowerManagementSettings(bool force); | |
81 | |
82 PrefService* prefs_; // Not owned. | |
83 ash::PowerStatus* power_status_; // Not owned. | |
84 | |
85 // Used to watch power management prefs for changes so the UI can be notified. | |
86 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; | |
50 | 87 |
51 ScopedObserver<ash::PowerStatus, PowerHandler> power_observer_; | 88 ScopedObserver<ash::PowerStatus, PowerHandler> power_observer_; |
52 | 89 |
90 // Last values sent by SendPowerManagementSettings(), cached here so | |
91 // SendPowerManagementSettings() can avoid spamming the UI after this class | |
92 // changes multiple prefs at once. | |
93 IdleBehavior last_idle_behavior_ = IdleBehavior::DISPLAY_OFF_SLEEP; | |
94 LidClosedBehavior last_lid_closed_behavior_ = LidClosedBehavior::SLEEP; | |
95 bool last_idle_managed_ = false; | |
96 bool last_lid_closed_managed_ = false; | |
97 | |
53 DISALLOW_COPY_AND_ASSIGN(PowerHandler); | 98 DISALLOW_COPY_AND_ASSIGN(PowerHandler); |
54 }; | 99 }; |
55 | 100 |
56 } // namespace settings | 101 } // namespace settings |
57 } // namespace chromeos | 102 } // namespace chromeos |
58 | 103 |
59 #endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_DEVICE_POWER_HANDLER_H_ | 104 #endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_DEVICE_POWER_HANDLER_H_ |
OLD | NEW |