summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhongbo.min@intel.com <hongbo.min@intel.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-03 19:06:51 +0000
committerhongbo.min@intel.com <hongbo.min@intel.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-03 19:06:51 +0000
commit6c5905b763d18bf2d81e2d1f4aac7f16ae32f6ea (patch)
tree86297e816ccbbe8dd10ab6fec01b350be86f63ea
parent617b65edba554089efd872e9f59f01ae964690ab (diff)
downloadchromium_src-6c5905b763d18bf2d81e2d1f4aac7f16ae32f6ea.zip
chromium_src-6c5905b763d18bf2d81e2d1f4aac7f16ae32f6ea.tar.gz
chromium_src-6c5905b763d18bf2d81e2d1f4aac7f16ae32f6ea.tar.bz2
Split the power monitoring feature from SystemMonitor
The SystemMonitor is a mixed monitor which not only monitors the power state changes but also the devices changes. This patch is to separate the power monitor from SystemMonitor as a new class PowerMonitor which is dedicated to monitor power state. The next step is to seek a opportunity to refactor SystemMonitor as something like DeviceMonitor. BUG=149059 TEST=base_unittests --gtest_filter=PowerMonitorTest.* Review URL: https://chromiumcodereview.appspot.com/10959020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192114 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/android/base_jni_registrar.cc4
-rw-r--r--base/android/java/src/org/chromium/base/PowerMonitor.java (renamed from base/android/java/src/org/chromium/base/SystemMonitor.java)15
-rw-r--r--base/android/java/src/org/chromium/base/PowerStatusReceiver.java4
-rw-r--r--base/base.gyp3
-rw-r--r--base/base.gypi17
-rw-r--r--base/hi_res_timer_manager.h8
-rw-r--r--base/hi_res_timer_manager_unittest.cc7
-rw-r--r--base/hi_res_timer_manager_win.cc9
-rw-r--r--base/power_monitor/power_monitor.cc106
-rw-r--r--base/power_monitor/power_monitor.h146
-rw-r--r--base/power_monitor/power_monitor_android.cc42
-rw-r--r--base/power_monitor/power_monitor_android.h17
-rw-r--r--base/power_monitor/power_monitor_ios.mm (renamed from base/system_monitor/system_monitor_ios.mm)12
-rw-r--r--base/power_monitor/power_monitor_mac.mm (renamed from base/system_monitor/system_monitor_mac.mm)25
-rw-r--r--base/power_monitor/power_monitor_posix.cc (renamed from base/system_monitor/system_monitor_posix.cc)6
-rw-r--r--base/power_monitor/power_monitor_unittest.cc106
-rw-r--r--base/power_monitor/power_monitor_win.cc (renamed from base/system_monitor/system_monitor_win.cc)32
-rw-r--r--base/power_monitor/power_observer.h31
-rw-r--r--base/system_monitor/system_monitor.cc83
-rw-r--r--base/system_monitor/system_monitor.h140
-rw-r--r--base/system_monitor/system_monitor_android.cc36
-rw-r--r--base/system_monitor/system_monitor_android.h17
-rw-r--r--base/system_monitor/system_monitor_unittest.cc76
-rw-r--r--build/android/findbugs_filter/findbugs_known_bugs.txt1
-rw-r--r--chrome/browser/extensions/event_router_forwarder_unittest.cc8
-rw-r--r--chrome/browser/profiles/profile_manager_unittest.cc7
-rw-r--r--chrome/nacl/nacl_exe_win_64.cc4
-rw-r--r--chrome/nacl/nacl_main.cc4
-rw-r--r--content/app/content_main_runner.cc8
-rw-r--r--content/browser/browser_main_loop.cc3
-rw-r--r--content/browser/browser_main_loop.h2
-rw-r--r--content/browser/gamepad/gamepad_test_helpers.cc5
-rw-r--r--content/browser/gamepad/gamepad_test_helpers.h6
-rw-r--r--content/plugin/plugin_main.cc4
-rw-r--r--content/public/test/browser_test_base.cc4
-rw-r--r--content/renderer/renderer_main.cc4
-rw-r--r--content/utility/utility_main.cc4
-rw-r--r--content/worker/worker_main.cc4
-rw-r--r--net/http/http_network_layer.h6
-rw-r--r--net/url_request/url_request_job.cc13
-rw-r--r--net/url_request/url_request_job.h10
-rw-r--r--testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java4
-rw-r--r--webkit/blob/blob_url_request_job.h2
43 files changed, 576 insertions, 469 deletions
diff --git a/base/android/base_jni_registrar.cc b/base/android/base_jni_registrar.cc
index 6aabd0d..105d03f 100644
--- a/base/android/base_jni_registrar.cc
+++ b/base/android/base_jni_registrar.cc
@@ -15,7 +15,7 @@
#include "base/android/path_utils.h"
#include "base/android/thread_utils.h"
#include "base/message_pump_android.h"
-#include "base/system_monitor/system_monitor_android.h"
+#include "base/power_monitor/power_monitor_android.h"
namespace base {
namespace android {
@@ -29,7 +29,7 @@ static RegistrationMethod kBaseRegisteredMethods[] = {
{ "PathService", base::android::RegisterPathService },
{ "PathUtils", base::android::RegisterPathUtils },
{ "SystemMessageHandler", base::MessagePumpForUI::RegisterBindings },
- { "SystemMonitor", base::RegisterSystemMonitor },
+ { "PowerMonitor", base::RegisterPowerMonitor },
{ "ThreadUtils", base::RegisterThreadUtils },
};
diff --git a/base/android/java/src/org/chromium/base/SystemMonitor.java b/base/android/java/src/org/chromium/base/PowerMonitor.java
index 138ae28..b7a691e 100644
--- a/base/android/java/src/org/chromium/base/SystemMonitor.java
+++ b/base/android/java/src/org/chromium/base/PowerMonitor.java
@@ -13,12 +13,15 @@ import android.os.Looper;
/**
- * Integrates native SystemMonitor with the java side.
+ * Integrates native PowerMonitor with the java side.
*/
@JNINamespace("base::android")
-public class SystemMonitor implements ActivityStatus.StateListener {
+public class PowerMonitor implements ActivityStatus.StateListener {
private static final long SUSPEND_DELAY_MS = 1 * 60 * 1000; // 1 minute.
- private static SystemMonitor sInstance;
+ private static class LazyHolder {
+ private static final PowerMonitor INSTANCE = new PowerMonitor();
+ }
+ private static PowerMonitor sInstance;
private boolean mIsBatteryPower;
private final Handler mHandler = new Handler(Looper.getMainLooper());
@@ -38,12 +41,12 @@ public class SystemMonitor implements ActivityStatus.StateListener {
// Applications will create this once the JNI side has been fully wired up both sides. For
// tests, we just need native -> java, that is, we don't need to notify java -> native on
// creation.
- sInstance = new SystemMonitor();
+ sInstance = LazyHolder.INSTANCE;
}
public static void create(Context context) {
if (sInstance == null) {
- sInstance = new SystemMonitor();
+ sInstance = LazyHolder.INSTANCE;
ActivityStatus.registerStateListener(sInstance);
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatusIntent = context.registerReceiver(null, ifilter);
@@ -51,7 +54,7 @@ public class SystemMonitor implements ActivityStatus.StateListener {
}
}
- private SystemMonitor() {
+ private PowerMonitor() {
}
public static void onBatteryChargingChanged(Intent intent) {
diff --git a/base/android/java/src/org/chromium/base/PowerStatusReceiver.java b/base/android/java/src/org/chromium/base/PowerStatusReceiver.java
index 89594b8..f36c146 100644
--- a/base/android/java/src/org/chromium/base/PowerStatusReceiver.java
+++ b/base/android/java/src/org/chromium/base/PowerStatusReceiver.java
@@ -11,13 +11,13 @@ import android.content.Intent;
/**
* A BroadcastReceiver that listens to changes in power status and notifies
- * SystemMonitor.
+ * PowerMonitor.
* It's instantiated by the framework via the application intent-filter
* declared in its manifest.
*/
public class PowerStatusReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
- SystemMonitor.onBatteryChargingChanged(intent);
+ PowerMonitor.onBatteryChargingChanged(intent);
}
}
diff --git a/base/base.gyp b/base/base.gyp
index ea04cae..a8f2832 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -535,6 +535,7 @@
'platform_file_unittest.cc',
'posix/file_descriptor_shuffle_unittest.cc',
'posix/unix_domain_socket_linux_unittest.cc',
+ 'power_monitor/power_monitor_unittest.cc',
'pr_time_unittest.cc',
'prefs/default_pref_store_unittest.cc',
'prefs/json_pref_store_unittest.cc',
@@ -1119,8 +1120,8 @@
'android/java/src/org/chromium/base/LocaleUtils.java',
'android/java/src/org/chromium/base/PathService.java',
'android/java/src/org/chromium/base/PathUtils.java',
+ 'android/java/src/org/chromium/base/PowerMonitor.java',
'android/java/src/org/chromium/base/SystemMessageHandler.java',
- 'android/java/src/org/chromium/base/SystemMonitor.java',
'android/java/src/org/chromium/base/ThreadUtils.java',
],
'variables': {
diff --git a/base/base.gypi b/base/base.gypi
index 325dc6c..9f1dc84 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -345,6 +345,15 @@
'posix/global_descriptors.h',
'posix/unix_domain_socket_linux.cc',
'posix/unix_domain_socket_linux.h',
+ 'power_monitor/power_monitor.cc',
+ 'power_monitor/power_monitor.h',
+ 'power_monitor/power_monitor_android.cc',
+ 'power_monitor/power_monitor_android.h',
+ 'power_monitor/power_monitor_ios.mm',
+ 'power_monitor/power_monitor_mac.mm',
+ 'power_monitor/power_monitor_posix.cc',
+ 'power_monitor/power_monitor_win.cc',
+ 'power_monitor/power_observer.h',
'process.h',
'process_info.h',
'process_info_mac.cc',
@@ -435,12 +444,6 @@
'synchronization/waitable_event_win.cc',
'system_monitor/system_monitor.cc',
'system_monitor/system_monitor.h',
- 'system_monitor/system_monitor_android.cc',
- 'system_monitor/system_monitor_android.h',
- 'system_monitor/system_monitor_ios.mm',
- 'system_monitor/system_monitor_mac.mm',
- 'system_monitor/system_monitor_posix.cc',
- 'system_monitor/system_monitor_win.cc',
'sys_byteorder.h',
'sys_info.cc',
'sys_info.h',
@@ -648,7 +651,7 @@
'base_paths_posix.cc',
'files/file_path_watcher_kqueue.cc',
'files/file_path_watcher_stub.cc',
- 'system_monitor/system_monitor_posix.cc',
+ 'power_monitor/power_monitor_posix.cc',
],
'sources/': [
['include', '^files/file_path_watcher_linux\\.cc$'],
diff --git a/base/hi_res_timer_manager.h b/base/hi_res_timer_manager.h
index 1bd5538..763aede 100644
--- a/base/hi_res_timer_manager.h
+++ b/base/hi_res_timer_manager.h
@@ -6,17 +6,17 @@
#define BASE_HI_RES_TIMER_MANAGER_H_
#include "base/base_export.h"
-#include "base/system_monitor/system_monitor.h"
+#include "base/basictypes.h"
+#include "base/power_monitor/power_observer.h"
// Ensures that the Windows high resolution timer is only used
// when not running on battery power.
-class BASE_EXPORT HighResolutionTimerManager
- : public base::SystemMonitor::PowerObserver {
+class BASE_EXPORT HighResolutionTimerManager : public base::PowerObserver {
public:
HighResolutionTimerManager();
virtual ~HighResolutionTimerManager();
- // base::SystemMonitor::PowerObserver:
+ // base::PowerObserver method.
virtual void OnPowerStateChange(bool on_battery_power) OVERRIDE;
// Returns true if the hi resolution clock could be used right now.
diff --git a/base/hi_res_timer_manager_unittest.cc b/base/hi_res_timer_manager_unittest.cc
index 07651ce..601586d 100644
--- a/base/hi_res_timer_manager_unittest.cc
+++ b/base/hi_res_timer_manager_unittest.cc
@@ -5,7 +5,8 @@
#include "base/hi_res_timer_manager.h"
#include "base/memory/scoped_ptr.h"
-#include "base/system_monitor/system_monitor.h"
+#include "base/message_loop.h"
+#include "base/power_monitor/power_monitor.h"
#include "base/time.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -13,12 +14,12 @@
// http://crbug.com/114048
TEST(HiResTimerManagerTest, DISABLED_ToggleOnOff) {
MessageLoop loop;
- scoped_ptr<base::SystemMonitor> system_monitor(new base::SystemMonitor());
+ scoped_ptr<base::PowerMonitor> power_monitor(new base::PowerMonitor());
HighResolutionTimerManager manager;
// At this point, we don't know if the high resolution timers are on or off,
// it depends on what system the tests are running on (for example, if this
- // test is running on a laptop/battery, then the SystemMonitor would have
+ // test is running on a laptop/battery, then the PowerMonitor would have
// already set the PowerState to battery power; but if we're running on a
// desktop, then the PowerState will be non-battery power). Simulate a power
// level change to get to a deterministic state.
diff --git a/base/hi_res_timer_manager_win.cc b/base/hi_res_timer_manager_win.cc
index 1a92394..2a297dc 100644
--- a/base/hi_res_timer_manager_win.cc
+++ b/base/hi_res_timer_manager_win.cc
@@ -4,17 +4,18 @@
#include "base/hi_res_timer_manager.h"
+#include "base/power_monitor/power_monitor.h"
#include "base/time.h"
HighResolutionTimerManager::HighResolutionTimerManager()
: hi_res_clock_available_(false) {
- base::SystemMonitor* system_monitor = base::SystemMonitor::Get();
- system_monitor->AddPowerObserver(this);
- UseHiResClock(!system_monitor->BatteryPower());
+ base::PowerMonitor* power_monitor = base::PowerMonitor::Get();
+ power_monitor->AddObserver(this);
+ UseHiResClock(!power_monitor->BatteryPower());
}
HighResolutionTimerManager::~HighResolutionTimerManager() {
- base::SystemMonitor::Get()->RemovePowerObserver(this);
+ base::PowerMonitor::Get()->RemoveObserver(this);
UseHiResClock(false);
}
diff --git a/base/power_monitor/power_monitor.cc b/base/power_monitor/power_monitor.cc
new file mode 100644
index 0000000..13e91c7
--- /dev/null
+++ b/base/power_monitor/power_monitor.cc
@@ -0,0 +1,106 @@
+// Copyright 2013 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/power_monitor/power_monitor.h"
+
+#include "base/time.h"
+
+namespace base {
+
+static PowerMonitor* g_power_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)
+
+PowerMonitor::PowerMonitor()
+ : observers_(new ObserverListThreadSafe<PowerObserver>()),
+ battery_in_use_(false),
+ suspended_(false) {
+ DCHECK(!g_power_monitor);
+ g_power_monitor = this;
+
+ DCHECK(MessageLoop::current());
+#if defined(ENABLE_BATTERY_MONITORING)
+ delayed_battery_check_.Start(FROM_HERE,
+ base::TimeDelta::FromMilliseconds(kDelayedBatteryCheckMs), this,
+ &PowerMonitor::BatteryCheck);
+#endif // defined(ENABLE_BATTERY_MONITORING)
+#if defined(OS_MACOSX)
+ PlatformInit();
+#endif
+}
+
+PowerMonitor::~PowerMonitor() {
+#if defined(OS_MACOSX)
+ PlatformDestroy();
+#endif
+ DCHECK_EQ(this, g_power_monitor);
+ g_power_monitor = NULL;
+}
+
+// static
+PowerMonitor* PowerMonitor::Get() {
+ return g_power_monitor;
+}
+
+void PowerMonitor::AddObserver(PowerObserver* obs) {
+ observers_->AddObserver(obs);
+}
+
+void PowerMonitor::RemoveObserver(PowerObserver* obs) {
+ observers_->RemoveObserver(obs);
+}
+
+void PowerMonitor::ProcessPowerEvent(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 PowerMonitor::BatteryCheck() {
+ ProcessPowerEvent(PowerMonitor::POWER_STATE_EVENT);
+}
+
+void PowerMonitor::NotifyPowerStateChange() {
+ DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off")
+ << " battery";
+ observers_->Notify(&PowerObserver::OnPowerStateChange, BatteryPower());
+}
+
+void PowerMonitor::NotifySuspend() {
+ DVLOG(1) << "Power Suspending";
+ observers_->Notify(&PowerObserver::OnSuspend);
+}
+
+void PowerMonitor::NotifyResume() {
+ DVLOG(1) << "Power Resuming";
+ observers_->Notify(&PowerObserver::OnResume);
+}
+
+} // namespace base
diff --git a/base/power_monitor/power_monitor.h b/base/power_monitor/power_monitor.h
new file mode 100644
index 0000000..e893547
--- /dev/null
+++ b/base/power_monitor/power_monitor.h
@@ -0,0 +1,146 @@
+// Copyright 2013 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_POWER_MONITOR_POWER_MONITOR_H_
+#define BASE_POWER_MONITOR_POWER_MONITOR_H_
+
+#include "base/base_export.h"
+#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
+#include "base/observer_list_threadsafe.h"
+#include "base/power_monitor/power_observer.h"
+
+#if defined(OS_WIN)
+#include <windows.h>
+
+// Windows HiRes timers drain the battery faster so we need to know the battery
+// status. This isn't true for other platforms.
+#define ENABLE_BATTERY_MONITORING 1
+#else
+#undef ENABLE_BATTERY_MONITORING
+#endif // !OS_WIN
+
+#if defined(ENABLE_BATTERY_MONITORING)
+#include "base/timer.h"
+#endif // defined(ENABLE_BATTERY_MONITORING)
+
+#if defined(OS_IOS)
+#include <objc/runtime.h>
+#endif // OS_IOS
+
+namespace base {
+
+// A class used to monitor the power state change and notify the observers about
+// the change event.
+class BASE_EXPORT PowerMonitor {
+ public:
+ // 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.
+ };
+
+ PowerMonitor();
+ ~PowerMonitor();
+
+ // Get the application-wide PowerMonitor (if not present, returns NULL).
+ static PowerMonitor* Get();
+
+#if defined(OS_MACOSX)
+ // Allocate system resources needed by the PowerMonitor class.
+ //
+ // This function must be called before instantiating an instance of the class
+ // and before the Sandbox is initialized.
+#if !defined(OS_IOS)
+ static void AllocateSystemIOPorts();
+#else
+ static void AllocateSystemIOPorts() {}
+#endif // OS_IOS
+#endif // OS_MACOSX
+
+ // Add and remove an observer.
+ // Can be called from any thread.
+ // Must not be called from within a notification callback.
+ void AddObserver(PowerObserver* observer);
+ void RemoveObserver(PowerObserver* observer);
+
+ // Is the computer currently on battery power. Can be called on any thread.
+ bool BatteryPower() const {
+ // Using a lock here is not necessary for just a bool.
+ return battery_in_use_;
+ }
+
+ private:
+ friend class PowerMonitorTest;
+ // A friend function that is allowed to access the private ProcessPowerEvent.
+ friend void ProcessPowerEventHelper(PowerEvent);
+
+#if defined(OS_WIN)
+ // Represents a message-only window for power message handling on Windows.
+ // Only allow PowerMonitor to create it.
+ class PowerMessageWindow {
+ public:
+ PowerMessageWindow();
+ ~PowerMessageWindow();
+
+ private:
+ void ProcessWmPowerBroadcastMessage(int event_id);
+ LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
+ WPARAM wparam, LPARAM lparam);
+ static LRESULT CALLBACK WndProcThunk(HWND hwnd,
+ UINT message,
+ WPARAM wparam,
+ LPARAM lparam);
+ // Instance of the module containing the window procedure.
+ HMODULE instance_;
+ // A hidden message-only window.
+ HWND message_hwnd_;
+ };
+#endif // OS_WIN
+
+#if defined(OS_MACOSX)
+ void PlatformInit();
+ void PlatformDestroy();
+#endif
+
+ // Cross-platform handling of a power event.
+ void ProcessPowerEvent(PowerEvent event_id);
+
+ // 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();
+
+ void NotifyPowerStateChange();
+ void NotifySuspend();
+ void NotifyResume();
+
+#if defined(OS_IOS)
+ // Holds pointers to system event notification observers.
+ std::vector<id> notification_observers_;
+#endif
+
+#if defined(ENABLE_BATTERY_MONITORING)
+ base::OneShotTimer<PowerMonitor> delayed_battery_check_;
+#endif
+
+ scoped_refptr<ObserverListThreadSafe<PowerObserver> > observers_;
+ bool battery_in_use_;
+ bool suspended_;
+
+#if defined(OS_WIN)
+ PowerMessageWindow power_message_window_;
+#endif
+
+ DISALLOW_COPY_AND_ASSIGN(PowerMonitor);
+};
+
+} // namespace base
+
+#endif // BASE_POWER_MONITOR_POWER_MONITOR_H_
diff --git a/base/power_monitor/power_monitor_android.cc b/base/power_monitor/power_monitor_android.cc
new file mode 100644
index 0000000..4900f6c
--- /dev/null
+++ b/base/power_monitor/power_monitor_android.cc
@@ -0,0 +1,42 @@
+// Copyright 2013 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/power_monitor/power_monitor.h"
+#include "jni/PowerMonitor_jni.h"
+
+namespace base {
+
+// A helper function which is a friend of PowerMonitor.
+void ProcessPowerEventHelper(PowerMonitor::PowerEvent event) {
+ if (base::PowerMonitor::Get())
+ base::PowerMonitor::Get()->ProcessPowerEvent(event);
+}
+
+namespace android {
+
+// Native implementation of PowerMonitor.java.
+void OnBatteryChargingChanged(JNIEnv* env, jclass clazz) {
+ ProcessPowerEventHelper(PowerMonitor::POWER_STATE_EVENT);
+}
+
+void OnMainActivityResumed(JNIEnv* env, jclass clazz) {
+ ProcessPowerEventHelper(PowerMonitor::RESUME_EVENT);
+}
+
+void OnMainActivitySuspended(JNIEnv* env, jclass clazz) {
+ ProcessPowerEventHelper(PowerMonitor::SUSPEND_EVENT);
+}
+
+} // namespace android
+
+bool PowerMonitor::IsBatteryPower() {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ return base::android::Java_PowerMonitor_isBatteryPower(env);
+}
+
+bool RegisterPowerMonitor(JNIEnv* env) {
+ return base::android::RegisterNativesImpl(env);
+}
+
+} // namespace base
diff --git a/base/power_monitor/power_monitor_android.h b/base/power_monitor/power_monitor_android.h
new file mode 100644
index 0000000..7f43164
--- /dev/null
+++ b/base/power_monitor/power_monitor_android.h
@@ -0,0 +1,17 @@
+// Copyright 2013 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_POWER_MONITOR_POWER_MONITOR_ANDROID_H_
+#define BASE_POWER_MONITOR_POWER_MONITOR_ANDROID_H_
+
+#include <jni.h>
+
+namespace base {
+
+// Registers the JNI bindings for PowerMonitor.
+bool RegisterPowerMonitor(JNIEnv* env);
+
+} // namespace base
+
+#endif // BASE_POWER_MONITOR_POWER_MONITOR_ANDROID_H_
diff --git a/base/system_monitor/system_monitor_ios.mm b/base/power_monitor/power_monitor_ios.mm
index f3251b6..f7c0b92 100644
--- a/base/system_monitor/system_monitor_ios.mm
+++ b/base/power_monitor/power_monitor_ios.mm
@@ -1,34 +1,34 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2013 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/system_monitor.h"
+#include "base/power_monitor/power_monitor.h"
#import <UIKit/UIKit.h>
namespace base {
-void SystemMonitor::PlatformInit() {
+void PowerMonitor::PlatformInit() {
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
id foreground =
[nc addObserverForName:UIApplicationWillEnterForegroundNotification
object:nil
queue:nil
usingBlock:^(NSNotification* notification) {
- ProcessPowerMessage(RESUME_EVENT);
+ ProcessPowerEvent(RESUME_EVENT);
}];
id background =
[nc addObserverForName:UIApplicationDidEnterBackgroundNotification
object:nil
queue:nil
usingBlock:^(NSNotification* notification) {
- ProcessPowerMessage(SUSPEND_EVENT);
+ ProcessPowerEvent(SUSPEND_EVENT);
}];
notification_observers_.push_back(foreground);
notification_observers_.push_back(background);
}
-void SystemMonitor::PlatformDestroy() {
+void PowerMonitor::PlatformDestroy() {
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
for (std::vector<id>::iterator it = notification_observers_.begin();
it != notification_observers_.end(); ++it) {
diff --git a/base/system_monitor/system_monitor_mac.mm b/base/power_monitor/power_monitor_mac.mm
index d0dbaab..ee906f6 100644
--- a/base/system_monitor/system_monitor_mac.mm
+++ b/base/power_monitor/power_monitor_mac.mm
@@ -1,17 +1,23 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2013 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.
// Implementation based on sample code from
// http://developer.apple.com/library/mac/#qa/qa1340/_index.html.
-#include "base/system_monitor/system_monitor.h"
+#include "base/power_monitor/power_monitor.h"
#include <IOKit/pwr_mgt/IOPMLib.h>
#include <IOKit/IOMessage.h>
namespace base {
+void ProcessPowerEventHelper(PowerMonitor::PowerEvent event) {
+ DCHECK(PowerMonitor::Get());
+ if (PowerMonitor::Get())
+ PowerMonitor::Get()->ProcessPowerEvent(event);
+}
+
namespace {
io_connect_t g_system_power_io_port = 0;
@@ -22,17 +28,15 @@ void SystemPowerEventCallback(void*,
io_service_t service,
natural_t message_type,
void* message_argument) {
- SystemMonitor* sys_monitor = SystemMonitor::Get();
- DCHECK(sys_monitor);
switch (message_type) {
case kIOMessageSystemWillSleep:
- sys_monitor->ProcessPowerMessage(SystemMonitor::SUSPEND_EVENT);
+ ProcessPowerEventHelper(base::PowerMonitor::SUSPEND_EVENT);
IOAllowPowerChange(g_system_power_io_port,
reinterpret_cast<intptr_t>(message_argument));
break;
case kIOMessageSystemWillPowerOn:
- sys_monitor->ProcessPowerMessage(SystemMonitor::RESUME_EVENT);
+ ProcessPowerEventHelper(PowerMonitor::RESUME_EVENT);
break;
}
}
@@ -45,11 +49,10 @@ void SystemPowerEventCallback(void*,
// See crbug.com/83783 .
// static
-void SystemMonitor::AllocateSystemIOPorts() {
+void PowerMonitor::AllocateSystemIOPorts() {
DCHECK_EQ(g_system_power_io_port, 0u);
// Notification port allocated by IORegisterForSystemPower.
-
g_system_power_io_port = IORegisterForSystemPower(
NULL, &g_notification_port_ref, SystemPowerEventCallback,
&g_notifier_object);
@@ -57,8 +60,8 @@ void SystemMonitor::AllocateSystemIOPorts() {
DCHECK_NE(g_system_power_io_port, 0u);
}
-void SystemMonitor::PlatformInit() {
- // Need to call AllocateSystemIOPorts() before constructing a SystemMonitor
+void PowerMonitor::PlatformInit() {
+ // Need to call AllocateSystemIOPorts() before creating a PowerMonitor
// object.
DCHECK_NE(g_system_power_io_port, 0u);
if (g_system_power_io_port == 0)
@@ -71,7 +74,7 @@ void SystemMonitor::PlatformInit() {
kCFRunLoopCommonModes);
}
-void SystemMonitor::PlatformDestroy() {
+void PowerMonitor::PlatformDestroy() {
DCHECK_NE(g_system_power_io_port, 0u);
if (g_system_power_io_port == 0)
return;
diff --git a/base/system_monitor/system_monitor_posix.cc b/base/power_monitor/power_monitor_posix.cc
index 6cf01bf..affebea 100644
--- a/base/system_monitor/system_monitor_posix.cc
+++ b/base/power_monitor/power_monitor_posix.cc
@@ -1,12 +1,12 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright 2013 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/system_monitor.h"
+#include "base/power_monitor/power_monitor.h"
namespace base {
-bool SystemMonitor::IsBatteryPower() {
+bool PowerMonitor::IsBatteryPower() {
NOTIMPLEMENTED();
return false;
}
diff --git a/base/power_monitor/power_monitor_unittest.cc b/base/power_monitor/power_monitor_unittest.cc
new file mode 100644
index 0000000..af3ed41
--- /dev/null
+++ b/base/power_monitor/power_monitor_unittest.cc
@@ -0,0 +1,106 @@
+// Copyright 2013 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/power_monitor/power_monitor.h"
+
+#include "base/message_loop.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+
+class PowerTest : public PowerObserver {
+ public:
+ PowerTest()
+ : power_state_changes_(0),
+ suspends_(0),
+ resumes_(0) {
+ }
+
+ // PowerObserver callbacks.
+ virtual void OnPowerStateChange(bool on_battery_power) OVERRIDE {
+ power_state_changes_++;
+ }
+
+ virtual void OnSuspend() OVERRIDE {
+ suspends_++;
+ }
+
+ virtual void OnResume() OVERRIDE {
+ resumes_++;
+ }
+
+ // Test status counts.
+ int power_state_changes() { return power_state_changes_; }
+ int suspends() { return suspends_; }
+ int resumes() { return resumes_; }
+
+ private:
+ int power_state_changes_; // Count of OnPowerStateChange notifications.
+ int suspends_; // Count of OnSuspend notifications.
+ int resumes_; // Count of OnResume notifications.
+};
+
+class PowerMonitorTest : public testing::Test {
+ protected:
+ PowerMonitorTest() {
+#if defined(OS_MACOSX)
+ // This needs to happen before PowerMonitor's ctor.
+ PowerMonitor::AllocateSystemIOPorts();
+#endif
+ power_monitor_.reset(new PowerMonitor);
+ }
+
+ void ProcessPowerEvent(PowerMonitor::PowerEvent event_id) {
+ power_monitor_->ProcessPowerEvent(event_id);
+ }
+
+ virtual ~PowerMonitorTest() {}
+
+ MessageLoop message_loop_;
+ scoped_ptr<PowerMonitor> power_monitor_;
+
+ DISALLOW_COPY_AND_ASSIGN(PowerMonitorTest);
+};
+
+TEST_F(PowerMonitorTest, PowerNotifications) {
+ const int kObservers = 5;
+
+ PowerTest test[kObservers];
+ for (int index = 0; index < kObservers; ++index)
+ power_monitor_->AddObserver(&test[index]);
+
+ // Send a bunch of power changes. Since the battery power hasn't
+ // actually changed, we shouldn't get notifications.
+ for (int index = 0; index < 5; index++) {
+ ProcessPowerEvent(PowerMonitor::POWER_STATE_EVENT);
+ EXPECT_EQ(test[0].power_state_changes(), 0);
+ }
+
+ // Sending resume when not suspended should have no effect.
+ ProcessPowerEvent(PowerMonitor::RESUME_EVENT);
+ message_loop_.RunUntilIdle();
+ EXPECT_EQ(test[0].resumes(), 0);
+
+ // Pretend we suspended.
+ ProcessPowerEvent(PowerMonitor::SUSPEND_EVENT);
+ message_loop_.RunUntilIdle();
+ EXPECT_EQ(test[0].suspends(), 1);
+
+ // Send a second suspend notification. This should be suppressed.
+ ProcessPowerEvent(PowerMonitor::SUSPEND_EVENT);
+ message_loop_.RunUntilIdle();
+ EXPECT_EQ(test[0].suspends(), 1);
+
+ // Pretend we were awakened.
+ ProcessPowerEvent(PowerMonitor::RESUME_EVENT);
+ message_loop_.RunUntilIdle();
+ EXPECT_EQ(test[0].resumes(), 1);
+
+ // Send a duplicate resume notification. This should be suppressed.
+ ProcessPowerEvent(PowerMonitor::RESUME_EVENT);
+ message_loop_.RunUntilIdle();
+ EXPECT_EQ(test[0].resumes(), 1);
+}
+
+} // namespace base
diff --git a/base/system_monitor/system_monitor_win.cc b/base/power_monitor/power_monitor_win.cc
index 562b69b..67a6ce1 100644
--- a/base/system_monitor/system_monitor_win.cc
+++ b/base/power_monitor/power_monitor_win.cc
@@ -1,8 +1,8 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright 2013 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/system_monitor.h"
+#include "base/power_monitor/power_monitor.h"
#include "base/win/wrapped_window_proc.h"
@@ -16,7 +16,7 @@ const wchar_t kWindowClassName[] = L"Base_PowerMessageWindow";
// Function to query the system to see if it is currently running on
// battery power. Returns true if running on battery.
-bool SystemMonitor::IsBatteryPower() {
+bool PowerMonitor::IsBatteryPower() {
SYSTEM_POWER_STATUS status;
if (!GetSystemPowerStatus(&status)) {
DLOG_GETLASTERROR(ERROR) << "GetSystemPowerStatus failed";
@@ -25,13 +25,13 @@ bool SystemMonitor::IsBatteryPower() {
return (status.ACLineStatus == 0);
}
-SystemMonitor::PowerMessageWindow::PowerMessageWindow()
+PowerMonitor::PowerMessageWindow::PowerMessageWindow()
: instance_(NULL), message_hwnd_(NULL) {
WNDCLASSEX window_class;
base::win::InitializeWindowClass(
kWindowClassName,
&base::win::WrappedWindowProc<
- SystemMonitor::PowerMessageWindow::WndProcThunk>,
+ PowerMonitor::PowerMessageWindow::WndProcThunk>,
0, 0, 0, NULL, NULL, NULL, NULL, NULL,
&window_class);
instance_ = window_class.hInstance;
@@ -44,29 +44,29 @@ SystemMonitor::PowerMessageWindow::PowerMessageWindow()
reinterpret_cast<LONG_PTR>(this));
}
-SystemMonitor::PowerMessageWindow::~PowerMessageWindow() {
+PowerMonitor::PowerMessageWindow::~PowerMessageWindow() {
if (message_hwnd_) {
DestroyWindow(message_hwnd_);
UnregisterClass(kWindowClassName, instance_);
}
}
-void SystemMonitor::PowerMessageWindow::ProcessWmPowerBroadcastMessage(
+void PowerMonitor::PowerMessageWindow::ProcessWmPowerBroadcastMessage(
int event_id) {
- SystemMonitor::PowerEvent power_event;
+ PowerMonitor::PowerEvent power_event;
switch (event_id) {
case PBT_APMPOWERSTATUSCHANGE: // The power status changed.
- power_event = SystemMonitor::POWER_STATE_EVENT;
+ power_event = PowerMonitor::POWER_STATE_EVENT;
break;
case PBT_APMRESUMEAUTOMATIC: // Resume from suspend.
//case PBT_APMRESUMESUSPEND: // User-initiated resume from suspend.
// We don't notify for this latter event
// because if it occurs it is always sent as a
// second event after PBT_APMRESUMEAUTOMATIC.
- power_event = SystemMonitor::RESUME_EVENT;
+ power_event = PowerMonitor::RESUME_EVENT;
break;
case PBT_APMSUSPEND: // System has been suspended.
- power_event = SystemMonitor::SUSPEND_EVENT;
+ power_event = PowerMonitor::SUSPEND_EVENT;
break;
default:
return;
@@ -80,10 +80,10 @@ void SystemMonitor::PowerMessageWindow::ProcessWmPowerBroadcastMessage(
// PBT_POWERSETTINGCHANGE - user changed the power settings.
}
- SystemMonitor::Get()->ProcessPowerMessage(power_event);
+ PowerMonitor::Get()->ProcessPowerEvent(power_event);
}
-LRESULT CALLBACK SystemMonitor::PowerMessageWindow::WndProc(
+LRESULT CALLBACK PowerMonitor::PowerMessageWindow::WndProc(
HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
switch (message) {
case WM_POWERBROADCAST: {
@@ -98,10 +98,10 @@ LRESULT CALLBACK SystemMonitor::PowerMessageWindow::WndProc(
}
// static
-LRESULT CALLBACK SystemMonitor::PowerMessageWindow::WndProcThunk(
+LRESULT CALLBACK PowerMonitor::PowerMessageWindow::WndProcThunk(
HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
- SystemMonitor::PowerMessageWindow* message_hwnd =
- reinterpret_cast<SystemMonitor::PowerMessageWindow*>(
+ PowerMonitor::PowerMessageWindow* message_hwnd =
+ reinterpret_cast<PowerMonitor::PowerMessageWindow*>(
GetWindowLongPtr(hwnd, GWLP_USERDATA));
if (message_hwnd)
return message_hwnd->WndProc(hwnd, message, wparam, lparam);
diff --git a/base/power_monitor/power_observer.h b/base/power_monitor/power_observer.h
new file mode 100644
index 0000000..6be70bb
--- /dev/null
+++ b/base/power_monitor/power_observer.h
@@ -0,0 +1,31 @@
+// Copyright 2013 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_POWER_MONITOR_POWER_OBSERVER_H_
+#define BASE_POWER_MONITOR_POWER_OBSERVER_H_
+
+#include "base/base_export.h"
+#include "base/compiler_specific.h"
+
+namespace base {
+
+class BASE_EXPORT 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(bool on_battery_power) {};
+
+ // Notification that the system is suspending.
+ virtual void OnSuspend() {}
+
+ // Notification that the system is resuming.
+ virtual void OnResume() {}
+
+ protected:
+ virtual ~PowerObserver() {}
+};
+
+} // namespace base
+
+#endif // BASE_POWER_MONITOR_POWER_OBSERVER_H_
diff --git a/base/system_monitor/system_monitor.cc b/base/system_monitor/system_monitor.cc
index 7c960cc..b934139 100644
--- a/base/system_monitor/system_monitor.cc
+++ b/base/system_monitor/system_monitor.cc
@@ -14,36 +14,14 @@ namespace base {
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()
- : power_observer_list_(new ObserverListThreadSafe<PowerObserver>()),
- devices_changed_observer_list_(
- new ObserverListThreadSafe<DevicesChangedObserver>()),
- battery_in_use_(false),
- suspended_(false) {
+ : devices_changed_observer_list_(
+ new ObserverListThreadSafe<DevicesChangedObserver>()) {
DCHECK(!g_system_monitor);
g_system_monitor = this;
-
- DCHECK(MessageLoop::current());
-#if defined(ENABLE_BATTERY_MONITORING)
- delayed_battery_check_.Start(FROM_HERE,
- 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;
}
@@ -53,46 +31,10 @@ 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::ProcessDevicesChanged(DeviceType device_type) {
NotifyDevicesChanged(device_type);
}
-void SystemMonitor::AddPowerObserver(PowerObserver* obs) {
- power_observer_list_->AddObserver(obs);
-}
-
-void SystemMonitor::RemovePowerObserver(PowerObserver* obs) {
- power_observer_list_->RemoveObserver(obs);
-}
-
void SystemMonitor::AddDevicesChangedObserver(DevicesChangedObserver* obs) {
devices_changed_observer_list_->AddObserver(obs);
}
@@ -107,25 +49,4 @@ void SystemMonitor::NotifyDevicesChanged(DeviceType device_type) {
&DevicesChangedObserver::OnDevicesChanged, device_type);
}
-void SystemMonitor::NotifyPowerStateChange() {
- DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off")
- << " battery";
- power_observer_list_->Notify(&PowerObserver::OnPowerStateChange,
- BatteryPower());
-}
-
-void SystemMonitor::NotifySuspend() {
- DVLOG(1) << "Power Suspending";
- power_observer_list_->Notify(&PowerObserver::OnSuspend);
-}
-
-void SystemMonitor::NotifyResume() {
- DVLOG(1) << "Power Resuming";
- power_observer_list_->Notify(&PowerObserver::OnResume);
-}
-
-void SystemMonitor::BatteryCheck() {
- ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT);
-}
-
} // namespace base
diff --git a/base/system_monitor/system_monitor.h b/base/system_monitor/system_monitor.h
index 10f279f..5dd849f 100644
--- a/base/system_monitor/system_monitor.h
+++ b/base/system_monitor/system_monitor.h
@@ -5,35 +5,11 @@
#ifndef BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_
#define BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_H_
-#include <map>
-#include <string>
-#include <vector>
-
#include "base/base_export.h"
#include "base/basictypes.h"
-#include "build/build_config.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
-
+#include "base/memory/ref_counted.h"
#include "base/observer_list_threadsafe.h"
-#if defined(ENABLE_BATTERY_MONITORING)
-#include "base/timer.h"
-#endif // defined(ENABLE_BATTERY_MONITORING)
-
-#if defined(OS_MACOSX) && !defined(OS_IOS)
-#include <IOKit/pwr_mgt/IOPMLib.h>
-#include <IOKit/IOMessage.h>
-#endif // OS_MACOSX && !OS_IOS
-
-#if defined(OS_IOS)
-#include <objc/runtime.h>
-#endif // OS_IOS
+#include "build/build_config.h"
namespace base {
@@ -42,13 +18,6 @@ namespace base {
// TODO(mbelshe): Add support beyond just power management.
class BASE_EXPORT SystemMonitor {
public:
- // 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.
- };
-
// Type of devices whose change need to be monitored, such as add/remove.
enum DeviceType {
DEVTYPE_AUDIO_CAPTURE, // Audio capture device, e.g., microphone.
@@ -64,50 +33,6 @@ class BASE_EXPORT SystemMonitor {
// Get the application-wide SystemMonitor (if not present, returns NULL).
static SystemMonitor* Get();
-#if defined(OS_MACOSX)
- // Allocate system resources needed by the SystemMonitor class.
- //
- // This function must be called before instantiating an instance of the class
- // and before the Sandbox is initialized.
-#if !defined(OS_IOS)
- static void AllocateSystemIOPorts();
-#else
- static void AllocateSystemIOPorts() {}
-#endif // OS_IOS
-#endif // OS_MACOSX
-
- //
- // Power-related APIs
- //
-
- // Is the computer currently on battery power.
- // Can be called on any thread.
- bool BatteryPower() const {
- // Using a lock here is not necessary for just a bool.
- return battery_in_use_;
- }
-
- // 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 BASE_EXPORT 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(bool on_battery_power) {}
-
- // Notification that the system is suspending.
- virtual void OnSuspend() {}
-
- // Notification that the system is resuming.
- virtual void OnResume() {}
-
- protected:
- virtual ~PowerObserver() {}
- };
-
class BASE_EXPORT DevicesChangedObserver {
public:
// Notification that the devices connected to the system have changed.
@@ -121,87 +46,26 @@ class BASE_EXPORT SystemMonitor {
// Add a new observer.
// Can be called from any thread.
// Must not be called from within a notification callback.
- void AddPowerObserver(PowerObserver* obs);
void AddDevicesChangedObserver(DevicesChangedObserver* obs);
// Remove an existing observer.
// Can be called from any thread.
// Must not be called from within a notification callback.
- void RemovePowerObserver(PowerObserver* obs);
void RemoveDevicesChangedObserver(DevicesChangedObserver* obs);
// The ProcessFoo() style methods are a broken pattern and should not
// be copied. Any significant addition to this class is blocked on
// refactoring to improve the state of affairs. See http://crbug.com/149059
- // Cross-platform handling of a power event.
- void ProcessPowerMessage(PowerEvent event_id);
-
// Cross-platform handling of a device change event.
void ProcessDevicesChanged(DeviceType device_type);
private:
-#if defined(OS_WIN)
- // Represents a message-only window for power message handling on Windows.
- // Only allow SystemMonitor to create it.
- class PowerMessageWindow {
- public:
- PowerMessageWindow();
- ~PowerMessageWindow();
-
- private:
- void ProcessWmPowerBroadcastMessage(int event_id);
- LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
- WPARAM wparam, LPARAM lparam);
- static LRESULT CALLBACK WndProcThunk(HWND hwnd,
- UINT message,
- WPARAM wparam,
- LPARAM lparam);
- // Instance of the module containing the window procedure.
- HMODULE instance_;
- // A hidden message-only window.
- HWND message_hwnd_;
- };
-#endif
-
-#if defined(OS_MACOSX)
- void PlatformInit();
- void PlatformDestroy();
-#endif
-
- // 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 NotifyDevicesChanged(DeviceType device_type);
- void NotifyPowerStateChange();
- void NotifySuspend();
- void NotifyResume();
- scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_;
scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> >
devices_changed_observer_list_;
- bool battery_in_use_;
- bool suspended_;
-
-#if defined(ENABLE_BATTERY_MONITORING)
- base::OneShotTimer<SystemMonitor> delayed_battery_check_;
-#endif
-
-#if defined(OS_IOS)
- // Holds pointers to system event notification observers.
- std::vector<id> notification_observers_;
-#endif
-
-#if defined(OS_WIN)
- PowerMessageWindow power_message_window_;
-#endif
DISALLOW_COPY_AND_ASSIGN(SystemMonitor);
};
diff --git a/base/system_monitor/system_monitor_android.cc b/base/system_monitor/system_monitor_android.cc
deleted file mode 100644
index f29b7b0..0000000
--- a/base/system_monitor/system_monitor_android.cc
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (c) 2011 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/system_monitor.h"
-#include "jni/SystemMonitor_jni.h"
-
-namespace base {
-
-namespace android {
-
-// Native implementation of SystemMonitor.java.
-void OnBatteryChargingChanged(JNIEnv* env, jclass clazz) {
- SystemMonitor::Get()->ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT);
-}
-
-void OnMainActivityResumed(JNIEnv* env, jclass clazz) {
- SystemMonitor::Get()->ProcessPowerMessage(SystemMonitor::RESUME_EVENT);
-}
-
-void OnMainActivitySuspended(JNIEnv* env, jclass clazz) {
- SystemMonitor::Get()->ProcessPowerMessage(SystemMonitor::SUSPEND_EVENT);
-}
-
-} // namespace android
-
-bool SystemMonitor::IsBatteryPower() {
- JNIEnv* env = base::android::AttachCurrentThread();
- return base::android::Java_SystemMonitor_isBatteryPower(env);
-}
-
-bool RegisterSystemMonitor(JNIEnv* env) {
- return base::android::RegisterNativesImpl(env);
-}
-
-} // namespace base
diff --git a/base/system_monitor/system_monitor_android.h b/base/system_monitor/system_monitor_android.h
deleted file mode 100644
index 9f60560..0000000
--- a/base/system_monitor/system_monitor_android.h
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright (c) 2012 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_SYSTEM_MONITOR_ANDROID_H_
-#define BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_ANDROID_H_
-
-#include <jni.h>
-
-namespace base {
-
-// Registers the JNI bindings for SystemMonitor.
-bool RegisterSystemMonitor(JNIEnv* env);
-
-} // namespace base
-
-#endif // BASE_SYSTEM_MONITOR_SYSTEM_MONITOR_ANDROID_H_
diff --git a/base/system_monitor/system_monitor_unittest.cc b/base/system_monitor/system_monitor_unittest.cc
index 43f1dd6..b46e52f 100644
--- a/base/system_monitor/system_monitor_unittest.cc
+++ b/base/system_monitor/system_monitor_unittest.cc
@@ -14,45 +14,9 @@ namespace base {
namespace {
-class PowerTest : public SystemMonitor::PowerObserver {
- public:
- PowerTest()
- : power_state_changes_(0),
- suspends_(0),
- resumes_(0) {
- }
-
- // PowerObserver callbacks.
- virtual void OnPowerStateChange(bool on_battery_power) OVERRIDE {
- power_state_changes_++;
- }
-
- virtual void OnSuspend() OVERRIDE {
- suspends_++;
- }
-
- virtual void OnResume() OVERRIDE {
- resumes_++;
- }
-
- // Test status counts.
- int power_state_changes() { return power_state_changes_; }
- int suspends() { return suspends_; }
- int resumes() { return resumes_; }
-
- private:
- int power_state_changes_; // Count of OnPowerStateChange notifications.
- int suspends_; // Count of OnSuspend notifications.
- int resumes_; // Count of OnResume notifications.
-};
-
class SystemMonitorTest : public testing::Test {
protected:
SystemMonitorTest() {
-#if defined(OS_MACOSX)
- // This needs to happen before SystemMonitor's ctor.
- SystemMonitor::AllocateSystemIOPorts();
-#endif
system_monitor_.reset(new SystemMonitor);
}
virtual ~SystemMonitorTest() {}
@@ -63,46 +27,6 @@ class SystemMonitorTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(SystemMonitorTest);
};
-TEST_F(SystemMonitorTest, PowerNotifications) {
- const int kObservers = 5;
-
- PowerTest test[kObservers];
- for (int index = 0; index < kObservers; ++index)
- system_monitor_->AddPowerObserver(&test[index]);
-
- // Send a bunch of power changes. Since the battery power hasn't
- // actually changed, we shouldn't get notifications.
- for (int index = 0; index < 5; index++) {
- system_monitor_->ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT);
- EXPECT_EQ(test[0].power_state_changes(), 0);
- }
-
- // Sending resume when not suspended should have no effect.
- system_monitor_->ProcessPowerMessage(SystemMonitor::RESUME_EVENT);
- RunLoop().RunUntilIdle();
- EXPECT_EQ(test[0].resumes(), 0);
-
- // Pretend we suspended.
- system_monitor_->ProcessPowerMessage(SystemMonitor::SUSPEND_EVENT);
- RunLoop().RunUntilIdle();
- EXPECT_EQ(test[0].suspends(), 1);
-
- // Send a second suspend notification. This should be suppressed.
- system_monitor_->ProcessPowerMessage(SystemMonitor::SUSPEND_EVENT);
- RunLoop().RunUntilIdle();
- EXPECT_EQ(test[0].suspends(), 1);
-
- // Pretend we were awakened.
- system_monitor_->ProcessPowerMessage(SystemMonitor::RESUME_EVENT);
- RunLoop().RunUntilIdle();
- EXPECT_EQ(test[0].resumes(), 1);
-
- // Send a duplicate resume notification. This should be suppressed.
- system_monitor_->ProcessPowerMessage(SystemMonitor::RESUME_EVENT);
- RunLoop().RunUntilIdle();
- EXPECT_EQ(test[0].resumes(), 1);
-}
-
TEST_F(SystemMonitorTest, DeviceChangeNotifications) {
const int kObservers = 5;
diff --git a/build/android/findbugs_filter/findbugs_known_bugs.txt b/build/android/findbugs_filter/findbugs_known_bugs.txt
index 5adce22..61fc567 100644
--- a/build/android/findbugs_filter/findbugs_known_bugs.txt
+++ b/build/android/findbugs_filter/findbugs_known_bugs.txt
@@ -32,7 +32,6 @@ M D SF: Switch statement found in org.chromium.content.browser.ContentSettings$E
M D SF: Switch statement found in org.chromium.content.browser.HandleView.onTouchEvent(MotionEvent) where default case is missing At HandleView.java
M D SF: Switch statement found in org.chromium.content.browser.third_party.GestureDetector.onTouchEvent(MotionEvent) where default case is missing At GestureDetector.java
M D ST: Write to static field org.chromium.content.browser.ContentSettings.sAppCachePathIsSet from instance method org.chromium.content.browser.ContentSettings.setAppCachePath(String) At ContentSettings.java
-M M LI: Incorrect lazy initialization and update of static field org.chromium.base.SystemMonitor.sInstance in org.chromium.base.SystemMonitor.create(Context) At SystemMonitor.java
M M LI: Incorrect lazy initialization and update of static field org.chromium.content.browser.ContentVideoView.sContentVideoView in org.chromium.content.browser.ContentVideoView.createContentVideoView(int) At ContentVideoView.java
M M UG: org.chromium.content.browser.JavaBridgeReturnValuesTest$TestObject.getBooleanValue() is unsynchronized, org.chromium.content.browser.JavaBridgeReturnValuesTest$TestObject.setBooleanValue(boolean) is synchronized At JavaBridgeReturnValuesTest.java
M M UG: org.chromium.content.browser.JavaBridgeReturnValuesTest$TestObject.getStringValue() is unsynchronized, org.chromium.content.browser.JavaBridgeReturnValuesTest$TestObject.setStringValue(String) is synchronized At JavaBridgeReturnValuesTest.java
diff --git a/chrome/browser/extensions/event_router_forwarder_unittest.cc b/chrome/browser/extensions/event_router_forwarder_unittest.cc
index 1e14b98..975d986 100644
--- a/chrome/browser/extensions/event_router_forwarder_unittest.cc
+++ b/chrome/browser/extensions/event_router_forwarder_unittest.cc
@@ -6,7 +6,7 @@
#include "base/bind.h"
#include "base/message_loop.h"
-#include "base/system_monitor/system_monitor.h"
+#include "base/power_monitor/power_monitor.h"
#include "base/test/thread_test_helper.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/test/base/testing_browser_process.h"
@@ -92,9 +92,9 @@ class EventRouterForwarderTest : public testing::Test {
profile_manager_(
TestingBrowserProcess::GetGlobal()) {
#if defined(OS_MACOSX)
- base::SystemMonitor::AllocateSystemIOPorts();
+ base::PowerMonitor::AllocateSystemIOPorts();
#endif
- dummy.reset(new base::SystemMonitor);
+ dummy.reset(new base::PowerMonitor);
}
virtual void SetUp() {
@@ -118,7 +118,7 @@ class EventRouterForwarderTest : public testing::Test {
content::TestBrowserThread ui_thread_;
content::TestBrowserThread io_thread_;
TestingProfileManager profile_manager_;
- scoped_ptr<base::SystemMonitor> dummy;
+ scoped_ptr<base::PowerMonitor> dummy;
// Profiles are weak pointers, owned by ProfileManager in |browser_process_|.
TestingProfile* profile1_;
TestingProfile* profile2_;
diff --git a/chrome/browser/profiles/profile_manager_unittest.cc b/chrome/browser/profiles/profile_manager_unittest.cc
index c8f01c6..ebc8b58 100644
--- a/chrome/browser/profiles/profile_manager_unittest.cc
+++ b/chrome/browser/profiles/profile_manager_unittest.cc
@@ -9,7 +9,6 @@
#include "base/files/scoped_temp_dir.h"
#include "base/message_loop.h"
#include "base/path_service.h"
-#include "base/system_monitor/system_monitor.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "build/build_config.h"
@@ -98,10 +97,6 @@ class ProfileManagerTest : public testing::Test {
file_thread_(BrowserThread::FILE, &message_loop_),
io_thread_(local_state_.Get(), g_browser_process->policy_service(),
NULL, extension_event_router_forwarder_) {
-#if defined(OS_MACOSX)
- base::SystemMonitor::AllocateSystemIOPorts();
-#endif
- system_monitor_dummy_.reset(new base::SystemMonitor);
TestingBrowserProcess::GetGlobal()->SetIOThread(&io_thread_);
}
@@ -141,8 +136,6 @@ class ProfileManagerTest : public testing::Test {
content::TestBrowserThread file_thread_;
// IOThread is necessary for the creation of some services below.
IOThread io_thread_;
-
- scoped_ptr<base::SystemMonitor> system_monitor_dummy_;
};
TEST_F(ProfileManagerTest, GetProfile) {
diff --git a/chrome/nacl/nacl_exe_win_64.cc b/chrome/nacl/nacl_exe_win_64.cc
index 0a3f9e4..f0cb832 100644
--- a/chrome/nacl/nacl_exe_win_64.cc
+++ b/chrome/nacl/nacl_exe_win_64.cc
@@ -7,9 +7,9 @@
#include "base/hi_res_timer_manager.h"
#include "base/logging.h"
#include "base/message_loop.h"
+#include "base/power_monitor/power_monitor.h"
#include "base/process_util.h"
#include "base/string_util.h"
-#include "base/system_monitor/system_monitor.h"
#include "chrome/app/breakpad_win.h"
#include "chrome/common/chrome_result_codes.h"
#include "chrome/common/chrome_switches.h"
@@ -32,7 +32,7 @@ int NaClBrokerMain(const content::MainFunctionParams& parameters) {
MessageLoopForIO main_message_loop;
base::PlatformThread::SetName("CrNaClBrokerMain");
- base::SystemMonitor system_monitor;
+ base::PowerMonitor power_monitor;
HighResolutionTimerManager hi_res_timer_manager;
NaClBrokerListener listener;
diff --git a/chrome/nacl/nacl_main.cc b/chrome/nacl/nacl_main.cc
index e340b38..9b7a8c6 100644
--- a/chrome/nacl/nacl_main.cc
+++ b/chrome/nacl/nacl_main.cc
@@ -7,7 +7,7 @@
#include "base/command_line.h"
#include "base/hi_res_timer_manager.h"
#include "base/message_loop.h"
-#include "base/system_monitor/system_monitor.h"
+#include "base/power_monitor/power_monitor.h"
#include "chrome/common/chrome_result_codes.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/logging_chrome.h"
@@ -23,7 +23,7 @@ int NaClMain(const content::MainFunctionParams& parameters) {
MessageLoopForIO main_message_loop;
base::PlatformThread::SetName("CrNaClMain");
- base::SystemMonitor system_monitor;
+ base::PowerMonitor power_monitor;
HighResolutionTimerManager hi_res_timer_manager;
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
diff --git a/content/app/content_main_runner.cc b/content/app/content_main_runner.cc
index 6630446..256f78f 100644
--- a/content/app/content_main_runner.cc
+++ b/content/app/content_main_runner.cc
@@ -67,7 +67,7 @@
#include "base/mac/scoped_nsautorelease_pool.h"
#if !defined(OS_IOS)
#include "base/mach_ipc_mac.h"
-#include "base/system_monitor/system_monitor.h"
+#include "base/power_monitor/power_monitor.h"
#include "content/browser/mach_broker_mac.h"
#include "content/common/sandbox_init_mac.h"
#endif // !OS_IOS
@@ -651,9 +651,9 @@ class ContentMainRunnerImpl : public ContentMainRunner {
#if defined(OS_MACOSX) && !defined(OS_IOS)
// We need to allocate the IO Ports before the Sandbox is initialized or
- // the first instance of SystemMonitor is created.
+ // the first instance of PowerMonitor is created.
// It's important not to allocate the ports for processes which don't
- // register with the system monitor - see crbug.com/88867.
+ // register with the power monitor - see crbug.com/88867.
if (process_type.empty() ||
process_type == switches::kPluginProcess ||
process_type == switches::kRendererProcess ||
@@ -661,7 +661,7 @@ class ContentMainRunnerImpl : public ContentMainRunner {
process_type == switches::kWorkerProcess ||
(delegate &&
delegate->ProcessRegistersWithSystemProcess(process_type))) {
- base::SystemMonitor::AllocateSystemIOPorts();
+ base::PowerMonitor::AllocateSystemIOPorts();
}
if (!process_type.empty() &&
diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc
index e85329f..713cdbf 100644
--- a/content/browser/browser_main_loop.cc
+++ b/content/browser/browser_main_loop.cc
@@ -13,6 +13,8 @@
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
#include "base/pending_task.h"
+#include "base/power_monitor/power_monitor.h"
+#include "base/system_monitor/system_monitor.h"
#include "base/run_loop.h"
#include "base/string_number_conversions.h"
#include "base/threading/thread_restrictions.h"
@@ -367,6 +369,7 @@ void BrowserMainLoop::MainMessageLoopStart() {
InitializeMainThread();
system_monitor_.reset(new base::SystemMonitor);
+ power_monitor_.reset(new base::PowerMonitor);
hi_res_timer_manager_.reset(new HighResolutionTimerManager);
network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
audio_manager_.reset(media::AudioManager::Create());
diff --git a/content/browser/browser_main_loop.h b/content/browser/browser_main_loop.h
index 9118309..30442a6 100644
--- a/content/browser/browser_main_loop.h
+++ b/content/browser/browser_main_loop.h
@@ -14,6 +14,7 @@ class HighResolutionTimerManager;
namespace base {
class MessageLoop;
+class PowerMonitor;
class SystemMonitor;
}
@@ -95,6 +96,7 @@ class BrowserMainLoop {
// Members initialized in |MainMessageLoopStart()| ---------------------------
scoped_ptr<base::MessageLoop> main_message_loop_;
scoped_ptr<base::SystemMonitor> system_monitor_;
+ scoped_ptr<base::PowerMonitor> power_monitor_;
scoped_ptr<HighResolutionTimerManager> hi_res_timer_manager_;
scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
scoped_ptr<media::AudioManager> audio_manager_;
diff --git a/content/browser/gamepad/gamepad_test_helpers.cc b/content/browser/gamepad/gamepad_test_helpers.cc
index abf4187..e4db14c 100644
--- a/content/browser/gamepad/gamepad_test_helpers.cc
+++ b/content/browser/gamepad/gamepad_test_helpers.cc
@@ -4,7 +4,6 @@
#include "content/browser/gamepad/gamepad_test_helpers.h"
-#include "base/system_monitor/system_monitor.h"
#include "content/browser/gamepad/gamepad_service.h"
namespace content {
@@ -37,10 +36,6 @@ void MockGamepadDataFetcher::SetTestData(const WebKit::WebGamepads& new_data) {
}
GamepadTestHelper::GamepadTestHelper() {
-#if defined(OS_MACOSX)
- base::SystemMonitor::AllocateSystemIOPorts();
-#endif
- system_monitor_.reset(new base::SystemMonitor);
}
GamepadTestHelper::~GamepadTestHelper() {
diff --git a/content/browser/gamepad/gamepad_test_helpers.h b/content/browser/gamepad/gamepad_test_helpers.h
index 9abba01..6b97eda 100644
--- a/content/browser/gamepad/gamepad_test_helpers.h
+++ b/content/browser/gamepad/gamepad_test_helpers.h
@@ -12,10 +12,6 @@
#include "content/browser/gamepad/gamepad_data_fetcher.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebGamepads.h"
-namespace base {
-class SystemMonitor;
-}
-
namespace content {
class GamepadService;
@@ -60,8 +56,6 @@ class GamepadTestHelper {
// This must be constructed before the system monitor.
MessageLoop message_loop_;
- scoped_ptr<base::SystemMonitor> system_monitor_;
-
DISALLOW_COPY_AND_ASSIGN(GamepadTestHelper);
};
diff --git a/content/plugin/plugin_main.cc b/content/plugin/plugin_main.cc
index 971e308..2f0817e 100644
--- a/content/plugin/plugin_main.cc
+++ b/content/plugin/plugin_main.cc
@@ -13,7 +13,7 @@
#include "base/hi_res_timer_manager.h"
#include "base/message_loop.h"
#include "base/string_util.h"
-#include "base/system_monitor/system_monitor.h"
+#include "base/power_monitor/power_monitor.h"
#include "base/threading/platform_thread.h"
#include "content/common/child_process.h"
#include "content/plugin/plugin_thread.h"
@@ -55,7 +55,7 @@ int PluginMain(const MainFunctionParams& parameters) {
MessageLoop main_message_loop(MessageLoop::TYPE_UI);
base::PlatformThread::SetName("CrPluginMain");
- base::SystemMonitor system_monitor;
+ base::PowerMonitor power_monitor;
HighResolutionTimerManager high_resolution_timer_manager;
const CommandLine& parsed_command_line = parameters.command_line;
diff --git a/content/public/test/browser_test_base.cc b/content/public/test/browser_test_base.cc
index 04d6ff0..4d44268 100644
--- a/content/public/test/browser_test_base.cc
+++ b/content/public/test/browser_test_base.cc
@@ -13,7 +13,7 @@
#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
-#include "base/system_monitor/system_monitor.h"
+#include "base/power_monitor/power_monitor.h"
#endif
#if defined(OS_ANDROID)
@@ -52,7 +52,7 @@ extern int BrowserMain(const content::MainFunctionParams&);
BrowserTestBase::BrowserTestBase() {
#if defined(OS_MACOSX)
base::mac::SetOverrideAmIBundled(true);
- base::SystemMonitor::AllocateSystemIOPorts();
+ base::PowerMonitor::AllocateSystemIOPorts();
#endif
#if defined(OS_POSIX)
diff --git a/content/renderer/renderer_main.cc b/content/renderer/renderer_main.cc
index 7cfd127..c154e69c 100644
--- a/content/renderer/renderer_main.cc
+++ b/content/renderer/renderer_main.cc
@@ -17,9 +17,9 @@
#include "base/metrics/stats_counters.h"
#include "base/path_service.h"
#include "base/pending_task.h"
+#include "base/power_monitor/power_monitor.h"
#include "base/process_util.h"
#include "base/string_util.h"
-#include "base/system_monitor/system_monitor.h"
#include "base/threading/platform_thread.h"
#include "base/time.h"
#include "content/common/pepper_plugin_registry.h"
@@ -161,7 +161,7 @@ int RendererMain(const MainFunctionParams& parameters) {
base::PlatformThread::SetName("CrRendererMain");
- base::SystemMonitor system_monitor;
+ base::PowerMonitor power_monitor;
HighResolutionTimerManager hi_res_timer_manager;
platform.PlatformInitialize();
diff --git a/content/utility/utility_main.cc b/content/utility/utility_main.cc
index 549af2c..8257c09 100644
--- a/content/utility/utility_main.cc
+++ b/content/utility/utility_main.cc
@@ -5,7 +5,7 @@
#include "base/command_line.h"
#include "base/hi_res_timer_manager.h"
#include "base/message_loop.h"
-#include "base/system_monitor/system_monitor.h"
+#include "base/power_monitor/power_monitor.h"
#include "base/threading/platform_thread.h"
#include "content/common/child_process.h"
#include "content/public/common/content_switches.h"
@@ -25,7 +25,7 @@ int UtilityMain(const MainFunctionParams& parameters) {
MessageLoop main_message_loop;
base::PlatformThread::SetName("CrUtilityMain");
- base::SystemMonitor system_monitor;
+ base::PowerMonitor power_monitor;
HighResolutionTimerManager hi_res_timer_manager;
#if defined(OS_LINUX)
diff --git a/content/worker/worker_main.cc b/content/worker/worker_main.cc
index 192cc57..981d0a5 100644
--- a/content/worker/worker_main.cc
+++ b/content/worker/worker_main.cc
@@ -6,8 +6,8 @@
#include "base/command_line.h"
#include "base/hi_res_timer_manager.h"
#include "base/message_loop.h"
+#include "base/power_monitor/power_monitor.h"
#include "base/string_util.h"
-#include "base/system_monitor/system_monitor.h"
#include "base/threading/platform_thread.h"
#include "content/common/child_process.h"
#include "content/public/common/main_function_params.h"
@@ -30,7 +30,7 @@ int WorkerMain(const MainFunctionParams& parameters) {
MessageLoop main_message_loop;
base::PlatformThread::SetName("CrWorkerMain");
- base::SystemMonitor system_monitor;
+ base::PowerMonitor power_monitor;
HighResolutionTimerManager hi_res_timer_manager;
#if defined(OS_WIN)
diff --git a/net/http/http_network_layer.h b/net/http/http_network_layer.h
index 63507b4..4b41b71 100644
--- a/net/http/http_network_layer.h
+++ b/net/http/http_network_layer.h
@@ -9,7 +9,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "base/system_monitor/system_monitor.h"
+#include "base/power_monitor/power_observer.h"
#include "base/threading/non_thread_safe.h"
#include "net/base/net_export.h"
#include "net/http/http_transaction_factory.h"
@@ -20,7 +20,7 @@ class HttpNetworkSession;
class NET_EXPORT HttpNetworkLayer
: public HttpTransactionFactory,
- public base::SystemMonitor::PowerObserver,
+ public base::PowerObserver,
NON_EXPORTED_BASE(public base::NonThreadSafe) {
public:
// Construct a HttpNetworkLayer with an existing HttpNetworkSession which
@@ -47,7 +47,7 @@ class NET_EXPORT HttpNetworkLayer
virtual HttpCache* GetCache() OVERRIDE;
virtual HttpNetworkSession* GetSession() OVERRIDE;
- // base::SystemMonitor::PowerObserver methods:
+ // base::PowerObserver methods:
virtual void OnSuspend() OVERRIDE;
virtual void OnResume() OVERRIDE;
diff --git a/net/url_request/url_request_job.cc b/net/url_request/url_request_job.cc
index 3c470a4..752c50f 100644
--- a/net/url_request/url_request_job.cc
+++ b/net/url_request/url_request_job.cc
@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/message_loop.h"
+#include "base/power_monitor/power_monitor.h"
#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "net/base/auth.h"
@@ -34,9 +35,9 @@ URLRequestJob::URLRequestJob(URLRequest* request,
deferred_redirect_status_code_(-1),
network_delegate_(network_delegate),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
- base::SystemMonitor* system_monitor = base::SystemMonitor::Get();
- if (system_monitor)
- base::SystemMonitor::Get()->AddPowerObserver(this);
+ base::PowerMonitor* power_monitor = base::PowerMonitor::Get();
+ if (power_monitor)
+ power_monitor->AddObserver(this);
}
void URLRequestJob::SetUpload(UploadDataStream* upload) {
@@ -229,9 +230,9 @@ void URLRequestJob::NotifyURLRequestDestroyed() {
}
URLRequestJob::~URLRequestJob() {
- base::SystemMonitor* system_monitor = base::SystemMonitor::Get();
- if (system_monitor)
- base::SystemMonitor::Get()->RemovePowerObserver(this);
+ base::PowerMonitor* power_monitor = base::PowerMonitor::Get();
+ if (power_monitor)
+ power_monitor->RemoveObserver(this);
}
void URLRequestJob::NotifyCertificateRequested(
diff --git a/net/url_request/url_request_job.h b/net/url_request/url_request_job.h
index ae95673..bd78ef5 100644
--- a/net/url_request/url_request_job.h
+++ b/net/url_request/url_request_job.h
@@ -11,7 +11,8 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
-#include "base/system_monitor/system_monitor.h"
+#include "base/message_loop.h"
+#include "base/power_monitor/power_observer.h"
#include "googleurl/src/gurl.h"
#include "net/base/filter.h"
#include "net/base/host_port_pair.h"
@@ -38,8 +39,9 @@ class UploadDataStream;
class URLRequestStatus;
class X509Certificate;
-class NET_EXPORT URLRequestJob : public base::RefCounted<URLRequestJob>,
- public base::SystemMonitor::PowerObserver {
+class NET_EXPORT URLRequestJob
+ : public base::RefCounted<URLRequestJob>,
+ public base::PowerObserver {
public:
explicit URLRequestJob(URLRequest* request,
NetworkDelegate* network_delegate);
@@ -195,7 +197,7 @@ class NET_EXPORT URLRequestJob : public base::RefCounted<URLRequestJob>,
// See url_request.h for details.
virtual HostPortPair GetSocketAddress() const;
- // base::SystemMonitor::PowerObserver methods:
+ // base::PowerObserver methods:
// We invoke URLRequestJob::Kill on suspend (crbug.com/4606).
virtual void OnSuspend() OVERRIDE;
diff --git a/testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java b/testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java
index 21b0f85..d15d04e 100644
--- a/testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java
+++ b/testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java
@@ -13,7 +13,7 @@ import android.util.Log;
import org.chromium.base.ChromiumActivity;
import org.chromium.base.PathUtils;
-import org.chromium.base.SystemMonitor;
+import org.chromium.base.PowerMonitor;
import java.io.File;
@@ -43,7 +43,7 @@ public class ChromeNativeTestActivity extends ChromiumActivity {
PathUtils.setPrivateDataDirectorySuffix("chrome");
// Needed by system_monitor_unittest.cc
- SystemMonitor.createForTests(this);
+ PowerMonitor.createForTests(this);
loadLibrary();
diff --git a/webkit/blob/blob_url_request_job.h b/webkit/blob/blob_url_request_job.h
index e24a491..00463be 100644
--- a/webkit/blob/blob_url_request_job.h
+++ b/webkit/blob/blob_url_request_job.h
@@ -5,6 +5,8 @@
#ifndef WEBKIT_BLOB_BLOB_URL_REQUEST_JOB_H_
#define WEBKIT_BLOB_BLOB_URL_REQUEST_JOB_H_
+#include <map>
+
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/platform_file.h"