Index: base/win/message_window.cc |
diff --git a/base/win/message_window.cc b/base/win/message_window.cc |
index 26b64a533887e0e619d7b50a4d36f2de69d6303e..55ccd044906d0ea587a534b26d99ae62f870b8a5 100644 |
--- a/base/win/message_window.cc |
+++ b/base/win/message_window.cc |
@@ -4,7 +4,7 @@ |
#include "base/win/message_window.h" |
-#include "base/lazy_instance.h" |
+#include "base/at_exit.h" |
#include "base/logging.h" |
#include "base/macros.h" |
#include "base/win/current_module.h" |
@@ -15,8 +15,8 @@ const wchar_t kMessageWindowClassName[] = L"Chrome_MessageWindow"; |
namespace base { |
namespace win { |
-// Used along with LazyInstance to register a window class for message-only |
-// windows created by MessageWindow. |
+// Used along with a threadsafe static pointer to register a window class for |
+// message-only windows created by MessageWindow. |
class MessageWindow::WindowClass { |
public: |
WindowClass(); |
@@ -32,8 +32,17 @@ class MessageWindow::WindowClass { |
DISALLOW_COPY_AND_ASSIGN(WindowClass); |
}; |
-static LazyInstance<MessageWindow::WindowClass> g_window_class = |
- LAZY_INSTANCE_INITIALIZER; |
+MessageWindow::WindowClass* GetWindowClass() { |
+ static MessageWindow::WindowClass* window_class = []() { |
+ auto ret = new MessageWindow::WindowClass(); |
+ auto deleter = [](void* p) { |
+ delete reinterpret_cast<MessageWindow::WindowClass*>(p); |
+ }; |
+ AtExitManager::RegisterCallback(deleter, ret); |
scottmg
2017/01/31 21:27:43
This "quick fix" is incorrect because in tests the
|
+ return ret; |
+ }(); |
+ return window_class; |
+} |
MessageWindow::WindowClass::WindowClass() |
: atom_(0), instance_(CURRENT_MODULE()) { |
@@ -104,9 +113,9 @@ bool MessageWindow::DoCreate(const MessageCallback& message_callback, |
message_callback_ = message_callback; |
- WindowClass& window_class = g_window_class.Get(); |
- window_ = CreateWindow(MAKEINTATOM(window_class.atom()), window_name, 0, 0, 0, |
- 0, 0, HWND_MESSAGE, 0, window_class.instance(), this); |
+ window_ = |
+ CreateWindow(MAKEINTATOM(GetWindowClass()->atom()), window_name, 0, 0, 0, |
+ 0, 0, HWND_MESSAGE, 0, GetWindowClass()->instance(), this); |
if (!window_) { |
PLOG(ERROR) << "Failed to create a message-only window"; |
return false; |