power_monitor_device_source_chromeos.cc 1.5 KB

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