Chromium Code Reviews| Index: base/message_pump_win.cc |
| diff --git a/base/message_pump_win.cc b/base/message_pump_win.cc |
| index 9484b29e67c5cc00bd98e92e18a34e4f10e43c6b..2b40b6552d973c40b949f87bd46c4edd2ef7ef10 100644 |
| --- a/base/message_pump_win.cc |
| +++ b/base/message_pump_win.cc |
| @@ -8,11 +8,13 @@ |
| #include "base/message_loop.h" |
| #include "base/metrics/histogram.h" |
| +#include "base/process_util.h" |
| +#include "base/stringprintf.h" |
| #include "base/win/wrapped_window_proc.h" |
| namespace base { |
| -static const wchar_t kWndClass[] = L"Chrome_MessagePumpWindow"; |
| +static const wchar_t kWndClassFormat[] = L"Chrome_MessagePumpWindow%p"; |
| // Message sent to get an additional time slice for pumping (processing) another |
| // task (a series of such messages creates a continuous task pump). |
| @@ -82,13 +84,19 @@ int MessagePumpWin::GetCurrentDelay() const { |
| //----------------------------------------------------------------------------- |
| // MessagePumpForUI public: |
| -MessagePumpForUI::MessagePumpForUI() { |
| +MessagePumpForUI::MessagePumpForUI() |
| + : atom_(0), |
| + instance_(NULL), |
| + message_hwnd_(NULL) { |
| InitMessageWnd(); |
| } |
| MessagePumpForUI::~MessagePumpForUI() { |
| - DestroyWindow(message_hwnd_); |
| - UnregisterClass(kWndClass, GetModuleHandle(NULL)); |
| + if (message_hwnd_ != NULL) |
|
jar (doing other things)
2012/05/17 00:57:24
nit: you probably don't need this test. The const
|
| + DestroyWindow(message_hwnd_); |
| + |
| + if (atom_ != 0) |
|
jar (doing other things)
2012/05/17 00:57:24
nit: The test is not needed since the constructors
|
| + UnregisterClass(MAKEINTATOM(atom_), instance_); |
| } |
| void MessagePumpForUI::ScheduleWork() { |
| @@ -230,18 +238,21 @@ void MessagePumpForUI::DoRunLoop() { |
| } |
| void MessagePumpForUI::InitMessageWnd() { |
| - HINSTANCE hinst = GetModuleHandle(NULL); |
| + // Register a unique window class for each instance of the UI pump. |
| + string16 class_name = base::StringPrintf(kWndClassFormat, this); |
| WNDCLASSEX wc = {0}; |
| wc.cbSize = sizeof(wc); |
| wc.lpfnWndProc = base::win::WrappedWindowProc<WndProcThunk>; |
| - wc.hInstance = hinst; |
| - wc.lpszClassName = kWndClass; |
| - RegisterClassEx(&wc); |
| - |
| - message_hwnd_ = |
| - CreateWindow(kWndClass, 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, hinst, 0); |
| - DCHECK(message_hwnd_); |
| + instance_ = base::GetModuleFromAddress(static_cast<void*>(wc.lpfnWndProc)); |
|
jar (doing other things)
2012/05/17 02:48:09
Talking to rvargas, he notes that a "minimal" chan
alexeypa (please no reviews)
2012/05/17 18:30:19
I guess you are right. Sure such a fix will not gi
|
| + wc.hInstance = instance_; |
| + wc.lpszClassName = class_name.c_str(); |
| + atom_ = RegisterClassEx(&wc); |
| + CHECK(atom_ != 0); |
| + |
| + message_hwnd_ = CreateWindow( |
| + MAKEINTATOM(atom_), 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, instance_, 0); |
| + CHECK(message_hwnd_); |
| } |
| void MessagePumpForUI::WaitForWork() { |