[email protected] | a20e82f | 2008-09-25 18:46:11 | [diff] [blame] | 1 | // 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 |
|
| 7 | namespace base {
|
| 8 |
|
| 9 | SystemMonitor::SystemMonitor()
|
| 10 | : battery_in_use_(IsBatteryPower()),
|
| 11 | suspended_(false) {
|
| 12 | }
|
| 13 |
|
| 14 | void 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] | e38d2192 | 2008-09-25 19:33:39 | [diff] [blame] | 42 | } // namespace base
|