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

Side by Side Diff: chrome/browser/media_gallery/media_device_notifications_window_win.cc

Issue 10829384: SystemMonitor: Pull device type into the device id (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 4 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/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 "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
18 19
19 using content::BrowserThread; 20 using content::BrowserThread;
20 21
21 namespace { 22 namespace {
22 23
23 const wchar_t WindowClassName[] = L"Chrome_MediaDeviceNotificationWindow"; 24 const wchar_t WindowClassName[] = L"Chrome_MediaDeviceNotificationWindow";
24 25
25 LRESULT GetVolumeName(LPCWSTR drive, 26 LRESULT GetVolumeName(LPCWSTR drive,
26 LPWSTR volume_name, 27 LPWSTR volume_name,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
93 switch (event_type) { 94 switch (event_type) {
94 case DBT_DEVICEARRIVAL: { 95 case DBT_DEVICEARRIVAL: {
95 DWORD unitmask = GetVolumeBitMaskFromBroadcastHeader(data); 96 DWORD unitmask = GetVolumeBitMaskFromBroadcastHeader(data);
96 for (int i = 0; unitmask; ++i, unitmask >>= 1) { 97 for (int i = 0; unitmask; ++i, unitmask >>= 1) {
97 if (unitmask & 0x01) { 98 if (unitmask & 0x01) {
98 FilePath::StringType drive(L"_:\\"); 99 FilePath::StringType drive(L"_:\\");
99 drive[0] = L'A' + i; 100 drive[0] = L'A' + i;
100 WCHAR volume_name[MAX_PATH + 1]; 101 WCHAR volume_name[MAX_PATH + 1];
101 if ((*volume_name_func_)(drive.c_str(), volume_name, MAX_PATH + 1)) { 102 if ((*volume_name_func_)(drive.c_str(), volume_name, MAX_PATH + 1)) {
103 // TODO(kmadhusu) We need to look up a real device id as well as
104 // having a fall back for volume name.
105 std::string device_id = MediaStorageUtil::MakeDeviceId(
106 MediaStorageUtil::USB_MASS_STORAGE_WITH_DCIM,
107 base::IntToString(i));
102 BrowserThread::PostTask( 108 BrowserThread::PostTask(
103 BrowserThread::FILE, FROM_HERE, 109 BrowserThread::FILE, FROM_HERE,
104 base::Bind(&MediaDeviceNotificationsWindowWin:: 110 base::Bind(&MediaDeviceNotificationsWindowWin::
105 CheckDeviceTypeOnFileThread, this, base::IntToString(i), 111 CheckDeviceTypeOnFileThread, this, device_id,
106 FilePath::StringType(volume_name), FilePath(drive))); 112 FilePath::StringType(volume_name), FilePath(drive)));
107 } 113 }
108 } 114 }
109 } 115 }
110 break; 116 break;
111 } 117 }
112 case DBT_DEVICEREMOVECOMPLETE: { 118 case DBT_DEVICEREMOVECOMPLETE: {
113 DWORD unitmask = GetVolumeBitMaskFromBroadcastHeader(data); 119 DWORD unitmask = GetVolumeBitMaskFromBroadcastHeader(data);
114 for (int i = 0; unitmask; ++i, unitmask >>= 1) { 120 for (int i = 0; unitmask; ++i, unitmask >>= 1) {
115 if (unitmask & 0x01) { 121 if (unitmask & 0x01) {
122 std::string device_id = MediaStorageUtil::MakeDeviceId(
123 MediaStorageUtil::USB_MASS_STORAGE_WITH_DCIM,
124 base::IntToString(i));
116 base::SystemMonitor* monitor = base::SystemMonitor::Get(); 125 base::SystemMonitor* monitor = base::SystemMonitor::Get();
117 monitor->ProcessMediaDeviceDetached(base::IntToString(i)); 126 monitor->ProcessMediaDeviceDetached(device_id);
118 } 127 }
119 } 128 }
120 break; 129 break;
121 } 130 }
122 } 131 }
123 return TRUE; 132 return TRUE;
124 } 133 }
125 134
126 void MediaDeviceNotificationsWindowWin::CheckDeviceTypeOnFileThread( 135 void MediaDeviceNotificationsWindowWin::CheckDeviceTypeOnFileThread(
127 const std::string& id, 136 const std::string& id,
(...skipping 13 matching lines...) Expand all
141 150
142 void MediaDeviceNotificationsWindowWin::ProcessMediaDeviceAttachedOnUIThread( 151 void MediaDeviceNotificationsWindowWin::ProcessMediaDeviceAttachedOnUIThread(
143 const std::string& id, 152 const std::string& id,
144 const FilePath::StringType& device_name, 153 const FilePath::StringType& device_name,
145 const FilePath& path) { 154 const FilePath& path) {
146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
147 156
148 base::SystemMonitor* monitor = base::SystemMonitor::Get(); 157 base::SystemMonitor* monitor = base::SystemMonitor::Get();
149 monitor->ProcessMediaDeviceAttached(id, 158 monitor->ProcessMediaDeviceAttached(id,
150 device_name, 159 device_name,
151 base::SystemMonitor::TYPE_PATH,
152 path.value()); 160 path.value());
153 } 161 }
154 162
155 LRESULT CALLBACK MediaDeviceNotificationsWindowWin::WndProc( 163 LRESULT CALLBACK MediaDeviceNotificationsWindowWin::WndProc(
156 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { 164 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
157 switch (message) { 165 switch (message) {
158 case WM_DEVICECHANGE: 166 case WM_DEVICECHANGE:
159 return OnDeviceChange(static_cast<UINT>(wparam), 167 return OnDeviceChange(static_cast<UINT>(wparam),
160 static_cast<DWORD>(lparam)); 168 static_cast<DWORD>(lparam));
161 default: 169 default:
(...skipping 11 matching lines...) Expand all
173 LPARAM lparam) { 181 LPARAM lparam) {
174 MediaDeviceNotificationsWindowWin* msg_wnd = 182 MediaDeviceNotificationsWindowWin* msg_wnd =
175 reinterpret_cast<MediaDeviceNotificationsWindowWin*>( 183 reinterpret_cast<MediaDeviceNotificationsWindowWin*>(
176 GetWindowLongPtr(hwnd, GWLP_USERDATA)); 184 GetWindowLongPtr(hwnd, GWLP_USERDATA));
177 if (msg_wnd) 185 if (msg_wnd)
178 return msg_wnd->WndProc(hwnd, message, wparam, lparam); 186 return msg_wnd->WndProc(hwnd, message, wparam, lparam);
179 return ::DefWindowProc(hwnd, message, wparam, lparam); 187 return ::DefWindowProc(hwnd, message, wparam, lparam);
180 } 188 }
181 189
182 } // namespace chrome 190 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698