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