Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / components / storage_monitor / volume_mount_watcher_win.cc
index 5dc2013..e38070e 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <dbt.h>
 #include <fileapi.h>
+#include <shlobj.h>
 #include <winioctl.h>
 
 #include "base/bind_helpers.h"
@@ -471,6 +472,30 @@ void VolumeMountWatcherWin::OnWindowMessage(UINT event_type, LPARAM data) {
   }
 }
 
+void VolumeMountWatcherWin::OnMediaChange(WPARAM wparam, LPARAM lparam) {
+  if (lparam == SHCNE_MEDIAINSERTED || lparam == SHCNE_MEDIAREMOVED) {
+    struct _ITEMIDLIST* pidl = *reinterpret_cast<struct _ITEMIDLIST**>(
+        wparam);
+    wchar_t sPath[MAX_PATH];
+    if (!SHGetPathFromIDList(pidl, sPath)) {
+      DVLOG(1) << "MediaInserted: SHGetPathFromIDList failed";
+      return;
+    }
+    switch (lparam) {
+      case SHCNE_MEDIAINSERTED: {
+        std::vector<base::FilePath> paths;
+        paths.push_back(base::FilePath(sPath));
+        AddDevicesOnUIThread(paths);
+        break;
+      }
+      case SHCNE_MEDIAREMOVED: {
+        HandleDeviceDetachEventOnUIThread(sPath);
+        break;
+      }
+    }
+  }
+}
+
 void VolumeMountWatcherWin::SetNotifications(
     StorageMonitor::Receiver* notifications) {
   notifications_ = notifications;