power_observer.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 PowerSuspendObserver {
  10. public:
  11. // Notification that the system is suspending.
  12. virtual void OnSuspend() {}
  13. // Notification that the system is resuming.
  14. virtual void OnResume() {}
  15. protected:
  16. virtual ~PowerSuspendObserver() = default;
  17. };
  18. class BASE_EXPORT PowerStateObserver {
  19. public:
  20. // Notification of a change in power status of the computer, such
  21. // as from switching between battery and A/C power.
  22. virtual void OnPowerStateChange(bool on_battery_power) = 0;
  23. protected:
  24. virtual ~PowerStateObserver() = default;
  25. };
  26. class BASE_EXPORT PowerThermalObserver {
  27. public:
  28. // Values to indicate the system's thermal states: from kNominal onwards to
  29. // kCritical they represent increasing SoC die temperatures, usually needing
  30. // disruptive actions by the system like e.g. turning on the fans (on systems
  31. // equipped with those) or reducing voltage and frequency (oftentimes
  32. // degrading overall responsiveness). The taxonomy is derived from MacOS (see
  33. // e.g. [1]) but applies to others e.g. Linux/ChromeOS.
  34. // [1]
  35. // https://developer.apple.com/library/archive/documentation/Performance/Conceptual/power_efficiency_guidelines_osx/RespondToThermalStateChanges.html
  36. // Attention: These values are persisted to logs. Entries should not be
  37. // renumbered and numeric values should never be reused. Keep in sync with
  38. // DeviceThermalState
  39. // in //tools/metrics/histograms/enums.xml.
  40. enum class DeviceThermalState {
  41. kUnknown = 0,
  42. kNominal = 1,
  43. kFair = 2,
  44. kSerious = 3,
  45. kCritical = 4,
  46. kMaxValue = kCritical,
  47. };
  48. // The maximum speed limit in the system.
  49. static constexpr int kSpeedLimitMax = 100;
  50. // Notification of a change in the thermal status of the system, such as
  51. // entering a critical temperature range. Depending on the severity, the SoC
  52. // or the OS might take steps to reduce said temperature e.g., throttling the
  53. // CPU or switching on the fans if available. API clients may react to the new
  54. // state by reducing expensive computing tasks (e.g. video encoding), or
  55. // notifying the user. The same |new_state| might be received repeatedly.
  56. // TODO(crbug.com/1071431): implemented on MacOS, extend to Linux/CrOs.
  57. virtual void OnThermalStateChange(DeviceThermalState new_state) = 0;
  58. // Notification of a change in the operating system's advertised speed limit
  59. // for CPUs in percent. Values below kSpeedLimitMax indicate that the system
  60. // is impairing processing power due to thermal management.
  61. virtual void OnSpeedLimitChange(int speed_limit) = 0;
  62. protected:
  63. virtual ~PowerThermalObserver() = default;
  64. };
  65. } // namespace base
  66. #endif // BASE_POWER_MONITOR_POWER_OBSERVER_H_