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

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

Issue 10315012: Added base::win::InitializeWindowClass() wrapper to make sure that window classes are properly asso… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR feedback and rebased. Created 8 years, 7 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 #include <string> 9 #include <string>
10 10
(...skipping 24 matching lines...) Expand all
35 return dev_broadcast_volume->dbcv_unitmask; 35 return dev_broadcast_volume->dbcv_unitmask;
36 } 36 }
37 return 0; 37 return 0;
38 } 38 }
39 39
40 } // namespace 40 } // namespace
41 41
42 namespace chrome { 42 namespace chrome {
43 43
44 MediaDeviceNotificationsWindowWin::MediaDeviceNotificationsWindowWin() 44 MediaDeviceNotificationsWindowWin::MediaDeviceNotificationsWindowWin()
45 : volume_name_func_(&GetVolumeName) { 45 : atom_(0),
46 instance_(NULL),
47 window_(NULL),
48 volume_name_func_(&GetVolumeName) {
46 Init(); 49 Init();
47 } 50 }
48 51
49 MediaDeviceNotificationsWindowWin::MediaDeviceNotificationsWindowWin( 52 MediaDeviceNotificationsWindowWin::MediaDeviceNotificationsWindowWin(
50 VolumeNameFunc volume_name_func) : volume_name_func_(volume_name_func) { 53 VolumeNameFunc volume_name_func)
54 : atom_(0),
55 instance_(NULL),
56 window_(NULL),
57 volume_name_func_(volume_name_func) {
51 Init(); 58 Init();
52 } 59 }
53 60
54 void MediaDeviceNotificationsWindowWin::Init() { 61 void MediaDeviceNotificationsWindowWin::Init() {
55 HINSTANCE hinst = GetModuleHandle(NULL); 62 WNDCLASSEX window_class;
63 base::win::InitializeWindowClass(
64 WindowClassName,
65 &base::win::WrappedWindowProc<
66 MediaDeviceNotificationsWindowWin::WndProcThunk>,
67 0, 0, 0, NULL, NULL, NULL, NULL, NULL,
68 &window_class);
69 instance_ = window_class.hInstance;
70 atom_ = RegisterClassEx(&window_class);
71 DCHECK(atom_);
56 72
57 WNDCLASSEX wc = {0}; 73 window_ = CreateWindow(MAKEINTATOM(atom_), 0, 0, 0, 0, 0, 0, 0, 0, instance_,
58 wc.cbSize = sizeof(wc); 74 0);
59 wc.lpfnWndProc = base::win::WrappedWindowProc<
60 &MediaDeviceNotificationsWindowWin::WndProcThunk>;
61 wc.hInstance = hinst;
62 wc.lpszClassName = WindowClassName;
63 ATOM clazz = RegisterClassEx(&wc);
64 DCHECK(clazz);
65
66 window_ = CreateWindow(WindowClassName, 0, 0, 0, 0, 0, 0, 0, 0, hinst, 0);
67 SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)); 75 SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
68 } 76 }
69 77
70 MediaDeviceNotificationsWindowWin::~MediaDeviceNotificationsWindowWin() { 78 MediaDeviceNotificationsWindowWin::~MediaDeviceNotificationsWindowWin() {
71 if (window_) { 79 if (window_)
72 DestroyWindow(window_); 80 DestroyWindow(window_);
73 UnregisterClass(WindowClassName, GetModuleHandle(NULL)); 81
74 } 82 if (atom_)
83 UnregisterClass(MAKEINTATOM(atom_), instance_);
75 } 84 }
76 85
77 LRESULT MediaDeviceNotificationsWindowWin::OnDeviceChange(UINT event_type, 86 LRESULT MediaDeviceNotificationsWindowWin::OnDeviceChange(UINT event_type,
78 DWORD data) { 87 DWORD data) {
79 base::SystemMonitor* monitor = base::SystemMonitor::Get(); 88 base::SystemMonitor* monitor = base::SystemMonitor::Get();
80 switch (event_type) { 89 switch (event_type) {
81 case DBT_DEVICEARRIVAL: { 90 case DBT_DEVICEARRIVAL: {
82 DWORD unitmask = GetVolumeBitMaskFromBroadcastHeader(data); 91 DWORD unitmask = GetVolumeBitMaskFromBroadcastHeader(data);
83 for (int i = 0; unitmask; ++i, unitmask >>= 1) { 92 for (int i = 0; unitmask; ++i, unitmask >>= 1) {
84 if (unitmask & 0x01) { 93 if (unitmask & 0x01) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 LPARAM lparam) { 136 LPARAM lparam) {
128 MediaDeviceNotificationsWindowWin* msg_wnd = 137 MediaDeviceNotificationsWindowWin* msg_wnd =
129 reinterpret_cast<MediaDeviceNotificationsWindowWin*>( 138 reinterpret_cast<MediaDeviceNotificationsWindowWin*>(
130 GetWindowLongPtr(hwnd, GWLP_USERDATA)); 139 GetWindowLongPtr(hwnd, GWLP_USERDATA));
131 if (msg_wnd) 140 if (msg_wnd)
132 return msg_wnd->WndProc(hwnd, message, wparam, lparam); 141 return msg_wnd->WndProc(hwnd, message, wparam, lparam);
133 return ::DefWindowProc(hwnd, message, wparam, lparam); 142 return ::DefWindowProc(hwnd, message, wparam, lparam);
134 } 143 }
135 144
136 } // namespace chrome 145 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698