Index: components/storage_monitor/volume_mount_watcher_win.cc |
diff --git a/components/storage_monitor/volume_mount_watcher_win.cc b/components/storage_monitor/volume_mount_watcher_win.cc |
index 101cbda2137b577731337b223184e163c504b825..74b5604d96cc10043df12be78b73a8e681175939 100644 |
--- a/components/storage_monitor/volume_mount_watcher_win.cc |
+++ b/components/storage_monitor/volume_mount_watcher_win.cc |
@@ -8,6 +8,7 @@ |
#include <dbt.h> |
#include <fileapi.h> |
+#include <shlobj.h> |
#include <winioctl.h> |
#include "base/bind_helpers.h" |
@@ -472,6 +473,42 @@ void VolumeMountWatcherWin::OnWindowMessage(UINT event_type, LPARAM data) { |
} |
} |
+// Surprisingly, we have to define this ourselves. |
+typedef struct { |
+ DWORD dwItem1; |
+ DWORD dwItem2; |
+} SHNOTIFYSTRUCT; |
vandebo (ex-Chrome)
2014/04/11 22:24:26
Can you figure out a better name for this.
Kevin Bailey
2014/04/22 15:43:03
Gone.
|
+ |
+void VolumeMountWatcherWin::OnMediaChanged(WPARAM wparam, LPARAM lparam) { |
+ SHNOTIFYSTRUCT* shns = reinterpret_cast<SHNOTIFYSTRUCT*>(wparam); |
vandebo (ex-Chrome)
2014/04/11 22:24:26
Seem to only use dwItem1, should we just cast is t
Kevin Bailey
2014/04/22 15:43:03
Ya, got rid of it entirely, and simplified the fun
|
+ switch (lparam) { |
+ case SHCNE_MEDIAINSERTED: { |
+ struct _ITEMIDLIST* pidl = reinterpret_cast<struct _ITEMIDLIST*>( |
+ shns->dwItem1); |
+ wchar_t sPath[MAX_PATH]; |
+ if (SHGetPathFromIDList(pidl, sPath)) { |
+ std::vector<base::FilePath> paths; |
+ paths.push_back(base::FilePath(sPath)); |
+ AddDevicesOnUIThread(paths); |
+ } else { |
+ DVLOG(1) << "MediaInserted: SHGetPathFromIDList failed"; |
+ } |
+ break; |
+ } |
+ case SHCNE_MEDIAREMOVED: { |
+ struct _ITEMIDLIST* pidl = reinterpret_cast<struct _ITEMIDLIST*>( |
+ shns->dwItem1); |
+ wchar_t sPath[MAX_PATH]; |
+ if (SHGetPathFromIDList(pidl, sPath)) { |
+ HandleDeviceDetachEventOnUIThread(sPath); |
+ } else { |
+ DVLOG(1) << "MediaRemoved: SHGetPathFromIDList failed"; |
+ } |
+ break; |
+ } |
+ } |
+} |
+ |
void VolumeMountWatcherWin::SetNotifications( |
StorageMonitor::Receiver* notifications) { |
notifications_ = notifications; |