Chromium Code Reviews| Index: chrome/browser/system_monitor/removable_device_notifications_window_win.cc |
| diff --git a/chrome/browser/system_monitor/removable_device_notifications_window_win.cc b/chrome/browser/system_monitor/removable_device_notifications_window_win.cc |
| index 74250b9ba9b7fcdbd60b32d7ce2615fcc7342c4d..8c6f2d0d649ada053bf41334c395ab254294211c 100644 |
| --- a/chrome/browser/system_monitor/removable_device_notifications_window_win.cc |
| +++ b/chrome/browser/system_monitor/removable_device_notifications_window_win.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/file_path.h" |
| #include "base/win/wrapped_window_proc.h" |
| #include "chrome/browser/system_monitor/media_storage_util.h" |
| +#include "chrome/browser/system_monitor/removable_device_constants.h" |
| using base::SystemMonitor; |
| using base::win::WrappedWindowProc; |
| @@ -29,17 +30,21 @@ RemovableDeviceNotificationsWindowWin* |
| // static |
| RemovableDeviceNotificationsWindowWin* |
| RemovableDeviceNotificationsWindowWin::Create() { |
| - return new RemovableDeviceNotificationsWindowWin(new VolumeMountWatcherWin()); |
| + return new RemovableDeviceNotificationsWindowWin( |
| + new VolumeMountWatcherWin(), new PortableDeviceWatcherWin()); |
| } |
| RemovableDeviceNotificationsWindowWin:: |
| RemovableDeviceNotificationsWindowWin( |
| - VolumeMountWatcherWin* volume_mount_watcher) |
| + VolumeMountWatcherWin* volume_mount_watcher, |
| + PortableDeviceWatcherWin* portable_device_watcher) |
| : window_class_(0), |
| instance_(NULL), |
| window_(NULL), |
| - volume_mount_watcher_(volume_mount_watcher) { |
| + volume_mount_watcher_(volume_mount_watcher), |
| + portable_device_watcher_(portable_device_watcher) { |
| DCHECK(volume_mount_watcher_); |
| + DCHECK(portable_device_watcher_); |
| DCHECK(!g_removable_device_notifications_window_win); |
| g_removable_device_notifications_window_win = this; |
| } |
| @@ -65,6 +70,7 @@ RemovableDeviceNotificationsWindowWin::GetInstance() { |
| void RemovableDeviceNotificationsWindowWin::Init() { |
| volume_mount_watcher_->Init(); |
| + portable_device_watcher_->Init(); |
| WNDCLASSEX window_class; |
| base::win::InitializeWindowClass( |
| @@ -129,6 +135,21 @@ bool RemovableDeviceNotificationsWindowWin::GetDeviceInfoForPath( |
| // static |
| LRESULT CALLBACK RemovableDeviceNotificationsWindowWin::WndProcThunk( |
| HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { |
| + static HDEVNOTIFY hDeviceNotify; |
|
Peter Kasting
2012/10/19 21:31:12
Overriding the WndProc and then looking for specif
kmadhusu
2012/10/23 23:44:17
Done. I used SystemMessageWindowWin::DeviceNotific
|
| + if (message == WM_CREATE) { |
| + GUID guidDevInterface = GUID_NULL; |
| + HRESULT hr = CLSIDFromString(kWPDDevInterfaceGUID, &guidDevInterface); |
| + if (SUCCEEDED(hr)) { |
| + DEV_BROADCAST_DEVICEINTERFACE db = {0}; |
|
Peter Kasting
2012/10/19 21:31:12
Nit: Or just:
DEV_BROADCAST_DEVICEINTERFACE
kmadhusu
2012/10/23 23:44:17
Done.
|
| + db.dbcc_size = sizeof(db); |
| + db.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; |
| + db.dbcc_classguid = guidDevInterface; |
| + hDeviceNotify = RegisterDeviceNotification(hwnd, &db, |
| + DEVICE_NOTIFY_WINDOW_HANDLE); |
| + } |
| + } else if (message == WM_CLOSE) { |
| + UnregisterDeviceNotification(hDeviceNotify); |
| + } |
| RemovableDeviceNotificationsWindowWin* msg_wnd = |
| reinterpret_cast<RemovableDeviceNotificationsWindowWin*>( |
| GetWindowLongPtr(hwnd, GWLP_USERDATA)); |
| @@ -153,13 +174,21 @@ LRESULT CALLBACK RemovableDeviceNotificationsWindowWin::WndProc( |
| bool RemovableDeviceNotificationsWindowWin::GetDeviceInfo( |
| const FilePath& device_path, string16* device_location, |
| std::string* unique_id, string16* name, bool* removable) { |
| - return volume_mount_watcher_->GetDeviceInfo(device_path, device_location, |
| - unique_id, name, removable); |
| + bool result = volume_mount_watcher_->GetDeviceInfo(device_path, |
|
Peter Kasting
2012/10/19 21:31:12
Nit: Shorter:
return volume_mount_watcher_->Get
kmadhusu
2012/10/23 23:44:17
Done.
|
| + device_location, unique_id, |
| + name, removable); |
| + if (!result) { |
| + result = portable_device_watcher_->GetDeviceInfo(device_path, |
| + device_location, unique_id, |
| + name, removable); |
| + } |
| + return result; |
| } |
| void RemovableDeviceNotificationsWindowWin::OnDeviceChange(UINT event_type, |
| LPARAM data) { |
| volume_mount_watcher_->OnWindowMessage(event_type, data); |
| + portable_device_watcher_->OnWindowMessage(event_type, data); |
| } |
| } // namespace chrome |