summaryrefslogtreecommitdiffstats
path: root/base/system_monitor
diff options
context:
space:
mode:
authorkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-14 23:49:03 +0000
committerkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-14 23:49:03 +0000
commit5dd4a2c8d4c8cb889069388fcf0105962b99c50d (patch)
tree26608e09708bfcf4bf7c0d2fa06b3077e03d1140 /base/system_monitor
parentcb36dc783d391f63a26a3191f9a274f4acaed8bf (diff)
downloadchromium_src-5dd4a2c8d4c8cb889069388fcf0105962b99c50d.zip
chromium_src-5dd4a2c8d4c8cb889069388fcf0105962b99c50d.tar.gz
chromium_src-5dd4a2c8d4c8cb889069388fcf0105962b99c50d.tar.bz2
Revert 109960 - Send WM_DEVICECHANGE message through SystemMonitor
WM_DEVICECHANGE is sent when there's been a change to devices or the computer; specifically when a USB device is connected or disconnected. This is intended for use in support of Gamepads for more performant polling and connect/disconnect testing. Currently only on Windows, though seems reasonable to add for other platforms in the future. BUG=79050 Review URL: http://codereview.chromium.org/8523021 TBR=scottmg@chromium.org Review URL: http://codereview.chromium.org/8528044 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109979 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/system_monitor')
-rw-r--r--base/system_monitor/system_monitor.cc37
-rw-r--r--base/system_monitor/system_monitor.h23
-rw-r--r--base/system_monitor/system_monitor_unittest.cc47
3 files changed, 12 insertions, 95 deletions
diff --git a/base/system_monitor/system_monitor.cc b/base/system_monitor/system_monitor.cc
index 28fc70b..5131fbf 100644
--- a/base/system_monitor/system_monitor.cc
+++ b/base/system_monitor/system_monitor.cc
@@ -19,9 +19,7 @@ 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>()),
+ : observer_list_(new ObserverListThreadSafe<PowerObserver>()),
battery_in_use_(false),
suspended_(false) {
DCHECK(!g_system_monitor);
@@ -79,47 +77,28 @@ void SystemMonitor::ProcessPowerMessage(PowerEvent event_id) {
}
}
-void SystemMonitor::ProcessDevicesChanged() {
- NotifyDevicesChanged();
+void SystemMonitor::AddObserver(PowerObserver* obs) {
+ observer_list_->AddObserver(obs);
}
-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);
-}
-
-void SystemMonitor::RemoveDevicesChangedObserver(DevicesChangedObserver* obs) {
- devices_changed_observer_list_->RemoveObserver(obs);
-}
-
-void SystemMonitor::NotifyDevicesChanged() {
- DVLOG(1) << "DevicesChanged";
- devices_changed_observer_list_->Notify(
- &DevicesChangedObserver::OnDevicesChanged);
+void SystemMonitor::RemoveObserver(PowerObserver* obs) {
+ observer_list_->RemoveObserver(obs);
}
void SystemMonitor::NotifyPowerStateChange() {
DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off")
<< " battery";
- power_observer_list_->Notify(&PowerObserver::OnPowerStateChange,
- BatteryPower());
+ observer_list_->Notify(&PowerObserver::OnPowerStateChange, BatteryPower());
}
void SystemMonitor::NotifySuspend() {
DVLOG(1) << "Power Suspending";
- power_observer_list_->Notify(&PowerObserver::OnSuspend);
+ observer_list_->Notify(&PowerObserver::OnSuspend);
}
void SystemMonitor::NotifyResume() {
DVLOG(1) << "Power Resuming";
- power_observer_list_->Notify(&PowerObserver::OnResume);
+ observer_list_->Notify(&PowerObserver::OnResume);
}
void SystemMonitor::BatteryCheck() {
diff --git a/base/system_monitor/system_monitor.h b/base/system_monitor/system_monitor.h
index 7684523..c779994 100644
--- a/base/system_monitor/system_monitor.h
+++ b/base/system_monitor/system_monitor.h
@@ -90,26 +90,15 @@ class BASE_EXPORT SystemMonitor {
virtual ~PowerObserver() {}
};
- class BASE_EXPORT DevicesChangedObserver {
- public:
- // Notification that the devices connected to the system have changed.
- virtual void OnDevicesChanged() {}
-
- protected:
- virtual ~DevicesChangedObserver() {}
- };
-
// 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);
+ void AddObserver(PowerObserver* 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);
+ void RemoveObserver(PowerObserver* obs);
#if defined(OS_WIN)
// Windows-specific handling of a WM_POWERBROADCAST message.
@@ -121,9 +110,6 @@ class BASE_EXPORT SystemMonitor {
// Cross-platform handling of a power event.
void ProcessPowerMessage(PowerEvent event_id);
- // Cross-platform handling of a device change event.
- void ProcessDevicesChanged();
-
private:
#if defined(OS_MACOSX)
void PlatformInit();
@@ -140,14 +126,11 @@ class BASE_EXPORT SystemMonitor {
void BatteryCheck();
// Functions to trigger notifications.
- void NotifyDevicesChanged();
void NotifyPowerStateChange();
void NotifySuspend();
void NotifyResume();
- scoped_refptr<ObserverListThreadSafe<PowerObserver> > power_observer_list_;
- scoped_refptr<ObserverListThreadSafe<DevicesChangedObserver> >
- devices_changed_observer_list_;
+ scoped_refptr<ObserverListThreadSafe<PowerObserver> > observer_list_;
bool battery_in_use_;
bool suspended_;
diff --git a/base/system_monitor/system_monitor_unittest.cc b/base/system_monitor/system_monitor_unittest.cc
index 1d5d6af..f4a4e73 100644
--- a/base/system_monitor/system_monitor_unittest.cc
+++ b/base/system_monitor/system_monitor_unittest.cc
@@ -55,7 +55,7 @@ TEST(SystemMonitor, PowerNotifications) {
SystemMonitor system_monitor;
PowerTest test[kObservers];
for (int index = 0; index < kObservers; ++index)
- system_monitor.AddPowerObserver(&test[index]);
+ system_monitor.AddObserver(&test[index]);
// Send a bunch of power changes. Since the battery power hasn't
// actually changed, we shouldn't get notifications.
@@ -90,49 +90,4 @@ TEST(SystemMonitor, PowerNotifications) {
EXPECT_EQ(test[0].resumes(), 1);
}
-class DevicesChangedTest : public SystemMonitor::DevicesChangedObserver {
- public:
- DevicesChangedTest()
- : changes_(0) {
- }
-
- // DevicesChangedObserver callbacks.
- virtual void OnDevicesChanged() OVERRIDE {
- changes_++;
- }
-
- // Test status counts.
- int changes() const { return changes_; }
-
- private:
- int changes_; // Count of OnDevicesChanged notifications.
-
- DISALLOW_COPY_AND_ASSIGN(DevicesChangedTest);
-};
-
-TEST(SystemMonitor, DeviceChangeNotifications) {
- const int kObservers = 5;
-
- // Initialize a message loop for this to run on.
- MessageLoop loop;
-
-#if defined(OS_MACOSX)
- SystemMonitor::AllocateSystemIOPorts();
-#endif
-
- SystemMonitor system_monitor;
- DevicesChangedTest test[kObservers];
- for (int index = 0; index < kObservers; ++index)
- system_monitor.AddDevicesChangedObserver(&test[index]);
-
- system_monitor.ProcessDevicesChanged();
- loop.RunAllPending();
- EXPECT_EQ(1, test[0].changes());
-
- system_monitor.ProcessDevicesChanged();
- system_monitor.ProcessDevicesChanged();
- loop.RunAllPending();
- EXPECT_EQ(3, test[0].changes());
-}
-
} // namespace base