• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.base.power_monitor
28   // GENERATED_JAVA_PREFIX_TO_STRIP: k
29   enum class BatteryPowerStatus {
30     kUnknown = 0,
31     kBatteryPower = 1,
32     kExternalPower = 2,
33   };
34 
35   // Notification of a change in power status of the computer, such
36   // as from switching between battery and A/C power.
37   virtual void OnBatteryPowerStatusChange(
38       BatteryPowerStatus battery_power_status) = 0;
39 
40  protected:
41   virtual ~PowerStateObserver() = default;
42 };
43 
44 class BASE_EXPORT PowerThermalObserver {
45  public:
46   // Values to indicate the system's thermal states: from kNominal onwards to
47   // kCritical they represent increasing SoC die temperatures, usually needing
48   // disruptive actions by the system like e.g. turning on the fans (on systems
49   // equipped with those) or reducing voltage and frequency (oftentimes
50   // degrading overall responsiveness). The taxonomy is derived from MacOS (see
51   // e.g. [1]) but applies to others e.g. Linux/ChromeOS.
52   // [1]
53   // https://developer.apple.com/library/archive/documentation/Performance/Conceptual/power_efficiency_guidelines_osx/RespondToThermalStateChanges.html
54   // Attention: These values are persisted to logs. Entries should not be
55   // renumbered and numeric values should never be reused. Keep in sync with
56   // DeviceThermalState
57   // in //tools/metrics/histograms/enums.xml.
58   enum class DeviceThermalState {
59     kUnknown = 0,
60     kNominal = 1,
61     kFair = 2,
62     kSerious = 3,
63     kCritical = 4,
64     kMaxValue = kCritical,
65   };
66   // The maximum speed limit in the system.
67   static constexpr int kSpeedLimitMax = 100;
68 
69   // Notification of a change in the thermal status of the system, such as
70   // entering a critical temperature range. Depending on the severity, the SoC
71   // or the OS might take steps to reduce said temperature e.g., throttling the
72   // CPU or switching on the fans if available. API clients may react to the new
73   // state by reducing expensive computing tasks (e.g. video encoding), or
74   // notifying the user. The same |new_state| might be received repeatedly.
75   // TODO(crbug.com/1071431): implemented on MacOS, extend to Linux/CrOs.
76   virtual void OnThermalStateChange(DeviceThermalState new_state) = 0;
77 
78   // Notification of a change in the operating system's advertised speed limit
79   // for CPUs in percent. Values below kSpeedLimitMax indicate that the system
80   // is impairing processing power due to thermal management.
81   virtual void OnSpeedLimitChange(int speed_limit) = 0;
82 
83  protected:
84   virtual ~PowerThermalObserver() = default;
85 };
86 
87 }  // namespace base
88 
89 #endif  // BASE_POWER_MONITOR_POWER_OBSERVER_H_
90