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

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

Issue 10211008: Moves media device notification code to chrome/browser (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressed comments Created 8 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 (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 "content/browser/system_message_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 #include <string> 9 #include <string>
10 10
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/sys_string_conversions.h" 12 #include "base/sys_string_conversions.h"
13 #include "base/system_monitor/system_monitor.h" 13 #include "base/system_monitor/system_monitor.h"
14 #include "base/win/wrapped_window_proc.h" 14 #include "base/win/wrapped_window_proc.h"
15 15
16 static const wchar_t* const WindowClassName = L"Chrome_SystemMessageWindow"; 16 static const wchar_t* const WindowClassName =
17 L"Chrome_MediaDeviceNotificationWindow";
17 18
18 namespace { 19 namespace {
19 20
20 LRESULT GetVolumeName(LPCWSTR drive, 21 LRESULT GetVolumeName(LPCWSTR drive,
21 LPWSTR volume_name, 22 LPWSTR volume_name,
22 unsigned int volume_name_len) { 23 unsigned int volume_name_len) {
23 return GetVolumeInformation(drive, volume_name, volume_name_len, NULL, NULL, 24 return GetVolumeInformation(drive, volume_name, volume_name_len, NULL, NULL,
24 NULL, NULL, 0); 25 NULL, NULL, 0);
25 } 26 }
26 27
27 // Returns 0 if the devicetype is not volume. 28 // Returns 0 if the devicetype is not volume.
28 DWORD GetVolumeBitMaskFromBroadcastHeader(DWORD data) { 29 DWORD GetVolumeBitMaskFromBroadcastHeader(DWORD data) {
29 PDEV_BROADCAST_HDR dev_broadcast_hdr = 30 PDEV_BROADCAST_HDR dev_broadcast_hdr =
30 reinterpret_cast<PDEV_BROADCAST_HDR>(data); 31 reinterpret_cast<PDEV_BROADCAST_HDR>(data);
31 if (dev_broadcast_hdr->dbch_devicetype == DBT_DEVTYP_VOLUME) { 32 if (dev_broadcast_hdr->dbch_devicetype == DBT_DEVTYP_VOLUME) {
32 PDEV_BROADCAST_VOLUME dev_broadcast_volume = 33 PDEV_BROADCAST_VOLUME dev_broadcast_volume =
33 reinterpret_cast<PDEV_BROADCAST_VOLUME>(dev_broadcast_hdr); 34 reinterpret_cast<PDEV_BROADCAST_VOLUME>(dev_broadcast_hdr);
34 return dev_broadcast_volume->dbcv_unitmask; 35 return dev_broadcast_volume->dbcv_unitmask;
35 } 36 }
36 return 0; 37 return 0;
37 } 38 }
38 39
39 } // namespace 40 } // namespace
40 41
42 namespace chrome {
41 43
42 SystemMessageWindowWin::SystemMessageWindowWin() 44 MediaDeviceNotificationsWindowWin::MediaDeviceNotificationsWindowWin()
43 : volume_name_func_(&GetVolumeName) { 45 : volume_name_func_(&GetVolumeName) {
44 Init(); 46 Init();
45 } 47 }
46 48
47 SystemMessageWindowWin::SystemMessageWindowWin(VolumeNameFunc volume_name_func) 49 MediaDeviceNotificationsWindowWin::MediaDeviceNotificationsWindowWin(
48 : volume_name_func_(volume_name_func) { 50 VolumeNameFunc volume_name_func) : volume_name_func_(volume_name_func) {
49 Init(); 51 Init();
50 } 52 }
51 53
52 void SystemMessageWindowWin::Init() { 54 void MediaDeviceNotificationsWindowWin::Init() {
53 HINSTANCE hinst = GetModuleHandle(NULL); 55 HINSTANCE hinst = GetModuleHandle(NULL);
54 56
55 WNDCLASSEX wc = {0}; 57 WNDCLASSEX wc = {0};
56 wc.cbSize = sizeof(wc); 58 wc.cbSize = sizeof(wc);
57 wc.lpfnWndProc = 59 wc.lpfnWndProc = base::win::WrappedWindowProc<
58 base::win::WrappedWindowProc<&SystemMessageWindowWin::WndProcThunk>; 60 &MediaDeviceNotificationsWindowWin::WndProcThunk>;
59 wc.hInstance = hinst; 61 wc.hInstance = hinst;
60 wc.lpszClassName = WindowClassName; 62 wc.lpszClassName = WindowClassName;
61 ATOM clazz = RegisterClassEx(&wc); 63 ATOM clazz = RegisterClassEx(&wc);
62 DCHECK(clazz); 64 DCHECK(clazz);
63 65
64 window_ = CreateWindow(WindowClassName, 66 window_ = CreateWindow(WindowClassName, 0, 0, 0, 0, 0, 0, 0, 0, hinst, 0);
65 0, 0, 0, 0, 0, 0, 0, 0, hinst, 0);
66 SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)); 67 SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
67 } 68 }
68 69
69 SystemMessageWindowWin::~SystemMessageWindowWin() { 70 MediaDeviceNotificationsWindowWin::~MediaDeviceNotificationsWindowWin() {
70 if (window_) { 71 if (window_) {
71 DestroyWindow(window_); 72 DestroyWindow(window_);
72 UnregisterClass(WindowClassName, GetModuleHandle(NULL)); 73 UnregisterClass(WindowClassName, GetModuleHandle(NULL));
73 } 74 }
74 } 75 }
75 76
76 LRESULT SystemMessageWindowWin::OnDeviceChange(UINT event_type, DWORD data) { 77 LRESULT MediaDeviceNotificationsWindowWin::OnDeviceChange(UINT event_type,
78 DWORD data) {
Lei Zhang 2012/04/24 23:10:42 nit: indentation
tpayne 2012/04/25 00:04:31 Done.
77 base::SystemMonitor* monitor = base::SystemMonitor::Get(); 79 base::SystemMonitor* monitor = base::SystemMonitor::Get();
78 switch (event_type) { 80 switch (event_type) {
79 case DBT_DEVNODES_CHANGED:
80 monitor->ProcessDevicesChanged();
81 break;
82 case DBT_DEVICEARRIVAL: { 81 case DBT_DEVICEARRIVAL: {
83 DWORD unitmask = GetVolumeBitMaskFromBroadcastHeader(data); 82 DWORD unitmask = GetVolumeBitMaskFromBroadcastHeader(data);
84 for (int i = 0; unitmask; ++i, unitmask >>= 1) { 83 for (int i = 0; unitmask; ++i, unitmask >>= 1) {
85 if (unitmask & 0x01) { 84 if (unitmask & 0x01) {
86 FilePath::StringType drive(L"_:\\"); 85 FilePath::StringType drive(L"_:\\");
87 drive[0] = L'A' + i; 86 drive[0] = L'A' + i;
88 WCHAR volume_name[MAX_PATH + 1]; 87 WCHAR volume_name[MAX_PATH + 1];
89 if ((*volume_name_func_)(drive.c_str(), volume_name, MAX_PATH + 1)) { 88 if ((*volume_name_func_)(drive.c_str(), volume_name, MAX_PATH + 1)) {
90 monitor->ProcessMediaDeviceAttached( 89 monitor->ProcessMediaDeviceAttached(
91 i, base::SysWideToUTF8(volume_name), FilePath(drive)); 90 i, base::SysWideToUTF8(volume_name), FilePath(drive));
92 } 91 }
93 } 92 }
94 } 93 }
95 break; 94 break;
96 } 95 }
97 case DBT_DEVICEREMOVECOMPLETE: { 96 case DBT_DEVICEREMOVECOMPLETE: {
98 DWORD unitmask = GetVolumeBitMaskFromBroadcastHeader(data); 97 DWORD unitmask = GetVolumeBitMaskFromBroadcastHeader(data);
99 for (int i = 0; unitmask; ++i, unitmask >>= 1) { 98 for (int i = 0; unitmask; ++i, unitmask >>= 1) {
100 if (unitmask & 0x01) { 99 if (unitmask & 0x01) {
101 monitor->ProcessMediaDeviceDetached(i); 100 monitor->ProcessMediaDeviceDetached(i);
102 } 101 }
103 } 102 }
104 break; 103 break;
105 } 104 }
106 } 105 }
107 return TRUE; 106 return TRUE;
108 } 107 }
109 108
110 LRESULT CALLBACK SystemMessageWindowWin::WndProc(HWND hwnd, UINT message, 109 LRESULT CALLBACK MediaDeviceNotificationsWindowWin::WndProc(
111 WPARAM wparam, LPARAM lparam) { 110 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
112 switch (message) { 111 switch (message) {
113 case WM_DEVICECHANGE: 112 case WM_DEVICECHANGE:
114 return OnDeviceChange(static_cast<UINT>(wparam), 113 return OnDeviceChange(static_cast<UINT>(wparam),
115 static_cast<DWORD>(lparam)); 114 static_cast<DWORD>(lparam));
116 default: 115 default:
117 break; 116 break;
118 } 117 }
119 118
120 return ::DefWindowProc(hwnd, message, wparam, lparam); 119 return ::DefWindowProc(hwnd, message, wparam, lparam);
121 } 120 }
121
122 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698