WebKit Update 61491:61498.
[chromium-blink-merge.git] / app / system_monitor_win.cc
blobc9347dc45e69db07d62198e4bb87560f8573efc6
1 // Copyright (c) 2009 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.
5 #include "app/system_monitor.h"
7 void SystemMonitor::ProcessWmPowerBroadcastMessage(int event_id) {
8 PowerEvent power_event;
9 switch (event_id) {
10 case PBT_APMPOWERSTATUSCHANGE: // The power status changed.
11 power_event = POWER_STATE_EVENT;
12 break;
13 case PBT_APMRESUMEAUTOMATIC: // Resume from suspend.
14 //case PBT_APMRESUMESUSPEND: // User-initiated resume from suspend.
15 // We don't notify for this latter event
16 // because if it occurs it is always sent as a
17 // second event after PBT_APMRESUMEAUTOMATIC.
18 power_event = RESUME_EVENT;
19 break;
20 case PBT_APMSUSPEND: // System has been suspended.
21 power_event = SUSPEND_EVENT;
22 break;
23 default:
24 return;
26 // Other Power Events:
27 // PBT_APMBATTERYLOW - removed in Vista.
28 // PBT_APMOEMEVENT - removed in Vista.
29 // PBT_APMQUERYSUSPEND - removed in Vista.
30 // PBT_APMQUERYSUSPENDFAILED - removed in Vista.
31 // PBT_APMRESUMECRITICAL - removed in Vista.
32 // PBT_POWERSETTINGCHANGE - user changed the power settings.
34 ProcessPowerMessage(power_event);
37 // Function to query the system to see if it is currently running on
38 // battery power. Returns true if running on battery.
39 bool SystemMonitor::IsBatteryPower() {
40 SYSTEM_POWER_STATUS status;
41 if (!GetSystemPowerStatus(&status)) {
42 LOG(ERROR) << "GetSystemPowerStatus failed: " << GetLastError();
43 return false;
45 return (status.ACLineStatus == 0);