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

Side by Side Diff: chrome/browser/ui/webui/settings/chromeos/device_power_handler.h

Issue 2853113004: chromeos: Add settings to control power management prefs. (Closed)
Patch Set: address review comments and display more lid-closed actions Created 3 years, 7 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
OLDNEW
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"
15 #include "chromeos/dbus/power_policy_controller.h"
16
17 class PrefChangeRegistrar;
18 class PrefService;
13 19
14 namespace base { 20 namespace base {
15 class ListValue; 21 class ListValue;
16 } 22 }
17 23
18 namespace chromeos { 24 namespace chromeos {
19 namespace settings { 25 namespace settings {
20 26
21 // Chrome OS battery status and power settings handler. 27 // Chrome OS battery status and power settings handler.
22 class PowerHandler : public ::settings::SettingsPageUIHandler, 28 class PowerHandler : public ::settings::SettingsPageUIHandler,
23 public ash::PowerStatus::Observer { 29 public ash::PowerStatus::Observer {
24 public: 30 public:
25 PowerHandler(); 31 explicit PowerHandler(PrefService* prefs);
26 ~PowerHandler() override; 32 ~PowerHandler() override;
27 33
28 // SettingsPageUIHandler implementation. 34 // SettingsPageUIHandler implementation.
29 void RegisterMessages() override; 35 void RegisterMessages() override;
30 void OnJavascriptAllowed() override; 36 void OnJavascriptAllowed() override;
31 void OnJavascriptDisallowed() override; 37 void OnJavascriptDisallowed() override;
32 38
33 // ash::PowerStatus::Observer implementation. 39 // ash::PowerStatus::Observer implementation.
34 void OnPowerStatusChanged() override; 40 void OnPowerStatusChanged() override;
35 41
36 private: 42 private:
43 // Idle behaviors presented in the UI. These are mapped to preferences by
44 // HandleSetIdleBehavior(). Values are shared with JS.
45 enum class IdleBehavior {
46 DISPLAY_OFF_SLEEP = 0,
47 DISPLAY_OFF_STAY_AWAKE = 1,
48 DISPLAY_ON = 2,
49 OTHER = 3,
50 };
51
37 // Handler to request updating the power status. 52 // Handler to request updating the power status.
38 void HandleUpdatePowerStatus(const base::ListValue* args); 53 void HandleUpdatePowerStatus(const base::ListValue* args);
39 54
40 // Handler to change the power source. 55 // Handler to change the power source.
41 void HandleSetPowerSource(const base::ListValue* args); 56 void HandleSetPowerSource(const base::ListValue* args);
42 57
58 // Handler to request the current power management settings. Just calls
59 // SendPowerManagementSettings().
60 void HandleRequestPowerManagementSettings(const base::ListValue* args);
61
62 // Handlers to change the idle and lid-closed behaviors.
63 void HandleSetIdleBehavior(const base::ListValue* args);
64 void HandleSetLidClosedBehavior(const base::ListValue* args);
65
43 // Updates the UI with the current battery status. 66 // Updates the UI with the current battery status.
44 void SendBatteryStatus(); 67 void SendBatteryStatus();
45 68
46 // Updates the UI with a list of available dual-role power sources. 69 // Updates the UI with a list of available dual-role power sources.
47 void SendPowerSources(); 70 void SendPowerSources();
48 71
49 ash::PowerStatus* power_status_; 72 // Updates the UI to display the current power management settings. If the
73 // settings didn't change since the previous call, nothing is sent unless
74 // |force| is true.
75 void SendPowerManagementSettings(bool force);
76
77 PrefService* prefs_; // Not owned.
78 ash::PowerStatus* power_status_; // Not owned.
79
80 // Used to watch power management prefs for changes so the UI can be notified.
81 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
50 82
51 ScopedObserver<ash::PowerStatus, PowerHandler> power_observer_; 83 ScopedObserver<ash::PowerStatus, PowerHandler> power_observer_;
52 84
85 // Last values sent by SendPowerManagementSettings(), cached here so
86 // SendPowerManagementSettings() can avoid spamming the UI after this class
87 // changes multiple prefs at once.
88 IdleBehavior last_idle_behavior_ = IdleBehavior::DISPLAY_OFF_SLEEP;
89 chromeos::PowerPolicyController::Action last_lid_closed_behavior_ =
90 chromeos::PowerPolicyController::ACTION_SUSPEND;
91 bool last_idle_managed_ = false;
92 bool last_lid_closed_managed_ = false;
93
53 DISALLOW_COPY_AND_ASSIGN(PowerHandler); 94 DISALLOW_COPY_AND_ASSIGN(PowerHandler);
54 }; 95 };
55 96
56 } // namespace settings 97 } // namespace settings
57 } // namespace chromeos 98 } // namespace chromeos
58 99
59 #endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_DEVICE_POWER_HANDLER_H_ 100 #endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_DEVICE_POWER_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698