power_observer.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 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.
  4. #ifndef BASE_POWER_MONITOR_POWER_OBSERVER_H_
  5. #define BASE_POWER_MONITOR_POWER_OBSERVER_H_
  6. #include "base/base_export.h"
  7. #include "base/compiler_specific.h"
  8. namespace base {
  9. class BASE_EXPORT PowerObserver {
  10. public:
  11. // Values to indicate the system's thermal states: from kNominal onwards to
  12. // kCritical they represent increasing SoC die temperatures, usually needing
  13. // disruptive actions by the system like e.g. turning on the fans (on systems
  14. // equipped with those) or reducing voltage and frequency (oftentimes
  15. // degrading overall responsiveness). The taxonomy is derived from MacOS (see
  16. // e.g. [1]) but applies to others e.g. Linux/ChromeOS.
  17. // [1] https://developer.apple.com/library/archive/documentation/Performance/Conceptual/power_efficiency_guidelines_osx/RespondToThermalStateChanges.html
  18. enum class DeviceThermalState {
  19. kUnknown,
  20. kNominal,
  21. kFair,
  22. kSerious,
  23. kCritical,
  24. };
  25. // Notification of a change in power status of the computer, such
  26. // as from switching between battery and A/C power.
  27. virtual void OnPowerStateChange(bool on_battery_power) {}
  28. // Notification that the system is suspending.
  29. virtual void OnSuspend() {}
  30. // Notification that the system is resuming.
  31. virtual void OnResume() {}
  32. // Notification of a change in the thermal status of the system, such as
  33. // entering a critical temperature range. Depending on the severity, the SoC
  34. // or the OS might take steps to reduce said temperature e.g., throttling the
  35. // CPU or switching on the fans if available. API clients may react to the new
  36. // state by reducing expensive computing tasks (e.g. video encoding), or
  37. // notifying the user. The same |new_state| might be received repeatedly.
  38. // TODO(crbug.com/1071431): implemented on MacOS, extend to Linux/CrOs.
  39. virtual void OnThermalStateChange(DeviceThermalState new_state) {}
  40. protected:
  41. virtual ~PowerObserver() = default;
  42. };
  43. } // namespace base
  44. #endif // BASE_POWER_MONITOR_POWER_OBSERVER_H_