Commit 515be83a authored by wjia@chromium.org's avatar wjia@chromium.org

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
parent 166a8660
......@@ -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(
......
......@@ -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,
......
......@@ -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(
......
......@@ -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,
......
......@@ -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;
}
......
......@@ -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:
......
......@@ -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;
......
......@@ -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();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment