xref: /aosp_15_r20/external/cronet/base/power_monitor/power_monitor_device_source_chromeos.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2014 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 #include "base/power_monitor/power_monitor.h"
6 #include "base/power_monitor/power_monitor_device_source.h"
7 #include "base/power_monitor/power_monitor_source.h"
8 
9 namespace base {
10 
11 namespace {
12 
13 // The most-recently-seen power source.
14 bool g_on_battery = false;
15 
16 }  // namespace
17 
18 // static
SetPowerSource(bool on_battery)19 void PowerMonitorDeviceSource::SetPowerSource(bool on_battery) {
20   if (on_battery != g_on_battery) {
21     g_on_battery = on_battery;
22     ProcessPowerEvent(POWER_STATE_EVENT);
23   }
24 }
25 
26 // static
HandleSystemSuspending()27 void PowerMonitorDeviceSource::HandleSystemSuspending() {
28   ProcessPowerEvent(SUSPEND_EVENT);
29 }
30 
31 // static
HandleSystemResumed()32 void PowerMonitorDeviceSource::HandleSystemResumed() {
33   ProcessPowerEvent(RESUME_EVENT);
34 }
35 
IsOnBatteryPower()36 bool PowerMonitorDeviceSource::IsOnBatteryPower() {
37   return g_on_battery;
38 }
39 
40 // static
ThermalEventReceived(PowerThermalObserver::DeviceThermalState state)41 void PowerMonitorDeviceSource::ThermalEventReceived(
42     PowerThermalObserver::DeviceThermalState state) {
43   if (!PowerMonitor::IsInitialized()) {
44     PowerMonitor::Initialize(std::make_unique<PowerMonitorDeviceSource>());
45   }
46   PowerMonitor::SetCurrentThermalState(state);
47 
48   ProcessThermalEvent(state);
49 }
50 
51 PowerThermalObserver::DeviceThermalState
GetCurrentThermalState()52 PowerMonitorDeviceSource::GetCurrentThermalState() {
53   return current_thermal_state_;
54 }
55 
SetCurrentThermalState(PowerThermalObserver::DeviceThermalState state)56 void PowerMonitorDeviceSource::SetCurrentThermalState(
57     PowerThermalObserver::DeviceThermalState state) {
58   current_thermal_state_ = state;
59 }
60 
61 }  // namespace base
62