summaryrefslogtreecommitdiffstats
path: root/base/system_monitor.cc
diff options
context:
space:
mode:
authorjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-10 20:34:16 +0000
committerjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-10 20:34:16 +0000
commit05dfd4a342fb80e31ff333aa9f3aa550742a8a4d (patch)
tree9bc08c7a64efb3a0fe26fb50f5061881fd234fa1 /base/system_monitor.cc
parentd78934f0979e1bba701c8422172be9f4a83db1a3 (diff)
downloadchromium_src-05dfd4a342fb80e31ff333aa9f3aa550742a8a4d.zip
chromium_src-05dfd4a342fb80e31ff333aa9f3aa550742a8a4d.tar.gz
chromium_src-05dfd4a342fb80e31ff333aa9f3aa550742a8a4d.tar.bz2
Disable battery power detection on POSIX since we don't currently use it.
Batter Power is used on Windows to toggle HiRest timers, but this isn't applicable on other platforms. Review URL: http://codereview.chromium.org/21187 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9510 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/system_monitor.cc')
-rw-r--r--base/system_monitor.cc174
1 files changed, 89 insertions, 85 deletions
diff --git a/base/system_monitor.cc b/base/system_monitor.cc
index 1d44e3c..dd5aa60 100644
--- a/base/system_monitor.cc
+++ b/base/system_monitor.cc
@@ -1,85 +1,89 @@
-// 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"
-#include "base/logging.h"
-#include "base/message_loop.h"
-
-namespace base {
-
-// The amount of time (in ms) to wait before running the initial
-// battery check.
-static int kDelayedBatteryCheckMs = 10 * 1000;
-
-SystemMonitor::SystemMonitor()
- : battery_in_use_(false),
- suspended_(false) {
- observer_list_ = new ObserverListThreadSafe<PowerObserver>();
-}
-
-void SystemMonitor::ProcessPowerMessage(PowerEvent event_id) {
- // Suppress duplicate notifications. Some platforms may
- // send multiple notifications of the same event.
- switch (event_id) {
- case POWER_STATE_EVENT:
- {
- bool on_battery = IsBatteryPower();
- if (on_battery != battery_in_use_) {
- battery_in_use_ = on_battery;
- NotifyPowerStateChange();
- }
- }
- break;
- case RESUME_EVENT:
- if (suspended_) {
- suspended_ = false;
- NotifyResume();
- }
- break;
- case SUSPEND_EVENT:
- if (!suspended_) {
- suspended_ = true;
- NotifySuspend();
- }
- break;
- }
-}
-
-void SystemMonitor::AddObserver(PowerObserver* obs) {
- observer_list_->AddObserver(obs);
-}
-
-void SystemMonitor::RemoveObserver(PowerObserver* obs) {
- observer_list_->RemoveObserver(obs);
-}
-
-void SystemMonitor::NotifyPowerStateChange() {
- LOG(INFO) << L"PowerStateChange: "
- << (BatteryPower() ? L"On" : L"Off") << L" battery";
- observer_list_->Notify(&PowerObserver::OnPowerStateChange, this);
-}
-
-void SystemMonitor::NotifySuspend() {
- LOG(INFO) << L"Power Suspending";
- observer_list_->Notify(&PowerObserver::OnSuspend, this);
-}
-
-void SystemMonitor::NotifyResume() {
- LOG(INFO) << L"Power Resuming";
- observer_list_->Notify(&PowerObserver::OnResume, this);
-}
-
-void SystemMonitor::Start() {
- DCHECK(MessageLoop::current()); // Can't call start too early.
- SystemMonitor* monitor = Get();
- monitor->delayed_battery_check_.Start(
- TimeDelta::FromMilliseconds(kDelayedBatteryCheckMs), monitor,
- &SystemMonitor::BatteryCheck);
-}
-
-void SystemMonitor::BatteryCheck() {
- ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT);
-}
-
-} // namespace base
+// 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"
+#include "base/logging.h"
+#include "base/message_loop.h"
+
+namespace base {
+
+#if defined(ENABLE_BATTERY_MONITORING)
+// The amount of time (in ms) to wait before running the initial
+// battery check.
+static int kDelayedBatteryCheckMs = 10 * 1000;
+#endif // defined(ENABLE_BATTERY_MONITORING)
+
+SystemMonitor::SystemMonitor()
+ : battery_in_use_(false),
+ suspended_(false) {
+ observer_list_ = new ObserverListThreadSafe<PowerObserver>();
+}
+
+void SystemMonitor::ProcessPowerMessage(PowerEvent event_id) {
+ // Suppress duplicate notifications. Some platforms may
+ // send multiple notifications of the same event.
+ switch (event_id) {
+ case POWER_STATE_EVENT:
+ {
+ bool on_battery = IsBatteryPower();
+ if (on_battery != battery_in_use_) {
+ battery_in_use_ = on_battery;
+ NotifyPowerStateChange();
+ }
+ }
+ break;
+ case RESUME_EVENT:
+ if (suspended_) {
+ suspended_ = false;
+ NotifyResume();
+ }
+ break;
+ case SUSPEND_EVENT:
+ if (!suspended_) {
+ suspended_ = true;
+ NotifySuspend();
+ }
+ break;
+ }
+}
+
+void SystemMonitor::AddObserver(PowerObserver* obs) {
+ observer_list_->AddObserver(obs);
+}
+
+void SystemMonitor::RemoveObserver(PowerObserver* obs) {
+ observer_list_->RemoveObserver(obs);
+}
+
+void SystemMonitor::NotifyPowerStateChange() {
+ LOG(INFO) << L"PowerStateChange: "
+ << (BatteryPower() ? L"On" : L"Off") << L" battery";
+ observer_list_->Notify(&PowerObserver::OnPowerStateChange, this);
+}
+
+void SystemMonitor::NotifySuspend() {
+ LOG(INFO) << L"Power Suspending";
+ observer_list_->Notify(&PowerObserver::OnSuspend, this);
+}
+
+void SystemMonitor::NotifyResume() {
+ LOG(INFO) << L"Power Resuming";
+ observer_list_->Notify(&PowerObserver::OnResume, this);
+}
+
+void SystemMonitor::Start() {
+#if defined(ENABLE_BATTERY_MONITORING)
+ DCHECK(MessageLoop::current()); // Can't call start too early.
+ SystemMonitor* monitor = Get();
+ monitor->delayed_battery_check_.Start(
+ TimeDelta::FromMilliseconds(kDelayedBatteryCheckMs), monitor,
+ &SystemMonitor::BatteryCheck);
+#endif // defined(ENABLE_BATTERY_MONITORING)
+}
+
+void SystemMonitor::BatteryCheck() {
+ ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT);
+}
+
+} // namespace base