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

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

Issue 2853113004: chromeos: Add settings to control power management prefs. (Closed)
Patch Set: re-add some code Created 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/settings/chromeos/device_power_handler.h
diff --git a/chrome/browser/ui/webui/settings/chromeos/device_power_handler.h b/chrome/browser/ui/webui/settings/chromeos/device_power_handler.h
index eaaf0cc9a58aab050e582f7552e5806484e53255..ab67365608cc846cfa47ea379087d9a45e3a1d1e 100644
--- a/chrome/browser/ui/webui/settings/chromeos/device_power_handler.h
+++ b/chrome/browser/ui/webui/settings/chromeos/device_power_handler.h
@@ -5,12 +5,17 @@
#ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_DEVICE_POWER_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_DEVICE_POWER_HANDLER_H_
+#include <memory>
+
#include "ash/system/power/power_status.h"
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "base/strings/string16.h"
#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"
+class PrefChangeRegistrar;
+class PrefService;
+
namespace base {
class ListValue;
}
@@ -22,7 +27,7 @@ namespace settings {
class PowerHandler : public ::settings::SettingsPageUIHandler,
public ash::PowerStatus::Observer {
public:
- PowerHandler();
+ explicit PowerHandler(PrefService* prefs);
~PowerHandler() override;
// SettingsPageUIHandler implementation.
@@ -34,22 +39,62 @@ class PowerHandler : public ::settings::SettingsPageUIHandler,
void OnPowerStatusChanged() override;
private:
+ // Idle behaviors presented in the UI. These are mapped to preferences by
+ // HandleSetIdleBehavior(). Values are shared with JS.
+ enum class IdleBehavior {
+ 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
+ DISPLAY_OFF_STAY_AWAKE = 1,
+ DISPLAY_ON = 2,
+ };
+
+ // Lid-closed behaviors presented in the UI. These are mapped to preferences
+ // by HandleSetLidClosedBehavior(). Values are shared with JS.
+ enum class LidClosedBehavior {
+ SLEEP = 0,
+ STAY_AWAKE = 1,
+ };
+
// Handler to request updating the power status.
void HandleUpdatePowerStatus(const base::ListValue* args);
// Handler to change the power source.
void HandleSetPowerSource(const base::ListValue* args);
+ // Handler to request the current power management settings. Just calls
+ // SendPowerManagementSettings().
+ void HandleRequestPowerManagementSettings(const base::ListValue* args);
+
+ // Handlers to change the idle and lid-closed behaviors.
+ void HandleSetIdleBehavior(const base::ListValue* args);
+ void HandleSetLidClosedBehavior(const base::ListValue* args);
+
// Updates the UI with the current battery status.
void SendBatteryStatus();
// Updates the UI with a list of available dual-role power sources.
void SendPowerSources();
- ash::PowerStatus* power_status_;
+ // Updates the UI to display the current power management settings. If the
+ // settings didn't change since the previous call, nothing is sent unless
+ // |force| is true.
+ void SendPowerManagementSettings(bool force);
+
+ PrefService* prefs_; // Not owned.
+ ash::PowerStatus* power_status_; // Not owned.
+
+ // Used to watch power management prefs for changes so the UI can be notified.
+ std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
ScopedObserver<ash::PowerStatus, PowerHandler> power_observer_;
+ // Last values sent by SendPowerManagementSettings(), cached here so
+ // SendPowerManagementSettings() can avoid spamming the UI after this class
+ // changes multiple prefs at once.
+ IdleBehavior last_idle_behavior_ = IdleBehavior::DISPLAY_OFF_SLEEP;
+ LidClosedBehavior last_lid_closed_behavior_ = LidClosedBehavior::SLEEP;
+ bool last_idle_managed_ = false;
+ bool last_lid_closed_managed_ = false;
+
DISALLOW_COPY_AND_ASSIGN(PowerHandler);
};

Powered by Google App Engine
This is Rietveld 408576698