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

Unified Diff: components/storage_monitor/storage_monitor_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/storage_monitor_win.cc
diff --git a/components/storage_monitor/storage_monitor_win.cc b/components/storage_monitor/storage_monitor_win.cc
index fb721bb3284826999bde409d67109cff8699cb6b..958c8edb63eb1f9dbd435b733ddc9d596ba6291c 100644
--- a/components/storage_monitor/storage_monitor_win.cc
+++ b/components/storage_monitor/storage_monitor_win.cc
@@ -7,6 +7,7 @@
#include <windows.h>
#include <dbt.h>
#include <fileapi.h>
+#include <shlobj.h>
#include "base/win/wrapped_window_proc.h"
#include "components/storage_monitor/portable_device_watcher_win.h"
@@ -43,6 +44,24 @@ StorageMonitorWin::~StorageMonitorWin() {
UnregisterClass(MAKEINTATOM(window_class_), instance_);
}
+#define WM_USER_MEDIACHANGED (WM_USER+1)
vandebo (ex-Chrome) 2014/04/11 22:24:26 Put this on before line 18
Kevin Bailey 2014/04/22 15:43:03 Done.
+
+void StorageMonitorWin::ChangeNotifyRegister() {
vandebo (ex-Chrome) 2014/04/11 22:24:26 Could also just put this code in the Init method,
Kevin Bailey 2014/04/22 15:43:03 It's a little messy, and would add entirely new ca
vandebo (ex-Chrome) 2014/04/22 18:07:42 I think inlining it would be fine, but leaving it
+ LPITEMIDLIST ppidl;
+ if (SHGetSpecialFolderLocation(window_, CSIDL_DESKTOP, &ppidl) == NOERROR) {
+ SHChangeNotifyEntry shCNE;
+ shCNE.pidl = ppidl;
+ shCNE.fRecursive = TRUE;
+ ULONG result = SHChangeNotifyRegister(window_, SHCNE_DISKEVENTS,
vandebo (ex-Chrome) 2014/04/11 22:24:26 result isn't used, inline the if
Kevin Bailey 2014/04/22 15:43:03 Done.
+ SHCNE_MEDIAINSERTED|SHCNE_MEDIAREMOVED,
+ WM_USER_MEDIACHANGED, 1, &shCNE);
+ if (!result)
+ DVLOG(1) << "SHChangeNotifyRegister FAILED";
+ } else {
+ DVLOG(1) << "SHGetSpecialFolderLocation FAILED";
+ }
+}
+
void StorageMonitorWin::Init() {
WNDCLASSEX window_class;
base::win::InitializeWindowClass(
@@ -59,6 +78,7 @@ void StorageMonitorWin::Init() {
SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
volume_mount_watcher_->Init();
portable_device_watcher_->Init(window_);
+ ChangeNotifyRegister();
}
bool StorageMonitorWin::GetStorageInfoForPath(const base::FilePath& path,
@@ -132,12 +152,19 @@ LRESULT CALLBACK StorageMonitorWin::WndProcThunk(HWND hwnd, UINT message,
return ::DefWindowProc(hwnd, message, wparam, lparam);
}
+void StorageMonitorWin::OnMediaChanged(WPARAM wparam, LPARAM lparam) {
vandebo (ex-Chrome) 2014/04/11 22:24:26 Move to after line 183
Kevin Bailey 2014/04/22 15:43:03 Done.
+ volume_mount_watcher_->OnMediaChanged(wparam, lparam);
+}
+
LRESULT CALLBACK StorageMonitorWin::WndProc(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam) {
switch (message) {
case WM_DEVICECHANGE:
OnDeviceChange(static_cast<UINT>(wparam), lparam);
return TRUE;
+ case WM_USER_MEDIACHANGED:
+ OnMediaChanged(wparam, lparam);
+ return TRUE;
default:
break;
}
@@ -156,6 +183,7 @@ bool StorageMonitorWin::GetDeviceInfo(const base::FilePath& device_path,
}
void StorageMonitorWin::OnDeviceChange(UINT event_type, LPARAM data) {
+ DVLOG(1) << "OnDeviceChange " << event_type << " " << data;
volume_mount_watcher_->OnWindowMessage(event_type, data);
portable_device_watcher_->OnWindowMessage(event_type, data);
}

Powered by Google App Engine
This is Rietveld 408576698