OLD | NEW |
---|---|
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 |
17 // StorageMonitorWin ------------------------------------------------------- | 18 // StorageMonitorWin ------------------------------------------------------- |
18 | 19 |
19 namespace storage_monitor { | 20 namespace storage_monitor { |
(...skipping 16 matching lines...) Expand all Loading... | |
36 volume_mount_watcher_->SetNotifications(NULL); | 37 volume_mount_watcher_->SetNotifications(NULL); |
37 portable_device_watcher_->SetNotifications(NULL); | 38 portable_device_watcher_->SetNotifications(NULL); |
38 | 39 |
39 if (window_) | 40 if (window_) |
40 DestroyWindow(window_); | 41 DestroyWindow(window_); |
41 | 42 |
42 if (window_class_) | 43 if (window_class_) |
43 UnregisterClass(MAKEINTATOM(window_class_), instance_); | 44 UnregisterClass(MAKEINTATOM(window_class_), instance_); |
44 } | 45 } |
45 | 46 |
47 #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.
| |
48 | |
49 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
| |
50 LPITEMIDLIST ppidl; | |
51 if (SHGetSpecialFolderLocation(window_, CSIDL_DESKTOP, &ppidl) == NOERROR) { | |
52 SHChangeNotifyEntry shCNE; | |
53 shCNE.pidl = ppidl; | |
54 shCNE.fRecursive = TRUE; | |
55 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.
| |
56 SHCNE_MEDIAINSERTED|SHCNE_MEDIAREMOVED, | |
57 WM_USER_MEDIACHANGED, 1, &shCNE); | |
58 if (!result) | |
59 DVLOG(1) << "SHChangeNotifyRegister FAILED"; | |
60 } else { | |
61 DVLOG(1) << "SHGetSpecialFolderLocation FAILED"; | |
62 } | |
63 } | |
64 | |
46 void StorageMonitorWin::Init() { | 65 void StorageMonitorWin::Init() { |
47 WNDCLASSEX window_class; | 66 WNDCLASSEX window_class; |
48 base::win::InitializeWindowClass( | 67 base::win::InitializeWindowClass( |
49 L"Chrome_StorageMonitorWindow", | 68 L"Chrome_StorageMonitorWindow", |
50 &base::win::WrappedWindowProc<StorageMonitorWin::WndProcThunk>, | 69 &base::win::WrappedWindowProc<StorageMonitorWin::WndProcThunk>, |
51 0, 0, 0, NULL, NULL, NULL, NULL, NULL, | 70 0, 0, 0, NULL, NULL, NULL, NULL, NULL, |
52 &window_class); | 71 &window_class); |
53 instance_ = window_class.hInstance; | 72 instance_ = window_class.hInstance; |
54 window_class_ = RegisterClassEx(&window_class); | 73 window_class_ = RegisterClassEx(&window_class); |
55 DCHECK(window_class_); | 74 DCHECK(window_class_); |
56 | 75 |
57 window_ = CreateWindow(MAKEINTATOM(window_class_), 0, 0, 0, 0, 0, 0, 0, 0, | 76 window_ = CreateWindow(MAKEINTATOM(window_class_), 0, 0, 0, 0, 0, 0, 0, 0, |
58 instance_, 0); | 77 instance_, 0); |
59 SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)); | 78 SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)); |
60 volume_mount_watcher_->Init(); | 79 volume_mount_watcher_->Init(); |
61 portable_device_watcher_->Init(window_); | 80 portable_device_watcher_->Init(window_); |
81 ChangeNotifyRegister(); | |
62 } | 82 } |
63 | 83 |
64 bool StorageMonitorWin::GetStorageInfoForPath(const base::FilePath& path, | 84 bool StorageMonitorWin::GetStorageInfoForPath(const base::FilePath& path, |
65 StorageInfo* device_info) const { | 85 StorageInfo* device_info) const { |
66 DCHECK(device_info); | 86 DCHECK(device_info); |
67 | 87 |
68 // TODO(gbillock): Move this logic up to StorageMonitor. | 88 // TODO(gbillock): Move this logic up to StorageMonitor. |
69 // If we already know the StorageInfo for the path, just return it. | 89 // If we already know the StorageInfo for the path, just return it. |
70 // This will account for portable devices as well. | 90 // This will account for portable devices as well. |
71 std::vector<StorageInfo> attached_devices = GetAllAvailableStorages(); | 91 std::vector<StorageInfo> attached_devices = GetAllAvailableStorages(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 // static | 145 // static |
126 LRESULT CALLBACK StorageMonitorWin::WndProcThunk(HWND hwnd, UINT message, | 146 LRESULT CALLBACK StorageMonitorWin::WndProcThunk(HWND hwnd, UINT message, |
127 WPARAM wparam, LPARAM lparam) { | 147 WPARAM wparam, LPARAM lparam) { |
128 StorageMonitorWin* msg_wnd = reinterpret_cast<StorageMonitorWin*>( | 148 StorageMonitorWin* msg_wnd = reinterpret_cast<StorageMonitorWin*>( |
129 GetWindowLongPtr(hwnd, GWLP_USERDATA)); | 149 GetWindowLongPtr(hwnd, GWLP_USERDATA)); |
130 if (msg_wnd) | 150 if (msg_wnd) |
131 return msg_wnd->WndProc(hwnd, message, wparam, lparam); | 151 return msg_wnd->WndProc(hwnd, message, wparam, lparam); |
132 return ::DefWindowProc(hwnd, message, wparam, lparam); | 152 return ::DefWindowProc(hwnd, message, wparam, lparam); |
133 } | 153 } |
134 | 154 |
155 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.
| |
156 volume_mount_watcher_->OnMediaChanged(wparam, lparam); | |
157 } | |
158 | |
135 LRESULT CALLBACK StorageMonitorWin::WndProc(HWND hwnd, UINT message, | 159 LRESULT CALLBACK StorageMonitorWin::WndProc(HWND hwnd, UINT message, |
136 WPARAM wparam, LPARAM lparam) { | 160 WPARAM wparam, LPARAM lparam) { |
137 switch (message) { | 161 switch (message) { |
138 case WM_DEVICECHANGE: | 162 case WM_DEVICECHANGE: |
139 OnDeviceChange(static_cast<UINT>(wparam), lparam); | 163 OnDeviceChange(static_cast<UINT>(wparam), lparam); |
140 return TRUE; | 164 return TRUE; |
165 case WM_USER_MEDIACHANGED: | |
166 OnMediaChanged(wparam, lparam); | |
167 return TRUE; | |
141 default: | 168 default: |
142 break; | 169 break; |
143 } | 170 } |
144 | 171 |
145 return ::DefWindowProc(hwnd, message, wparam, lparam); | 172 return ::DefWindowProc(hwnd, message, wparam, lparam); |
146 } | 173 } |
147 | 174 |
148 bool StorageMonitorWin::GetDeviceInfo(const base::FilePath& device_path, | 175 bool StorageMonitorWin::GetDeviceInfo(const base::FilePath& device_path, |
149 StorageInfo* info) const { | 176 StorageInfo* info) const { |
150 DCHECK(info); | 177 DCHECK(info); |
151 | 178 |
152 // TODO(kmadhusu) Implement PortableDeviceWatcherWin::GetDeviceInfo() | 179 // TODO(kmadhusu) Implement PortableDeviceWatcherWin::GetDeviceInfo() |
153 // function when we have the functionality to add a sub directory of | 180 // function when we have the functionality to add a sub directory of |
154 // portable device as a media gallery. | 181 // portable device as a media gallery. |
155 return volume_mount_watcher_->GetDeviceInfo(device_path, info); | 182 return volume_mount_watcher_->GetDeviceInfo(device_path, info); |
156 } | 183 } |
157 | 184 |
158 void StorageMonitorWin::OnDeviceChange(UINT event_type, LPARAM data) { | 185 void StorageMonitorWin::OnDeviceChange(UINT event_type, LPARAM data) { |
186 DVLOG(1) << "OnDeviceChange " << event_type << " " << data; | |
159 volume_mount_watcher_->OnWindowMessage(event_type, data); | 187 volume_mount_watcher_->OnWindowMessage(event_type, data); |
160 portable_device_watcher_->OnWindowMessage(event_type, data); | 188 portable_device_watcher_->OnWindowMessage(event_type, data); |
161 } | 189 } |
162 | 190 |
163 StorageMonitor* StorageMonitor::CreateInternal() { | 191 StorageMonitor* StorageMonitor::CreateInternal() { |
164 return new StorageMonitorWin(new VolumeMountWatcherWin(), | 192 return new StorageMonitorWin(new VolumeMountWatcherWin(), |
165 new PortableDeviceWatcherWin()); | 193 new PortableDeviceWatcherWin()); |
166 } | 194 } |
167 | 195 |
168 } // namespace storage_monitor | 196 } // namespace storage_monitor |
OLD | NEW |