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 #include "base/power_monitor/power_monitor_source.h" 6 7 #include "base/notreached.h" 8 #include "base/power_monitor/power_monitor.h" 9 #include "base/power_monitor/power_observer.h" 10 #include "build/build_config.h" 11 12 namespace base { 13 14 PowerMonitorSource::PowerMonitorSource() = default; 15 PowerMonitorSource::~PowerMonitorSource() = default; 16 17 PowerThermalObserver::DeviceThermalState GetCurrentThermalState() const18PowerMonitorSource::GetCurrentThermalState() const { 19 return PowerThermalObserver::DeviceThermalState::kUnknown; 20 } 21 GetInitialSpeedLimit() const22int PowerMonitorSource::GetInitialSpeedLimit() const { 23 return PowerThermalObserver::kSpeedLimitMax; 24 } 25 SetCurrentThermalState(PowerThermalObserver::DeviceThermalState state)26void PowerMonitorSource::SetCurrentThermalState( 27 PowerThermalObserver::DeviceThermalState state) {} 28 29 #if BUILDFLAG(IS_ANDROID) GetRemainingBatteryCapacity() const30int PowerMonitorSource::GetRemainingBatteryCapacity() const { 31 return 0; 32 } 33 #endif // BUILDFLAG(IS_ANDROID) 34 35 // static ProcessPowerEvent(PowerEvent event_id)36void PowerMonitorSource::ProcessPowerEvent(PowerEvent event_id) { 37 auto* power_monitor = base::PowerMonitor::GetInstance(); 38 if (!power_monitor->IsInitialized()) { 39 return; 40 } 41 42 switch (event_id) { 43 case POWER_STATE_EVENT: 44 power_monitor->NotifyPowerStateChange( 45 power_monitor->Source()->GetBatteryPowerStatus()); 46 break; 47 case RESUME_EVENT: 48 power_monitor->NotifyResume(); 49 break; 50 case SUSPEND_EVENT: 51 power_monitor->NotifySuspend(); 52 break; 53 } 54 } 55 56 // static ProcessThermalEvent(PowerThermalObserver::DeviceThermalState new_thermal_state)57void PowerMonitorSource::ProcessThermalEvent( 58 PowerThermalObserver::DeviceThermalState new_thermal_state) { 59 if (auto* power_monitor = base::PowerMonitor::GetInstance(); 60 power_monitor->IsInitialized()) { 61 power_monitor->NotifyThermalStateChange(new_thermal_state); 62 } 63 } 64 65 // static ProcessSpeedLimitEvent(int speed_limit)66void PowerMonitorSource::ProcessSpeedLimitEvent(int speed_limit) { 67 if (auto* power_monitor = base::PowerMonitor::GetInstance(); 68 power_monitor->IsInitialized()) { 69 power_monitor->NotifySpeedLimitChange(speed_limit); 70 } 71 } 72 73 // static DeviceThermalStateToString(PowerThermalObserver::DeviceThermalState state)74const char* PowerMonitorSource::DeviceThermalStateToString( 75 PowerThermalObserver::DeviceThermalState state) { 76 switch (state) { 77 case PowerThermalObserver::DeviceThermalState::kUnknown: 78 return "Unknown"; 79 case PowerThermalObserver::DeviceThermalState::kNominal: 80 return "Nominal"; 81 case PowerThermalObserver::DeviceThermalState::kFair: 82 return "Fair"; 83 case PowerThermalObserver::DeviceThermalState::kSerious: 84 return "Serious"; 85 case PowerThermalObserver::DeviceThermalState::kCritical: 86 return "Critical"; 87 } 88 NOTREACHED(); 89 } 90 91 } // namespace base 92