diff options
author | wjia@chromium.org <wjia@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-31 01:16:35 +0000 |
---|---|---|
committer | wjia@chromium.org <wjia@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-31 01:16:35 +0000 |
commit | 515be83a491239753e32ddb49ee28871770964a2 (patch) | |
tree | 9040d901dfa6645769f0f9da6af6976ac5cb6f34 | |
parent | 166a8660822de18d093724318c2fde2e3c000c58 (diff) | |
download | chromium_src-515be83a491239753e32ddb49ee28871770964a2.zip chromium_src-515be83a491239753e32ddb49ee28871770964a2.tar.gz chromium_src-515be83a491239753e32ddb49ee28871770964a2.tar.bz2 |
add device type as an argument in OnDevicesChanged.
This allows DevicesChangedObserver to listen to desired events, instead of being woken up by change of uninterested devices.
BUG=137799
Review URL: https://chromiumcodereview.appspot.com/10836004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149103 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/system_monitor/system_monitor.cc | 10 | ||||
-rw-r--r-- | base/system_monitor/system_monitor.h | 13 | ||||
-rw-r--r-- | base/system_monitor/system_monitor_unittest.cc | 9 | ||||
-rw-r--r-- | base/test/mock_devices_changed_observer.h | 3 | ||||
-rw-r--r-- | content/browser/gamepad/gamepad_provider.cc | 2 | ||||
-rw-r--r-- | content/browser/gamepad/gamepad_provider.h | 2 | ||||
-rw-r--r-- | content/browser/system_message_window_win.cc | 2 | ||||
-rw-r--r-- | content/browser/system_message_window_win_unittest.cc | 2 |
8 files changed, 26 insertions, 17 deletions
diff --git a/base/system_monitor/system_monitor.cc b/base/system_monitor/system_monitor.cc index 6db1db5..22f91d7 100644 --- a/base/system_monitor/system_monitor.cc +++ b/base/system_monitor/system_monitor.cc @@ -83,8 +83,8 @@ void SystemMonitor::ProcessPowerMessage(PowerEvent event_id) { } } -void SystemMonitor::ProcessDevicesChanged() { - NotifyDevicesChanged(); +void SystemMonitor::ProcessDevicesChanged(DeviceType device_type) { + NotifyDevicesChanged(device_type); } void SystemMonitor::ProcessMediaDeviceAttached( @@ -136,10 +136,10 @@ void SystemMonitor::RemoveDevicesChangedObserver(DevicesChangedObserver* obs) { devices_changed_observer_list_->RemoveObserver(obs); } -void SystemMonitor::NotifyDevicesChanged() { - DVLOG(1) << "DevicesChanged"; +void SystemMonitor::NotifyDevicesChanged(DeviceType device_type) { + DVLOG(1) << "DevicesChanged with device type " << device_type; devices_changed_observer_list_->Notify( - &DevicesChangedObserver::OnDevicesChanged); + &DevicesChangedObserver::OnDevicesChanged, device_type); } void SystemMonitor::NotifyMediaDeviceAttached( diff --git a/base/system_monitor/system_monitor.h b/base/system_monitor/system_monitor.h index 359feb6..e05df74 100644 --- a/base/system_monitor/system_monitor.h +++ b/base/system_monitor/system_monitor.h @@ -51,6 +51,13 @@ class BASE_EXPORT SystemMonitor { 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. + DEVTYPE_VIDEO_CAPTURE, // Video capture device, e.g., webcam. + DEVTYPE_UNKNOWN, // Other devices. + }; + // Type of location data to identify a currently attached media device. enum MediaDeviceType { TYPE_PATH, // FilePath::StringType, e.g. a mount point. @@ -140,7 +147,7 @@ class BASE_EXPORT SystemMonitor { public: // Notification that the devices connected to the system have changed. // This is only implemented on Windows currently. - virtual void OnDevicesChanged() {} + virtual void OnDevicesChanged(DeviceType device_type) {} // When a media device is attached or detached, one of these two events // is triggered. @@ -178,7 +185,7 @@ class BASE_EXPORT SystemMonitor { void ProcessPowerMessage(PowerEvent event_id); // Cross-platform handling of a device change event. - void ProcessDevicesChanged(); + void ProcessDevicesChanged(DeviceType device_type); void ProcessMediaDeviceAttached(const std::string& id, const string16& name, MediaDeviceType type, @@ -204,7 +211,7 @@ class BASE_EXPORT SystemMonitor { void BatteryCheck(); // Functions to trigger notifications. - void NotifyDevicesChanged(); + void NotifyDevicesChanged(DeviceType device_type); void NotifyMediaDeviceAttached(const std::string& id, const string16& name, MediaDeviceType type, diff --git a/base/system_monitor/system_monitor_unittest.cc b/base/system_monitor/system_monitor_unittest.cc index 7c5f375..d3a99fb 100644 --- a/base/system_monitor/system_monitor_unittest.cc +++ b/base/system_monitor/system_monitor_unittest.cc @@ -118,7 +118,8 @@ TEST_F(SystemMonitorTest, DeviceChangeNotifications) { for (int index = 0; index < kObservers; ++index) { system_monitor_->AddDevicesChangedObserver(&observers[index]); - EXPECT_CALL(observers[index], OnDevicesChanged()) + EXPECT_CALL(observers[index], + OnDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN)) .Times(3) .InSequence(mock_sequencer[index]); EXPECT_CALL(observers[index], @@ -133,11 +134,11 @@ TEST_F(SystemMonitorTest, DeviceChangeNotifications) { .InSequence(mock_sequencer[index]); } - system_monitor_->ProcessDevicesChanged(); + system_monitor_->ProcessDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN); message_loop_.RunAllPending(); - system_monitor_->ProcessDevicesChanged(); - system_monitor_->ProcessDevicesChanged(); + system_monitor_->ProcessDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN); + system_monitor_->ProcessDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN); message_loop_.RunAllPending(); system_monitor_->ProcessMediaDeviceAttached( diff --git a/base/test/mock_devices_changed_observer.h b/base/test/mock_devices_changed_observer.h index b2f46c7..10f8840 100644 --- a/base/test/mock_devices_changed_observer.h +++ b/base/test/mock_devices_changed_observer.h @@ -18,7 +18,8 @@ class MockDevicesChangedObserver MockDevicesChangedObserver(); ~MockDevicesChangedObserver(); - MOCK_METHOD0(OnDevicesChanged, void()); + MOCK_METHOD1(OnDevicesChanged, + void(base::SystemMonitor::DeviceType device_type)); MOCK_METHOD4(OnMediaDeviceAttached, void(const std::string& id, const string16& name, diff --git a/content/browser/gamepad/gamepad_provider.cc b/content/browser/gamepad/gamepad_provider.cc index 5476620..507c704 100644 --- a/content/browser/gamepad/gamepad_provider.cc +++ b/content/browser/gamepad/gamepad_provider.cc @@ -91,7 +91,7 @@ void GamepadProvider::Resume() { base::Bind(&GamepadProvider::ScheduleDoPoll, Unretained(this))); } -void GamepadProvider::OnDevicesChanged() { +void GamepadProvider::OnDevicesChanged(base::SystemMonitor::DeviceType type) { base::AutoLock lock(devices_changed_lock_); devices_changed_ = true; } diff --git a/content/browser/gamepad/gamepad_provider.h b/content/browser/gamepad/gamepad_provider.h index 3579028..22c39c5 100644 --- a/content/browser/gamepad/gamepad_provider.h +++ b/content/browser/gamepad/gamepad_provider.h @@ -40,7 +40,7 @@ class CONTENT_EXPORT GamepadProvider : void Resume(); // base::SystemMonitor::DevicesChangedObserver implementation. - virtual void OnDevicesChanged() OVERRIDE; + virtual void OnDevicesChanged(base::SystemMonitor::DeviceType type) OVERRIDE; private: diff --git a/content/browser/system_message_window_win.cc b/content/browser/system_message_window_win.cc index 1f6fcb0..ca31feb 100644 --- a/content/browser/system_message_window_win.cc +++ b/content/browser/system_message_window_win.cc @@ -41,7 +41,7 @@ LRESULT SystemMessageWindowWin::OnDeviceChange(UINT event_type, DWORD data) { base::SystemMonitor* monitor = base::SystemMonitor::Get(); switch (event_type) { case DBT_DEVNODES_CHANGED: - monitor->ProcessDevicesChanged(); + monitor->ProcessDevicesChanged(base::SystemMonitor::DEVTYPE_UNKNOWN); break; } return TRUE; diff --git a/content/browser/system_message_window_win_unittest.cc b/content/browser/system_message_window_win_unittest.cc index d8eb7b7..1c03de5 100644 --- a/content/browser/system_message_window_win_unittest.cc +++ b/content/browser/system_message_window_win_unittest.cc @@ -30,7 +30,7 @@ class SystemMessageWindowWinTest : public testing::Test { }; TEST_F(SystemMessageWindowWinTest, DevicesChanged) { - EXPECT_CALL(observer_, OnDevicesChanged()).Times(1); + EXPECT_CALL(observer_, OnDevicesChanged(testing::_)).Times(1); window_.OnDeviceChange(DBT_DEVNODES_CHANGED, NULL); message_loop_.RunAllPending(); } |