diff options
author | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-25 18:46:11 +0000 |
---|---|---|
committer | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-25 18:46:11 +0000 |
commit | a20e82fa0c45fee5515a2ebfc46f38dc65446ef7 (patch) | |
tree | 3d14c292858f52cee26ee431410849499f7fcc52 /base/system_monitor.cc | |
parent | f9ef79b3c3f5e6a1b00909b30692d47ba92925e6 (diff) | |
download | chromium_src-a20e82fa0c45fee5515a2ebfc46f38dc65446ef7.zip chromium_src-a20e82fa0c45fee5515a2ebfc46f38dc65446ef7.tar.gz chromium_src-a20e82fa0c45fee5515a2ebfc46f38dc65446ef7.tar.bz2 |
Implement a SystemMonitor class for monitoring system status
changes. For now, this is just implementing power changes
(e.g. battery/AC power changes).
This CL just contains this class; the hooking into Chrome
will come in a separate CL, but I've tested the basics already.
Review URL: http://codereview.chromium.org/4051
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2593 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/system_monitor.cc')
-rw-r--r-- | base/system_monitor.cc | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/base/system_monitor.cc b/base/system_monitor.cc new file mode 100644 index 0000000..375945d --- /dev/null +++ b/base/system_monitor.cc @@ -0,0 +1,42 @@ +// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/system_monitor.h"
+
+namespace base {
+
+SystemMonitor::SystemMonitor()
+ : battery_in_use_(IsBatteryPower()),
+ suspended_(false) {
+}
+
+void SystemMonitor::ProcessPowerMessage(PowerEvent event_id) {
+ // Suppress duplicate notifications. Some platforms may
+ // send multiple notifications of the same event.
+ switch (event_id) {
+ case PowerStateEvent:
+ {
+ bool on_battery = IsBatteryPower();
+ if (on_battery != battery_in_use_) {
+ battery_in_use_ = on_battery;
+ NotifyPowerStateChange();
+ }
+ }
+ break;
+ case ResumeEvent:
+ if (suspended_) {
+ suspended_ = false;
+ NotifyResume();
+ }
+ break;
+ case SuspendEvent:
+ if (!suspended_) {
+ suspended_ = true;
+ NotifySuspend();
+ }
+ break;
+ }
+}
+
+} // namespace base
\ No newline at end of file |