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

Side by Side Diff: chrome/browser/system_monitor/removable_device_notifications_window_win.cc

Issue 11088012: [Win, MediaGallery] Enumerate and handle mtp device attach/detach events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/system_monitor/removable_device_notifications_window_wi n.h" 5 #include "chrome/browser/system_monitor/removable_device_notifications_window_wi n.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 10
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/win/wrapped_window_proc.h" 12 #include "base/win/wrapped_window_proc.h"
13 #include "chrome/browser/system_monitor/media_storage_util.h" 13 #include "chrome/browser/system_monitor/media_storage_util.h"
14 #include "chrome/browser/system_monitor/removable_device_constants.h"
14 15
15 using base::SystemMonitor; 16 using base::SystemMonitor;
16 using base::win::WrappedWindowProc; 17 using base::win::WrappedWindowProc;
17 18
18 namespace chrome { 19 namespace chrome {
19 20
20 namespace { 21 namespace {
21 22
22 const char16 kWindowClassName[] = L"Chrome_RemovableDeviceNotificationWindow"; 23 const char16 kWindowClassName[] = L"Chrome_RemovableDeviceNotificationWindow";
23 24
24 RemovableDeviceNotificationsWindowWin* 25 RemovableDeviceNotificationsWindowWin*
25 g_removable_device_notifications_window_win = NULL; 26 g_removable_device_notifications_window_win = NULL;
26 27
27 } // namespace 28 } // namespace
28 29
29 // static 30 // static
30 RemovableDeviceNotificationsWindowWin* 31 RemovableDeviceNotificationsWindowWin*
31 RemovableDeviceNotificationsWindowWin::Create() { 32 RemovableDeviceNotificationsWindowWin::Create() {
32 return new RemovableDeviceNotificationsWindowWin(new VolumeMountWatcherWin()); 33 return new RemovableDeviceNotificationsWindowWin(
34 new VolumeMountWatcherWin(), new PortableDeviceWatcherWin());
33 } 35 }
34 36
35 RemovableDeviceNotificationsWindowWin:: 37 RemovableDeviceNotificationsWindowWin::
36 RemovableDeviceNotificationsWindowWin( 38 RemovableDeviceNotificationsWindowWin(
37 VolumeMountWatcherWin* volume_mount_watcher) 39 VolumeMountWatcherWin* volume_mount_watcher,
40 PortableDeviceWatcherWin* portable_device_watcher)
38 : window_class_(0), 41 : window_class_(0),
39 instance_(NULL), 42 instance_(NULL),
40 window_(NULL), 43 window_(NULL),
41 volume_mount_watcher_(volume_mount_watcher) { 44 volume_mount_watcher_(volume_mount_watcher),
45 portable_device_watcher_(portable_device_watcher) {
42 DCHECK(volume_mount_watcher_); 46 DCHECK(volume_mount_watcher_);
47 DCHECK(portable_device_watcher_);
43 DCHECK(!g_removable_device_notifications_window_win); 48 DCHECK(!g_removable_device_notifications_window_win);
44 g_removable_device_notifications_window_win = this; 49 g_removable_device_notifications_window_win = this;
45 } 50 }
46 51
47 RemovableDeviceNotificationsWindowWin:: 52 RemovableDeviceNotificationsWindowWin::
48 ~RemovableDeviceNotificationsWindowWin() { 53 ~RemovableDeviceNotificationsWindowWin() {
49 if (window_) 54 if (window_)
50 DestroyWindow(window_); 55 DestroyWindow(window_);
51 56
52 if (window_class_) 57 if (window_class_)
53 UnregisterClass(MAKEINTATOM(window_class_), instance_); 58 UnregisterClass(MAKEINTATOM(window_class_), instance_);
54 59
55 DCHECK_EQ(this, g_removable_device_notifications_window_win); 60 DCHECK_EQ(this, g_removable_device_notifications_window_win);
56 g_removable_device_notifications_window_win = NULL; 61 g_removable_device_notifications_window_win = NULL;
57 } 62 }
58 63
59 // static 64 // static
60 RemovableDeviceNotificationsWindowWin* 65 RemovableDeviceNotificationsWindowWin*
61 RemovableDeviceNotificationsWindowWin::GetInstance() { 66 RemovableDeviceNotificationsWindowWin::GetInstance() {
62 DCHECK(g_removable_device_notifications_window_win); 67 DCHECK(g_removable_device_notifications_window_win);
63 return g_removable_device_notifications_window_win; 68 return g_removable_device_notifications_window_win;
64 } 69 }
65 70
66 void RemovableDeviceNotificationsWindowWin::Init() { 71 void RemovableDeviceNotificationsWindowWin::Init() {
67 volume_mount_watcher_->Init(); 72 volume_mount_watcher_->Init();
73 portable_device_watcher_->Init();
68 74
69 WNDCLASSEX window_class; 75 WNDCLASSEX window_class;
70 base::win::InitializeWindowClass( 76 base::win::InitializeWindowClass(
71 kWindowClassName, 77 kWindowClassName,
72 &WrappedWindowProc<RemovableDeviceNotificationsWindowWin::WndProcThunk>, 78 &WrappedWindowProc<RemovableDeviceNotificationsWindowWin::WndProcThunk>,
73 0, 0, 0, NULL, NULL, NULL, NULL, NULL, 79 0, 0, 0, NULL, NULL, NULL, NULL, NULL,
74 &window_class); 80 &window_class);
75 instance_ = window_class.hInstance; 81 instance_ = window_class.hInstance;
76 window_class_ = RegisterClassEx(&window_class); 82 window_class_ = RegisterClassEx(&window_class);
77 DCHECK(window_class_); 83 DCHECK(window_class_);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 device_info->device_id = device_id; 128 device_info->device_id = device_id;
123 device_info->name = name; 129 device_info->name = name;
124 device_info->location = location; 130 device_info->location = location;
125 } 131 }
126 return true; 132 return true;
127 } 133 }
128 134
129 // static 135 // static
130 LRESULT CALLBACK RemovableDeviceNotificationsWindowWin::WndProcThunk( 136 LRESULT CALLBACK RemovableDeviceNotificationsWindowWin::WndProcThunk(
131 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { 137 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
138 static HDEVNOTIFY hDeviceNotify;
Peter Kasting 2012/10/19 21:31:12 Overriding the WndProc and then looking for specif
kmadhusu 2012/10/23 23:44:17 Done. I used SystemMessageWindowWin::DeviceNotific
139 if (message == WM_CREATE) {
140 GUID guidDevInterface = GUID_NULL;
141 HRESULT hr = CLSIDFromString(kWPDDevInterfaceGUID, &guidDevInterface);
142 if (SUCCEEDED(hr)) {
143 DEV_BROADCAST_DEVICEINTERFACE db = {0};
Peter Kasting 2012/10/19 21:31:12 Nit: Or just: DEV_BROADCAST_DEVICEINTERFACE
kmadhusu 2012/10/23 23:44:17 Done.
144 db.dbcc_size = sizeof(db);
145 db.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
146 db.dbcc_classguid = guidDevInterface;
147 hDeviceNotify = RegisterDeviceNotification(hwnd, &db,
148 DEVICE_NOTIFY_WINDOW_HANDLE);
149 }
150 } else if (message == WM_CLOSE) {
151 UnregisterDeviceNotification(hDeviceNotify);
152 }
132 RemovableDeviceNotificationsWindowWin* msg_wnd = 153 RemovableDeviceNotificationsWindowWin* msg_wnd =
133 reinterpret_cast<RemovableDeviceNotificationsWindowWin*>( 154 reinterpret_cast<RemovableDeviceNotificationsWindowWin*>(
134 GetWindowLongPtr(hwnd, GWLP_USERDATA)); 155 GetWindowLongPtr(hwnd, GWLP_USERDATA));
135 if (msg_wnd) 156 if (msg_wnd)
136 return msg_wnd->WndProc(hwnd, message, wparam, lparam); 157 return msg_wnd->WndProc(hwnd, message, wparam, lparam);
137 return ::DefWindowProc(hwnd, message, wparam, lparam); 158 return ::DefWindowProc(hwnd, message, wparam, lparam);
138 } 159 }
139 160
140 LRESULT CALLBACK RemovableDeviceNotificationsWindowWin::WndProc( 161 LRESULT CALLBACK RemovableDeviceNotificationsWindowWin::WndProc(
141 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { 162 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
142 switch (message) { 163 switch (message) {
143 case WM_DEVICECHANGE: 164 case WM_DEVICECHANGE:
144 OnDeviceChange(static_cast<UINT>(wparam), lparam); 165 OnDeviceChange(static_cast<UINT>(wparam), lparam);
145 return TRUE; 166 return TRUE;
146 default: 167 default:
147 break; 168 break;
148 } 169 }
149 170
150 return ::DefWindowProc(hwnd, message, wparam, lparam); 171 return ::DefWindowProc(hwnd, message, wparam, lparam);
151 } 172 }
152 173
153 bool RemovableDeviceNotificationsWindowWin::GetDeviceInfo( 174 bool RemovableDeviceNotificationsWindowWin::GetDeviceInfo(
154 const FilePath& device_path, string16* device_location, 175 const FilePath& device_path, string16* device_location,
155 std::string* unique_id, string16* name, bool* removable) { 176 std::string* unique_id, string16* name, bool* removable) {
156 return volume_mount_watcher_->GetDeviceInfo(device_path, device_location, 177 bool result = volume_mount_watcher_->GetDeviceInfo(device_path,
Peter Kasting 2012/10/19 21:31:12 Nit: Shorter: return volume_mount_watcher_->Get
kmadhusu 2012/10/23 23:44:17 Done.
157 unique_id, name, removable); 178 device_location, unique_id,
179 name, removable);
180 if (!result) {
181 result = portable_device_watcher_->GetDeviceInfo(device_path,
182 device_location, unique_id,
183 name, removable);
184 }
185 return result;
158 } 186 }
159 187
160 void RemovableDeviceNotificationsWindowWin::OnDeviceChange(UINT event_type, 188 void RemovableDeviceNotificationsWindowWin::OnDeviceChange(UINT event_type,
161 LPARAM data) { 189 LPARAM data) {
162 volume_mount_watcher_->OnWindowMessage(event_type, data); 190 volume_mount_watcher_->OnWindowMessage(event_type, data);
191 portable_device_watcher_->OnWindowMessage(event_type, data);
163 } 192 }
164 193
165 } // namespace chrome 194 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698