1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/chromium/src/base/system_monitor_win.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,49 @@ 1.4 +// Copyright (c) 2008 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#include "base/system_monitor.h" 1.9 + 1.10 +namespace base { 1.11 + 1.12 +void SystemMonitor::ProcessWmPowerBroadcastMessage(int event_id) { 1.13 + PowerEvent power_event; 1.14 + switch (event_id) { 1.15 + case PBT_APMPOWERSTATUSCHANGE: // The power status changed. 1.16 + power_event = POWER_STATE_EVENT; 1.17 + break; 1.18 + case PBT_APMRESUMEAUTOMATIC: // Non-user initiated resume from suspend. 1.19 + case PBT_APMRESUMESUSPEND: // User initiated resume from suspend. 1.20 + power_event = RESUME_EVENT; 1.21 + break; 1.22 + case PBT_APMSUSPEND: // System has been suspended. 1.23 + power_event = SUSPEND_EVENT; 1.24 + break; 1.25 + default: 1.26 + return; 1.27 + 1.28 + // Other Power Events: 1.29 + // PBT_APMBATTERYLOW - removed in Vista. 1.30 + // PBT_APMOEMEVENT - removed in Vista. 1.31 + // PBT_APMQUERYSUSPEND - removed in Vista. 1.32 + // PBT_APMQUERYSUSPENDFAILED - removed in Vista. 1.33 + // PBT_APMRESUMECRITICAL - removed in Vista. 1.34 + // PBT_POWERSETTINGCHANGE - user changed the power settings. 1.35 + } 1.36 + ProcessPowerMessage(power_event); 1.37 +} 1.38 + 1.39 +// Function to query the system to see if it is currently running on 1.40 +// battery power. Returns true if running on battery. 1.41 +bool SystemMonitor::IsBatteryPower() { 1.42 + SYSTEM_POWER_STATUS status; 1.43 + if (!GetSystemPowerStatus(&status)) { 1.44 + CHROMIUM_LOG(ERROR) << "GetSystemPowerStatus failed: " << GetLastError(); 1.45 + return false; 1.46 + } 1.47 + return (status.ACLineStatus == 0); 1.48 +} 1.49 + 1.50 + 1.51 + 1.52 +} // namespace base