mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-05 05:30:29 +00:00
Bug 1062076 - remove Chromium system monitor from IPC code. rs=bent
This commit is contained in:
parent
7dce463506
commit
dfc298875b
@ -58,7 +58,6 @@ UNIFIED_SOURCES += [
|
||||
'src/base/simple_thread.cc',
|
||||
'src/base/string_piece.cc',
|
||||
'src/base/string_util.cc',
|
||||
'src/base/system_monitor.cc',
|
||||
'src/base/thread.cc',
|
||||
'src/base/thread_collision_warner.cc',
|
||||
'src/base/time.cc',
|
||||
@ -102,7 +101,6 @@ if os_win:
|
||||
'src/base/shared_memory_win.cc',
|
||||
'src/base/sys_info_win.cc',
|
||||
'src/base/sys_string_conversions_win.cc',
|
||||
'src/base/system_monitor_win.cc',
|
||||
'src/base/thread_local_storage_win.cc',
|
||||
'src/base/thread_local_win.cc',
|
||||
'src/base/time_win.cc',
|
||||
@ -159,7 +157,6 @@ if os_posix:
|
||||
'src/base/shared_memory_posix.cc',
|
||||
'src/base/string16.cc',
|
||||
'src/base/sys_info_posix.cc',
|
||||
'src/base/system_monitor_posix.cc',
|
||||
'src/base/thread_local_posix.cc',
|
||||
'src/base/thread_local_storage_posix.cc',
|
||||
'src/base/waitable_event_posix.cc',
|
||||
|
@ -1,89 +0,0 @@
|
||||
// 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() {
|
||||
CHROMIUM_LOG(INFO) << "PowerStateChange: "
|
||||
<< (BatteryPower() ? "On" : "Off") << " battery";
|
||||
observer_list_->Notify(&PowerObserver::OnPowerStateChange, this);
|
||||
}
|
||||
|
||||
void SystemMonitor::NotifySuspend() {
|
||||
CHROMIUM_LOG(INFO) << "Power Suspending";
|
||||
observer_list_->Notify(&PowerObserver::OnSuspend, this);
|
||||
}
|
||||
|
||||
void SystemMonitor::NotifyResume() {
|
||||
CHROMIUM_LOG(INFO) << "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
|
@ -1,129 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef BASE_SYSTEM_MONITOR_H_
|
||||
#define BASE_SYSTEM_MONITOR_H_
|
||||
|
||||
#include "base/observer_list_threadsafe.h"
|
||||
#include "base/singleton.h"
|
||||
|
||||
// Windows HiRes timers drain the battery faster so we need to know the battery
|
||||
// status. This isn't true for other platforms.
|
||||
#if defined(OS_WIN)
|
||||
#define ENABLE_BATTERY_MONITORING 1
|
||||
#else
|
||||
#undef ENABLE_BATTERY_MONITORING
|
||||
#endif // !OS_WIN
|
||||
|
||||
namespace base {
|
||||
|
||||
// Class for monitoring various system-related subsystems
|
||||
// such as power management, network status, etc.
|
||||
// TODO(mbelshe): Add support beyond just power management.
|
||||
class SystemMonitor {
|
||||
public:
|
||||
// Access to the Singleton
|
||||
static SystemMonitor* Get() {
|
||||
// Uses the LeakySingletonTrait because cleanup is optional.
|
||||
return
|
||||
Singleton<SystemMonitor, LeakySingletonTraits<SystemMonitor> >::get();
|
||||
}
|
||||
|
||||
// Start the System Monitor within a process. This method
|
||||
// is provided so that the battery check can be deferred.
|
||||
// The MessageLoop must be started before calling this
|
||||
// method.
|
||||
// This is a no-op on platforms for which ENABLE_BATTERY_MONITORING is
|
||||
// disabled.
|
||||
static void Start();
|
||||
|
||||
//
|
||||
// Power-related APIs
|
||||
//
|
||||
|
||||
// Is the computer currently on battery power.
|
||||
// Can be called on any thread.
|
||||
bool BatteryPower() {
|
||||
// Using a lock here is not necessary for just a bool.
|
||||
return battery_in_use_;
|
||||
}
|
||||
|
||||
// Normalized list of power events.
|
||||
enum PowerEvent {
|
||||
POWER_STATE_EVENT, // The Power status of the system has changed.
|
||||
SUSPEND_EVENT, // The system is being suspended.
|
||||
RESUME_EVENT // The system is being resumed.
|
||||
};
|
||||
|
||||
// Callbacks will be called on the thread which creates the SystemMonitor.
|
||||
// During the callback, Add/RemoveObserver will block until the callbacks
|
||||
// are finished. Observers should implement quick callback functions; if
|
||||
// lengthy operations are needed, the observer should take care to invoke
|
||||
// the operation on an appropriate thread.
|
||||
class PowerObserver {
|
||||
public:
|
||||
// Notification of a change in power status of the computer, such
|
||||
// as from switching between battery and A/C power.
|
||||
virtual void OnPowerStateChange(SystemMonitor*) = 0;
|
||||
|
||||
// Notification that the system is suspending.
|
||||
virtual void OnSuspend(SystemMonitor*) = 0;
|
||||
|
||||
// Notification that the system is resuming.
|
||||
virtual void OnResume(SystemMonitor*) = 0;
|
||||
};
|
||||
|
||||
// Add a new observer.
|
||||
// Can be called from any thread.
|
||||
// Must not be called from within a notification callback.
|
||||
void AddObserver(PowerObserver* obs);
|
||||
|
||||
// Remove an existing observer.
|
||||
// Can be called from any thread.
|
||||
// Must not be called from within a notification callback.
|
||||
void RemoveObserver(PowerObserver* obs);
|
||||
|
||||
#if defined(OS_WIN)
|
||||
// Windows-specific handling of a WM_POWERBROADCAST message.
|
||||
// Embedders of this API should hook their top-level window
|
||||
// message loop and forward WM_POWERBROADCAST through this call.
|
||||
void ProcessWmPowerBroadcastMessage(int event_id);
|
||||
#endif
|
||||
|
||||
// Cross-platform handling of a power event.
|
||||
void ProcessPowerMessage(PowerEvent event_id);
|
||||
|
||||
// Constructor.
|
||||
// Don't use this; access SystemMonitor via the Singleton.
|
||||
SystemMonitor();
|
||||
|
||||
private:
|
||||
// Platform-specific method to check whether the system is currently
|
||||
// running on battery power. Returns true if running on batteries,
|
||||
// false otherwise.
|
||||
bool IsBatteryPower();
|
||||
|
||||
// Checks the battery status and notifies observers if the battery
|
||||
// status has changed.
|
||||
void BatteryCheck();
|
||||
|
||||
// Functions to trigger notifications.
|
||||
void NotifyPowerStateChange();
|
||||
void NotifySuspend();
|
||||
void NotifyResume();
|
||||
|
||||
scoped_refptr<ObserverListThreadSafe<PowerObserver> > observer_list_;
|
||||
bool battery_in_use_;
|
||||
bool suspended_;
|
||||
|
||||
#if defined(ENABLE_BATTERY_MONITORING)
|
||||
base::OneShotTimer<SystemMonitor> delayed_battery_check_;
|
||||
#endif
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(SystemMonitor);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // BASE_SYSTEM_MONITOR_H_
|
@ -1,14 +0,0 @@
|
||||
// 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 {
|
||||
|
||||
bool SystemMonitor::IsBatteryPower() {
|
||||
NOTIMPLEMENTED();
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace base
|
@ -1,49 +0,0 @@
|
||||
// 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 {
|
||||
|
||||
void SystemMonitor::ProcessWmPowerBroadcastMessage(int event_id) {
|
||||
PowerEvent power_event;
|
||||
switch (event_id) {
|
||||
case PBT_APMPOWERSTATUSCHANGE: // The power status changed.
|
||||
power_event = POWER_STATE_EVENT;
|
||||
break;
|
||||
case PBT_APMRESUMEAUTOMATIC: // Non-user initiated resume from suspend.
|
||||
case PBT_APMRESUMESUSPEND: // User initiated resume from suspend.
|
||||
power_event = RESUME_EVENT;
|
||||
break;
|
||||
case PBT_APMSUSPEND: // System has been suspended.
|
||||
power_event = SUSPEND_EVENT;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
|
||||
// Other Power Events:
|
||||
// PBT_APMBATTERYLOW - removed in Vista.
|
||||
// PBT_APMOEMEVENT - removed in Vista.
|
||||
// PBT_APMQUERYSUSPEND - removed in Vista.
|
||||
// PBT_APMQUERYSUSPENDFAILED - removed in Vista.
|
||||
// PBT_APMRESUMECRITICAL - removed in Vista.
|
||||
// PBT_POWERSETTINGCHANGE - user changed the power settings.
|
||||
}
|
||||
ProcessPowerMessage(power_event);
|
||||
}
|
||||
|
||||
// Function to query the system to see if it is currently running on
|
||||
// battery power. Returns true if running on battery.
|
||||
bool SystemMonitor::IsBatteryPower() {
|
||||
SYSTEM_POWER_STATUS status;
|
||||
if (!GetSystemPowerStatus(&status)) {
|
||||
CHROMIUM_LOG(ERROR) << "GetSystemPowerStatus failed: " << GetLastError();
|
||||
return false;
|
||||
}
|
||||
return (status.ACLineStatus == 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace base
|
@ -45,7 +45,6 @@
|
||||
#include "base/logging.h"
|
||||
#include "base/cpu.h"
|
||||
#include "base/singleton.h"
|
||||
#include "base/system_monitor.h"
|
||||
#include "mozilla/Casting.h"
|
||||
|
||||
using base::Time;
|
||||
|
Loading…
x
Reference in New Issue
Block a user