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

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: Simplified a function 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..f663e88814aab8b488e128ebf935180280910d98 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"
@@ -14,6 +15,8 @@
#include "components/storage_monitor/storage_info.h"
#include "components/storage_monitor/volume_mount_watcher_win.h"
+#define WM_USER_MEDIACHANGED (WM_USER+1)
rvargas (doing something else) 2014/04/22 21:09:44 This is numerically the same as the wake up messag
Kevin Bailey 2014/04/23 16:02:23 I was under the impression that it is the intent o
rvargas (doing something else) 2014/04/23 18:45:15 There is no bug in using the same value, as long a
Kevin Bailey 2014/04/24 15:12:38 Agreed, but now I have little idea who it's collid
+
// StorageMonitorWin -------------------------------------------------------
namespace storage_monitor {
@@ -43,6 +46,21 @@ StorageMonitorWin::~StorageMonitorWin() {
UnregisterClass(MAKEINTATOM(window_class_), instance_);
}
+void StorageMonitorWin::MediaChangeNotificationRegister() {
vandebo (ex-Chrome) 2014/04/22 18:07:42 Move to line 169
Kevin Bailey 2014/04/22 20:09:31 Done.
+ LPITEMIDLIST ppidl;
rvargas (doing something else) 2014/04/22 21:09:44 nit: even for Windows code, variables should follo
Kevin Bailey 2014/04/23 16:02:23 Done.
+ if (SHGetSpecialFolderLocation(window_, CSIDL_DESKTOP, &ppidl) == NOERROR) {
rvargas (doing something else) 2014/04/22 21:09:44 CSIDL_DRIVES ?
rvargas (doing something else) 2014/04/22 21:09:44 The first argument is reserved.
Kevin Bailey 2014/04/23 16:02:23 Done.
Kevin Bailey 2014/04/23 16:02:23 I assume this means, pass 0.
+ SHChangeNotifyEntry shCNE;
+ shCNE.pidl = ppidl;
+ shCNE.fRecursive = TRUE;
+ if (!SHChangeNotifyRegister(window_, SHCNE_DISKEVENTS,
rvargas (doing something else) 2014/04/22 21:09:44 The second argument (fSources) is one of SHCNRF_*
Kevin Bailey 2014/04/23 16:02:23 Ok, I hope ShellLevel is correct. It seems to work
+ SHCNE_MEDIAINSERTED|SHCNE_MEDIAREMOVED,
rvargas (doing something else) 2014/04/22 21:09:44 nit: spaces around |
Kevin Bailey 2014/04/23 16:02:23 Done.
+ WM_USER_MEDIACHANGED, 1, &shCNE))
+ DVLOG(1) << "SHChangeNotifyRegister FAILED";
+ } else {
+ DVLOG(1) << "SHGetSpecialFolderLocation FAILED";
+ }
+}
+
void StorageMonitorWin::Init() {
WNDCLASSEX window_class;
base::win::InitializeWindowClass(
@@ -59,6 +77,7 @@ void StorageMonitorWin::Init() {
SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
volume_mount_watcher_->Init();
portable_device_watcher_->Init(window_);
+ MediaChangeNotificationRegister();
}
bool StorageMonitorWin::GetStorageInfoForPath(const base::FilePath& path,
@@ -138,6 +157,9 @@ LRESULT CALLBACK StorageMonitorWin::WndProc(HWND hwnd, UINT message,
case WM_DEVICECHANGE:
OnDeviceChange(static_cast<UINT>(wparam), lparam);
return TRUE;
+ case WM_USER_MEDIACHANGED:
+ OnMediaChange(wparam, lparam);
+ return TRUE;
default:
break;
}
@@ -156,10 +178,15 @@ 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);
}
+void StorageMonitorWin::OnMediaChange(WPARAM wparam, LPARAM lparam) {
+ volume_mount_watcher_->OnMediaChange(wparam, lparam);
+}
+
StorageMonitor* StorageMonitor::CreateInternal() {
return new StorageMonitorWin(new VolumeMountWatcherWin(),
new PortableDeviceWatcherWin());
« no previous file with comments | « components/storage_monitor/storage_monitor_win.h ('k') | components/storage_monitor/volume_mount_watcher_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698