Chromium Code Reviews| Index: chrome/browser/media_gallery/media_device_notifications_window_win.cc |
| diff --git a/chrome/browser/media_gallery/media_device_notifications_window_win.cc b/chrome/browser/media_gallery/media_device_notifications_window_win.cc |
| index a1d1ccb05480fb2f0a1d4995d3b83732554ff2dd..75b5a53123a0cb23142710d3e90db98fd6e7e230 100644 |
| --- a/chrome/browser/media_gallery/media_device_notifications_window_win.cc |
| +++ b/chrome/browser/media_gallery/media_device_notifications_window_win.cc |
| @@ -6,7 +6,7 @@ |
| #include <windows.h> |
| #include <dbt.h> |
| - |
| +#include <ObjBase.h> |
| #include <string> |
| #include "base/file_path.h" |
| @@ -22,6 +22,9 @@ namespace { |
| const wchar_t WindowClassName[] = L"Chrome_MediaDeviceNotificationWindow"; |
| +// The WPD device interface GUID |
| +const wchar_t WPDDevInterfaceGUID[] = L"{6ac27878-a6fa-4155-ba85-f98f491d4f33}"; |
| + |
| LRESULT GetVolumeName(LPCWSTR drive, |
| LPWSTR volume_name, |
| unsigned int volume_name_len) { |
| @@ -92,21 +95,37 @@ LRESULT MediaDeviceNotificationsWindowWin::OnDeviceChange(UINT event_type, |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| switch (event_type) { |
| case DBT_DEVICEARRIVAL: { |
| - DWORD unitmask = GetVolumeBitMaskFromBroadcastHeader(data); |
| - for (int i = 0; unitmask; ++i, unitmask >>= 1) { |
| - if (unitmask & 0x01) { |
| - FilePath::StringType drive(L"_:\\"); |
| - drive[0] = L'A' + i; |
| - WCHAR volume_name[MAX_PATH + 1]; |
| - if ((*volume_name_func_)(drive.c_str(), volume_name, MAX_PATH + 1)) { |
| - BrowserThread::PostTask( |
| - BrowserThread::FILE, FROM_HERE, |
| - base::Bind(&MediaDeviceNotificationsWindowWin:: |
| - CheckDeviceTypeOnFileThread, this, i, |
| - FilePath::StringType(volume_name), FilePath(drive))); |
| + PDEV_BROADCAST_HDR dev_broadcast_hdr = |
| + reinterpret_cast<PDEV_BROADCAST_HDR>(data); |
| + if (dev_broadcast_hdr->dbch_devicetype == DBT_DEVTYP_VOLUME) { |
| + DWORD unitmask = GetVolumeBitMaskFromBroadcastHeader(data); |
| + for (int i = 0; unitmask; ++i, unitmask >>= 1) { |
| + if (unitmask & 0x01) { |
| + FilePath::StringType drive(L"_:\\"); |
| + drive[0] = L'A' + i; |
| + WCHAR volume_name[MAX_PATH + 1]; |
| + if ((*volume_name_func_)(drive.c_str(), volume_name, MAX_PATH + 1)) { |
| + BrowserThread::PostTask( |
| + BrowserThread::FILE, FROM_HERE, |
| + base::Bind(&MediaDeviceNotificationsWindowWin:: |
| + CheckDeviceTypeOnFileThread, this, i, |
| + FilePath::StringType(volume_name), FilePath(drive))); |
| + } |
| } |
| } |
| + } |
| +#if defined(DBT_DEVTYP_DEVICEINTERFACE) |
| + else if (dev_broadcast_hdr != NULL && |
| + dev_broadcast_hdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) { |
| + GUID guidDevInterface = GUID_NULL; |
| + CLSIDFromString(WPDDevInterfaceGUID, &guidDevInterface); |
| + DEV_BROADCAST_DEVICEINTERFACE* pdbi = |
| + reinterpret_cast<DEV_BROADCAST_DEVICEINTERFACE*>(data); |
| + if (!IsEqualGUID(pdbi->dbcc_classguid, guidDevInterface)) |
| + return 0; |
| + ProcessMediaDeviceAttachedOnUIThread(1, FilePath::StringType(pdbi->dbcc_name), FilePath(pdbi->dbcc_name)); |
| } |
| +#endif |
| break; |
| } |
| case DBT_DEVICEREMOVECOMPLETE: { |
| @@ -117,6 +136,7 @@ LRESULT MediaDeviceNotificationsWindowWin::OnDeviceChange(UINT event_type, |
| monitor->ProcessMediaDeviceDetached(i); |
| } |
| } |
| + // FIX for MTP Device. |
| break; |
| } |
| } |
| @@ -169,6 +189,21 @@ LRESULT CALLBACK MediaDeviceNotificationsWindowWin::WndProcThunk( |
| UINT message, |
| WPARAM wparam, |
| LPARAM lparam) { |
| +#if defined(DBT_DEVTYP_DEVICEINTERFACE) && defined(DEVICE_NOTIFY_WINDOW_HANDLE) |
| + if (message == WM_CREATE) { |
| + GUID guidDevInterface = GUID_NULL; |
| + HRESULT hr = CLSIDFromString(WPDDevInterfaceGUID, &guidDevInterface); |
| + if (SUCCEEDED(hr)) { |
| + static HDEVNOTIFY hDeviceNotify; |
| + DEV_BROADCAST_DEVICEINTERFACE db = {0}; |
| + db.dbcc_size = sizeof(db); |
| + db.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; |
| + db.dbcc_classguid = guidDevInterface; |
| + hDeviceNotify = RegisterDeviceNotification(hwnd, &db, DEVICE_NOTIFY_WINDOW_HANDLE); |
|
kinuko
2012/07/18 10:33:24
nit: over 80 cols (here and elsewhere; maybe you c
|
| + } |
| + } |
| +#endif |
| + |
| MediaDeviceNotificationsWindowWin* msg_wnd = |
| reinterpret_cast<MediaDeviceNotificationsWindowWin*>( |
| GetWindowLongPtr(hwnd, GWLP_USERDATA)); |