blob: 37dc48a87f1d1aa697bd826bdc8c8256db27fa6b [file] [log] [blame]
[email protected]a20e82f2008-09-25 18:46:111// Copyright (c) 2008 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
5#include "base/system_monitor.h"
6
7namespace base {
8
9SystemMonitor::SystemMonitor()
10 : battery_in_use_(IsBatteryPower()),
11 suspended_(false) {
12}
13
14void SystemMonitor::ProcessPowerMessage(PowerEvent event_id) {
15 // Suppress duplicate notifications. Some platforms may
16 // send multiple notifications of the same event.
17 switch (event_id) {
18 case PowerStateEvent:
19 {
20 bool on_battery = IsBatteryPower();
21 if (on_battery != battery_in_use_) {
22 battery_in_use_ = on_battery;
23 NotifyPowerStateChange();
24 }
25 }
26 break;
27 case ResumeEvent:
28 if (suspended_) {
29 suspended_ = false;
30 NotifyResume();
31 }
32 break;
33 case SuspendEvent:
34 if (!suspended_) {
35 suspended_ = true;
36 NotifySuspend();
37 }
38 break;
39 }
40}
41
[email protected]e38d21922008-09-25 19:33:3942} // namespace base