Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(564)

Unified Diff: components/storage_monitor/volume_mount_watcher_win.cc

Issue 231063002: Add notification for media changed, and notify volume mount watcher when it occurs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Linting. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;

Powered by Google App Engine
This is Rietveld 408576698