Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Unified Diff: app/system_monitor.cc

Issue 6361002: Move SystemMonitor to src/chrome/common.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « app/system_monitor.h ('k') | app/system_monitor_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: app/system_monitor.cc
===================================================================
--- app/system_monitor.cc (revision 71446)
+++ app/system_monitor.cc (working copy)
@@ -1,104 +0,0 @@
-// Copyright (c) 2010 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 "app/system_monitor.h"
-
-#include "base/logging.h"
-#include "base/message_loop.h"
-#include "base/time.h"
-
-static SystemMonitor* g_system_monitor = NULL;
-
-#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()
- : observer_list_(new ObserverListThreadSafe<PowerObserver>()),
- battery_in_use_(false),
- suspended_(false) {
- DCHECK(!g_system_monitor);
- g_system_monitor = this;
-
- DCHECK(MessageLoop::current());
-#if defined(ENABLE_BATTERY_MONITORING)
- delayed_battery_check_.Start(
- base::TimeDelta::FromMilliseconds(kDelayedBatteryCheckMs), this,
- &SystemMonitor::BatteryCheck);
-#endif // defined(ENABLE_BATTERY_MONITORING)
-#if defined(OS_MACOSX)
- PlatformInit();
-#endif
-}
-
-SystemMonitor::~SystemMonitor() {
-#if defined(OS_MACOSX)
- PlatformDestroy();
-#endif
- DCHECK_EQ(this, g_system_monitor);
- g_system_monitor = NULL;
-}
-
-// static
-SystemMonitor* SystemMonitor::Get() {
- return g_system_monitor;
-}
-
-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() {
- VLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off")
- << " battery";
- observer_list_->Notify(&PowerObserver::OnPowerStateChange, BatteryPower());
-}
-
-void SystemMonitor::NotifySuspend() {
- VLOG(1) << "Power Suspending";
- observer_list_->Notify(&PowerObserver::OnSuspend);
-}
-
-void SystemMonitor::NotifyResume() {
- VLOG(1) << "Power Resuming";
- observer_list_->Notify(&PowerObserver::OnResume);
-}
-
-void SystemMonitor::BatteryCheck() {
- ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT);
-}
« no previous file with comments | « app/system_monitor.h ('k') | app/system_monitor_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698