| 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 "base/message_pump_win.h" | 5 #include "base/message_pump_win.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/process_util.h" | |
| 12 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 13 #include "base/win/wrapped_window_proc.h" | 12 #include "base/win/wrapped_window_proc.h" |
| 14 | 13 |
| 15 namespace { | 14 namespace { |
| 16 | 15 |
| 17 // The ID of the timer used by the UI message pump. | 16 // The ID of the timer used by the UI message pump. |
| 18 const int kMessagePumpTimerId = 0; | 17 const int kMessagePumpTimerId = 0; |
| 19 | 18 |
| 20 } // namespace | 19 } // namespace |
| 21 | 20 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 if (more_work_is_plausible) | 245 if (more_work_is_plausible) |
| 247 continue; | 246 continue; |
| 248 | 247 |
| 249 WaitForWork(); // Wait (sleep) until we have work to do again. | 248 WaitForWork(); // Wait (sleep) until we have work to do again. |
| 250 } | 249 } |
| 251 } | 250 } |
| 252 | 251 |
| 253 void MessagePumpForUI::InitMessageWnd() { | 252 void MessagePumpForUI::InitMessageWnd() { |
| 254 // Register a unique window class for each instance of UI pump. | 253 // Register a unique window class for each instance of UI pump. |
| 255 string16 class_name = base::StringPrintf(kWndClassFormat, this); | 254 string16 class_name = base::StringPrintf(kWndClassFormat, this); |
| 256 WNDPROC window_procedure = &base::win::WrappedWindowProc<WndProcThunk>; | 255 WNDCLASSEX window_class; |
| 257 | 256 base::win::InitializeWindowClass( |
| 258 // RegisterClassEx uses a handle of the module containing the window procedure | 257 class_name.c_str(), |
| 259 // to distinguish identically named classes registered in different modules. | 258 &base::win::WrappedWindowProc<WndProcThunk>, |
| 260 instance_ = GetModuleFromAddress(window_procedure); | 259 0, 0, 0, NULL, NULL, NULL, NULL, NULL, |
| 261 | 260 &window_class); |
| 262 WNDCLASSEXW wc = {0}; | 261 instance_ = window_class.hInstance; |
| 263 wc.cbSize = sizeof(wc); | 262 atom_ = RegisterClassEx(&window_class); |
| 264 wc.lpfnWndProc = window_procedure; | |
| 265 wc.hInstance = instance_; | |
| 266 wc.lpszClassName = class_name.c_str(); | |
| 267 atom_ = RegisterClassEx(&wc); | |
| 268 if (atom_ == 0) { | 263 if (atom_ == 0) { |
| 269 DCHECK(atom_); | 264 DCHECK(atom_); |
| 270 return; | 265 return; |
| 271 } | 266 } |
| 272 | 267 |
| 273 // Create the message-only window. | 268 // Create the message-only window. |
| 274 message_hwnd_ = CreateWindow( | 269 message_hwnd_ = CreateWindow( |
| 275 reinterpret_cast<const char16*>(atom_), 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, | 270 MAKEINTATOM(atom_), 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, instance_, 0); |
| 276 instance_, 0); | |
| 277 if (message_hwnd_ == NULL) { | 271 if (message_hwnd_ == NULL) { |
| 278 DCHECK(message_hwnd_); | 272 DCHECK(message_hwnd_); |
| 279 return; | 273 return; |
| 280 } | 274 } |
| 281 | 275 |
| 282 // Store |this| so that the window procedure could retrieve it later. | 276 // Store |this| so that the window procedure could retrieve it later. |
| 283 SetWindowLongPtr(message_hwnd_, | 277 SetWindowLongPtr(message_hwnd_, |
| 284 GWLP_USERDATA, | 278 GWLP_USERDATA, |
| 285 reinterpret_cast<LONG_PTR>(this)); | 279 reinterpret_cast<LONG_PTR>(this)); |
| 286 } | 280 } |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 | 609 |
| 616 void MessagePumpForIO::WillProcessIOEvent() { | 610 void MessagePumpForIO::WillProcessIOEvent() { |
| 617 FOR_EACH_OBSERVER(IOObserver, io_observers_, WillProcessIOEvent()); | 611 FOR_EACH_OBSERVER(IOObserver, io_observers_, WillProcessIOEvent()); |
| 618 } | 612 } |
| 619 | 613 |
| 620 void MessagePumpForIO::DidProcessIOEvent() { | 614 void MessagePumpForIO::DidProcessIOEvent() { |
| 621 FOR_EACH_OBSERVER(IOObserver, io_observers_, DidProcessIOEvent()); | 615 FOR_EACH_OBSERVER(IOObserver, io_observers_, DidProcessIOEvent()); |
| 622 } | 616 } |
| 623 | 617 |
| 624 } // namespace base | 618 } // namespace base |
| OLD | NEW |