| 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_loop/message_pump_win.h" | 5 #include "base/message_loop/message_pump_win.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| 11 | 11 |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/process/memory.h" | |
| 15 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 16 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 16 #include "base/win/current_module.h" |
| 17 #include "base/win/wrapped_window_proc.h" | 17 #include "base/win/wrapped_window_proc.h" |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 enum MessageLoopProblems { | 23 enum MessageLoopProblems { |
| 24 MESSAGE_POST_ERROR, | 24 MESSAGE_POST_ERROR, |
| 25 COMPLETION_POST_ERROR, | 25 COMPLETION_POST_ERROR, |
| 26 SET_TIMER_ERROR, | 26 SET_TIMER_ERROR, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 //----------------------------------------------------------------------------- | 82 //----------------------------------------------------------------------------- |
| 83 // MessagePumpForUI public: | 83 // MessagePumpForUI public: |
| 84 | 84 |
| 85 MessagePumpForUI::MessagePumpForUI() | 85 MessagePumpForUI::MessagePumpForUI() |
| 86 : atom_(0) { | 86 : atom_(0) { |
| 87 InitMessageWnd(); | 87 InitMessageWnd(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 MessagePumpForUI::~MessagePumpForUI() { | 90 MessagePumpForUI::~MessagePumpForUI() { |
| 91 DestroyWindow(message_hwnd_); | 91 DestroyWindow(message_hwnd_); |
| 92 UnregisterClass(MAKEINTATOM(atom_), | 92 UnregisterClass(MAKEINTATOM(atom_), CURRENT_MODULE()); |
| 93 GetModuleFromAddress(&WndProcThunk)); | |
| 94 } | 93 } |
| 95 | 94 |
| 96 void MessagePumpForUI::ScheduleWork() { | 95 void MessagePumpForUI::ScheduleWork() { |
| 97 if (InterlockedExchange(&have_work_, 1)) | 96 if (InterlockedExchange(&have_work_, 1)) |
| 98 return; // Someone else continued the pumping. | 97 return; // Someone else continued the pumping. |
| 99 | 98 |
| 100 // Make sure the MessagePump does some work for us. | 99 // Make sure the MessagePump does some work for us. |
| 101 BOOL ret = PostMessage(message_hwnd_, kMsgHaveWork, | 100 BOOL ret = PostMessage(message_hwnd_, kMsgHaveWork, |
| 102 reinterpret_cast<WPARAM>(this), 0); | 101 reinterpret_cast<WPARAM>(this), 0); |
| 103 if (ret) | 102 if (ret) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 continue; | 190 continue; |
| 192 | 191 |
| 193 WaitForWork(); // Wait (sleep) until we have work to do again. | 192 WaitForWork(); // Wait (sleep) until we have work to do again. |
| 194 } | 193 } |
| 195 } | 194 } |
| 196 | 195 |
| 197 void MessagePumpForUI::InitMessageWnd() { | 196 void MessagePumpForUI::InitMessageWnd() { |
| 198 // Generate a unique window class name. | 197 // Generate a unique window class name. |
| 199 string16 class_name = StringPrintf(kWndClassFormat, this); | 198 string16 class_name = StringPrintf(kWndClassFormat, this); |
| 200 | 199 |
| 201 HINSTANCE instance = GetModuleFromAddress(&WndProcThunk); | 200 HINSTANCE instance = CURRENT_MODULE(); |
| 202 WNDCLASSEX wc = {0}; | 201 WNDCLASSEX wc = {0}; |
| 203 wc.cbSize = sizeof(wc); | 202 wc.cbSize = sizeof(wc); |
| 204 wc.lpfnWndProc = base::win::WrappedWindowProc<WndProcThunk>; | 203 wc.lpfnWndProc = base::win::WrappedWindowProc<WndProcThunk>; |
| 205 wc.hInstance = instance; | 204 wc.hInstance = instance; |
| 206 wc.lpszClassName = class_name.c_str(); | 205 wc.lpszClassName = class_name.c_str(); |
| 207 atom_ = RegisterClassEx(&wc); | 206 atom_ = RegisterClassEx(&wc); |
| 208 DCHECK(atom_); | 207 DCHECK(atom_); |
| 209 | 208 |
| 210 message_hwnd_ = CreateWindow(MAKEINTATOM(atom_), 0, 0, 0, 0, 0, 0, | 209 message_hwnd_ = CreateWindow(MAKEINTATOM(atom_), 0, 0, 0, 0, 0, 0, |
| 211 HWND_MESSAGE, 0, instance, 0); | 210 HWND_MESSAGE, 0, instance, 0); |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 | 632 |
| 634 // static | 633 // static |
| 635 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( | 634 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( |
| 636 ULONG_PTR key, | 635 ULONG_PTR key, |
| 637 bool* has_valid_io_context) { | 636 bool* has_valid_io_context) { |
| 638 *has_valid_io_context = ((key & 1) == 0); | 637 *has_valid_io_context = ((key & 1) == 0); |
| 639 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); | 638 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); |
| 640 } | 639 } |
| 641 | 640 |
| 642 } // namespace base | 641 } // namespace base |
| OLD | NEW |