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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/storage_monitor/storage_monitor_win.h" 5 #include "components/storage_monitor/storage_monitor_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <dbt.h> 8 #include <dbt.h>
9 #include <fileapi.h> 9 #include <fileapi.h>
10 #include <shlobj.h>
10 11
11 #include "base/win/wrapped_window_proc.h" 12 #include "base/win/wrapped_window_proc.h"
12 #include "components/storage_monitor/portable_device_watcher_win.h" 13 #include "components/storage_monitor/portable_device_watcher_win.h"
13 #include "components/storage_monitor/removable_device_constants.h" 14 #include "components/storage_monitor/removable_device_constants.h"
14 #include "components/storage_monitor/storage_info.h" 15 #include "components/storage_monitor/storage_info.h"
15 #include "components/storage_monitor/volume_mount_watcher_win.h" 16 #include "components/storage_monitor/volume_mount_watcher_win.h"
16 17
18 #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
19
17 // StorageMonitorWin ------------------------------------------------------- 20 // StorageMonitorWin -------------------------------------------------------
18 21
19 namespace storage_monitor { 22 namespace storage_monitor {
20 23
21 StorageMonitorWin::StorageMonitorWin( 24 StorageMonitorWin::StorageMonitorWin(
22 VolumeMountWatcherWin* volume_mount_watcher, 25 VolumeMountWatcherWin* volume_mount_watcher,
23 PortableDeviceWatcherWin* portable_device_watcher) 26 PortableDeviceWatcherWin* portable_device_watcher)
24 : window_class_(0), 27 : window_class_(0),
25 instance_(NULL), 28 instance_(NULL),
26 window_(NULL), 29 window_(NULL),
27 volume_mount_watcher_(volume_mount_watcher), 30 volume_mount_watcher_(volume_mount_watcher),
28 portable_device_watcher_(portable_device_watcher) { 31 portable_device_watcher_(portable_device_watcher) {
29 DCHECK(volume_mount_watcher_); 32 DCHECK(volume_mount_watcher_);
30 DCHECK(portable_device_watcher_); 33 DCHECK(portable_device_watcher_);
31 volume_mount_watcher_->SetNotifications(receiver()); 34 volume_mount_watcher_->SetNotifications(receiver());
32 portable_device_watcher_->SetNotifications(receiver()); 35 portable_device_watcher_->SetNotifications(receiver());
33 } 36 }
34 37
35 StorageMonitorWin::~StorageMonitorWin() { 38 StorageMonitorWin::~StorageMonitorWin() {
rvargas (doing something else) 2014/04/22 21:09:44 SHChangeNotifyDeregister ?
Kevin Bailey 2014/04/23 16:02:23 Done.
36 volume_mount_watcher_->SetNotifications(NULL); 39 volume_mount_watcher_->SetNotifications(NULL);
37 portable_device_watcher_->SetNotifications(NULL); 40 portable_device_watcher_->SetNotifications(NULL);
38 41
39 if (window_) 42 if (window_)
40 DestroyWindow(window_); 43 DestroyWindow(window_);
41 44
42 if (window_class_) 45 if (window_class_)
43 UnregisterClass(MAKEINTATOM(window_class_), instance_); 46 UnregisterClass(MAKEINTATOM(window_class_), instance_);
44 } 47 }
45 48
49 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.
50 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.
51 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.
52 SHChangeNotifyEntry shCNE;
53 shCNE.pidl = ppidl;
54 shCNE.fRecursive = TRUE;
55 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
56 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.
57 WM_USER_MEDIACHANGED, 1, &shCNE))
58 DVLOG(1) << "SHChangeNotifyRegister FAILED";
59 } else {
60 DVLOG(1) << "SHGetSpecialFolderLocation FAILED";
61 }
62 }
63
46 void StorageMonitorWin::Init() { 64 void StorageMonitorWin::Init() {
47 WNDCLASSEX window_class; 65 WNDCLASSEX window_class;
48 base::win::InitializeWindowClass( 66 base::win::InitializeWindowClass(
49 L"Chrome_StorageMonitorWindow", 67 L"Chrome_StorageMonitorWindow",
50 &base::win::WrappedWindowProc<StorageMonitorWin::WndProcThunk>, 68 &base::win::WrappedWindowProc<StorageMonitorWin::WndProcThunk>,
51 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 69 0, 0, 0, NULL, NULL, NULL, NULL, NULL,
52 &window_class); 70 &window_class);
53 instance_ = window_class.hInstance; 71 instance_ = window_class.hInstance;
54 window_class_ = RegisterClassEx(&window_class); 72 window_class_ = RegisterClassEx(&window_class);
55 DCHECK(window_class_); 73 DCHECK(window_class_);
56 74
57 window_ = CreateWindow(MAKEINTATOM(window_class_), 0, 0, 0, 0, 0, 0, 0, 0, 75 window_ = CreateWindow(MAKEINTATOM(window_class_), 0, 0, 0, 0, 0, 0, 0, 0,
58 instance_, 0); 76 instance_, 0);
59 SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)); 77 SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
60 volume_mount_watcher_->Init(); 78 volume_mount_watcher_->Init();
61 portable_device_watcher_->Init(window_); 79 portable_device_watcher_->Init(window_);
80 MediaChangeNotificationRegister();
62 } 81 }
63 82
64 bool StorageMonitorWin::GetStorageInfoForPath(const base::FilePath& path, 83 bool StorageMonitorWin::GetStorageInfoForPath(const base::FilePath& path,
65 StorageInfo* device_info) const { 84 StorageInfo* device_info) const {
66 DCHECK(device_info); 85 DCHECK(device_info);
67 86
68 // TODO(gbillock): Move this logic up to StorageMonitor. 87 // TODO(gbillock): Move this logic up to StorageMonitor.
69 // If we already know the StorageInfo for the path, just return it. 88 // If we already know the StorageInfo for the path, just return it.
70 // This will account for portable devices as well. 89 // This will account for portable devices as well.
71 std::vector<StorageInfo> attached_devices = GetAllAvailableStorages(); 90 std::vector<StorageInfo> attached_devices = GetAllAvailableStorages();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 return msg_wnd->WndProc(hwnd, message, wparam, lparam); 150 return msg_wnd->WndProc(hwnd, message, wparam, lparam);
132 return ::DefWindowProc(hwnd, message, wparam, lparam); 151 return ::DefWindowProc(hwnd, message, wparam, lparam);
133 } 152 }
134 153
135 LRESULT CALLBACK StorageMonitorWin::WndProc(HWND hwnd, UINT message, 154 LRESULT CALLBACK StorageMonitorWin::WndProc(HWND hwnd, UINT message,
136 WPARAM wparam, LPARAM lparam) { 155 WPARAM wparam, LPARAM lparam) {
137 switch (message) { 156 switch (message) {
138 case WM_DEVICECHANGE: 157 case WM_DEVICECHANGE:
139 OnDeviceChange(static_cast<UINT>(wparam), lparam); 158 OnDeviceChange(static_cast<UINT>(wparam), lparam);
140 return TRUE; 159 return TRUE;
160 case WM_USER_MEDIACHANGED:
161 OnMediaChange(wparam, lparam);
162 return TRUE;
141 default: 163 default:
142 break; 164 break;
143 } 165 }
144 166
145 return ::DefWindowProc(hwnd, message, wparam, lparam); 167 return ::DefWindowProc(hwnd, message, wparam, lparam);
146 } 168 }
147 169
148 bool StorageMonitorWin::GetDeviceInfo(const base::FilePath& device_path, 170 bool StorageMonitorWin::GetDeviceInfo(const base::FilePath& device_path,
149 StorageInfo* info) const { 171 StorageInfo* info) const {
150 DCHECK(info); 172 DCHECK(info);
151 173
152 // TODO(kmadhusu) Implement PortableDeviceWatcherWin::GetDeviceInfo() 174 // TODO(kmadhusu) Implement PortableDeviceWatcherWin::GetDeviceInfo()
153 // function when we have the functionality to add a sub directory of 175 // function when we have the functionality to add a sub directory of
154 // portable device as a media gallery. 176 // portable device as a media gallery.
155 return volume_mount_watcher_->GetDeviceInfo(device_path, info); 177 return volume_mount_watcher_->GetDeviceInfo(device_path, info);
156 } 178 }
157 179
158 void StorageMonitorWin::OnDeviceChange(UINT event_type, LPARAM data) { 180 void StorageMonitorWin::OnDeviceChange(UINT event_type, LPARAM data) {
181 DVLOG(1) << "OnDeviceChange " << event_type << " " << data;
159 volume_mount_watcher_->OnWindowMessage(event_type, data); 182 volume_mount_watcher_->OnWindowMessage(event_type, data);
160 portable_device_watcher_->OnWindowMessage(event_type, data); 183 portable_device_watcher_->OnWindowMessage(event_type, data);
161 } 184 }
162 185
186 void StorageMonitorWin::OnMediaChange(WPARAM wparam, LPARAM lparam) {
187 volume_mount_watcher_->OnMediaChange(wparam, lparam);
188 }
189
163 StorageMonitor* StorageMonitor::CreateInternal() { 190 StorageMonitor* StorageMonitor::CreateInternal() {
164 return new StorageMonitorWin(new VolumeMountWatcherWin(), 191 return new StorageMonitorWin(new VolumeMountWatcherWin(),
165 new PortableDeviceWatcherWin()); 192 new PortableDeviceWatcherWin());
166 } 193 }
167 194
168 } // namespace storage_monitor 195 } // namespace storage_monitor
OLDNEW
« 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