OLD | NEW |
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/media_gallery/media_device_notifications_window_win.h" | 5 #include "chrome/browser/media_gallery/media_device_notifications_window_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <dbt.h> | 8 #include <dbt.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "base/system_monitor/system_monitor.h" | 14 #include "base/system_monitor/system_monitor.h" |
15 #include "base/win/wrapped_window_proc.h" | 15 #include "base/win/wrapped_window_proc.h" |
16 #include "chrome/browser/media_gallery/media_device_notifications_utils.h" | 16 #include "chrome/browser/media_gallery/media_device_notifications_utils.h" |
17 #include "chrome/browser/media_gallery/media_storage_util.h" | 17 #include "chrome/browser/media_gallery/media_storage_util.h" |
18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
19 | 19 |
| 20 using base::SystemMonitor; |
20 using content::BrowserThread; | 21 using content::BrowserThread; |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 const wchar_t WindowClassName[] = L"Chrome_MediaDeviceNotificationWindow"; | 25 const wchar_t WindowClassName[] = L"Chrome_MediaDeviceNotificationWindow"; |
25 | 26 |
26 LRESULT GetVolumeName(LPCWSTR drive, | 27 LRESULT GetVolumeName(LPCWSTR drive, |
27 LPWSTR volume_name, | 28 LPWSTR volume_name, |
28 unsigned int volume_name_len) { | 29 unsigned int volume_name_len) { |
29 return GetVolumeInformation(drive, volume_name, volume_name_len, NULL, NULL, | 30 return GetVolumeInformation(drive, volume_name, volume_name_len, NULL, NULL, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 116 } |
116 break; | 117 break; |
117 } | 118 } |
118 case DBT_DEVICEREMOVECOMPLETE: { | 119 case DBT_DEVICEREMOVECOMPLETE: { |
119 DWORD unitmask = GetVolumeBitMaskFromBroadcastHeader(data); | 120 DWORD unitmask = GetVolumeBitMaskFromBroadcastHeader(data); |
120 for (int i = 0; unitmask; ++i, unitmask >>= 1) { | 121 for (int i = 0; unitmask; ++i, unitmask >>= 1) { |
121 if (unitmask & 0x01) { | 122 if (unitmask & 0x01) { |
122 std::string device_id = MediaStorageUtil::MakeDeviceId( | 123 std::string device_id = MediaStorageUtil::MakeDeviceId( |
123 MediaStorageUtil::USB_MASS_STORAGE_WITH_DCIM, | 124 MediaStorageUtil::USB_MASS_STORAGE_WITH_DCIM, |
124 base::IntToString(i)); | 125 base::IntToString(i)); |
125 base::SystemMonitor* monitor = base::SystemMonitor::Get(); | 126 SystemMonitor::Get()->ProcessRemovableStorageDetached(device_id); |
126 monitor->ProcessMediaDeviceDetached(device_id); | |
127 } | 127 } |
128 } | 128 } |
129 break; | 129 break; |
130 } | 130 } |
131 } | 131 } |
132 return TRUE; | 132 return TRUE; |
133 } | 133 } |
134 | 134 |
135 void MediaDeviceNotificationsWindowWin::CheckDeviceTypeOnFileThread( | 135 void MediaDeviceNotificationsWindowWin::CheckDeviceTypeOnFileThread( |
136 const std::string& id, | 136 const std::string& id, |
(...skipping 10 matching lines...) Expand all Loading... |
147 ProcessMediaDeviceAttachedOnUIThread, | 147 ProcessMediaDeviceAttachedOnUIThread, |
148 this, id, device_name, path)); | 148 this, id, device_name, path)); |
149 } | 149 } |
150 | 150 |
151 void MediaDeviceNotificationsWindowWin::ProcessMediaDeviceAttachedOnUIThread( | 151 void MediaDeviceNotificationsWindowWin::ProcessMediaDeviceAttachedOnUIThread( |
152 const std::string& id, | 152 const std::string& id, |
153 const FilePath::StringType& device_name, | 153 const FilePath::StringType& device_name, |
154 const FilePath& path) { | 154 const FilePath& path) { |
155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
156 | 156 |
157 base::SystemMonitor* monitor = base::SystemMonitor::Get(); | 157 SystemMonitor::Get()->ProcessRemovableStorageAttached(id, |
158 monitor->ProcessMediaDeviceAttached(id, | 158 device_name, |
159 device_name, | 159 path.value()); |
160 path.value()); | |
161 } | 160 } |
162 | 161 |
163 LRESULT CALLBACK MediaDeviceNotificationsWindowWin::WndProc( | 162 LRESULT CALLBACK MediaDeviceNotificationsWindowWin::WndProc( |
164 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { | 163 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { |
165 switch (message) { | 164 switch (message) { |
166 case WM_DEVICECHANGE: | 165 case WM_DEVICECHANGE: |
167 return OnDeviceChange(static_cast<UINT>(wparam), | 166 return OnDeviceChange(static_cast<UINT>(wparam), |
168 static_cast<DWORD>(lparam)); | 167 static_cast<DWORD>(lparam)); |
169 default: | 168 default: |
170 break; | 169 break; |
(...skipping 10 matching lines...) Expand all Loading... |
181 LPARAM lparam) { | 180 LPARAM lparam) { |
182 MediaDeviceNotificationsWindowWin* msg_wnd = | 181 MediaDeviceNotificationsWindowWin* msg_wnd = |
183 reinterpret_cast<MediaDeviceNotificationsWindowWin*>( | 182 reinterpret_cast<MediaDeviceNotificationsWindowWin*>( |
184 GetWindowLongPtr(hwnd, GWLP_USERDATA)); | 183 GetWindowLongPtr(hwnd, GWLP_USERDATA)); |
185 if (msg_wnd) | 184 if (msg_wnd) |
186 return msg_wnd->WndProc(hwnd, message, wparam, lparam); | 185 return msg_wnd->WndProc(hwnd, message, wparam, lparam); |
187 return ::DefWindowProc(hwnd, message, wparam, lparam); | 186 return ::DefWindowProc(hwnd, message, wparam, lparam); |
188 } | 187 } |
189 | 188 |
190 } // namespace chrome | 189 } // namespace chrome |
OLD | NEW |