summaryrefslogtreecommitdiffstats
path: root/base/win
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-28 23:47:11 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-28 23:47:11 +0000
commit9b917fdc65319d6d83a5185510cda82e3aaf1c74 (patch)
tree6cfc87a06f4d6e013967cf2beb011151d5891430 /base/win
parenta1bfc8a9208af349125e54706e06b083e7d938d7 (diff)
downloadchromium_src-9b917fdc65319d6d83a5185510cda82e3aaf1c74.zip
chromium_src-9b917fdc65319d6d83a5185510cda82e3aaf1c74.tar.gz
chromium_src-9b917fdc65319d6d83a5185510cda82e3aaf1c74.tar.bz2
Revert 209047 "ProcessSingleton now uses base::win::MessageWindo..."
> ProcessSingleton now uses base::win::MessageWindow to create a message-only window. > > Collateral changes: > - base::win::MessageWindow registes a single window class used by all message-only windows it creates. The class is registered via base::LazyInstance. > - Added base::win::MessageWindow::FindWindow() wrapper used to find other message-only windows, including the other created by a different process. > - Removed chrome::kMessageWindowClass constant. > > Review URL: https://chromiumcodereview.appspot.com/17615003 TBR=alexeypa@chromium.org Review URL: https://codereview.chromium.org/18040003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@209232 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/win')
-rw-r--r--base/win/message_window.cc103
-rw-r--r--base/win/message_window.h13
-rw-r--r--base/win/message_window_unittest.cc13
3 files changed, 43 insertions, 86 deletions
diff --git a/base/win/message_window.cc b/base/win/message_window.cc
index fa6381b..8a9c287 100644
--- a/base/win/message_window.cc
+++ b/base/win/message_window.cc
@@ -4,68 +4,20 @@
#include "base/win/message_window.h"
-#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/process_util.h"
+#include "base/strings/string16.h"
+#include "base/strings/stringprintf.h"
#include "base/win/wrapped_window_proc.h"
-const wchar_t kMessageWindowClassName[] = L"Chrome_MessageWindow";
+const wchar_t kClassNameFormat[] = L"Chrome_MessageWindow_%p";
namespace base {
namespace win {
-// Used along with LazyInstance to register a window class for message-only
-// windows created by MessageWindow.
-class MessageWindow::WindowClass {
- public:
- WindowClass();
- ~WindowClass();
-
- ATOM atom() { return atom_; }
- HINSTANCE instance() { return instance_; }
-
- private:
- ATOM atom_;
- HINSTANCE instance_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowClass);
-};
-
-static LazyInstance<MessageWindow::WindowClass> g_window_class =
- LAZY_INSTANCE_INITIALIZER;
-
-MessageWindow::WindowClass::WindowClass()
- : atom_(0),
- instance_(base::GetModuleFromAddress(&MessageWindow::WindowProc)) {
- WNDCLASSEX window_class;
- window_class.cbSize = sizeof(window_class);
- window_class.style = 0;
- window_class.lpfnWndProc = &base::win::WrappedWindowProc<WindowProc>;
- window_class.cbClsExtra = 0;
- window_class.cbWndExtra = 0;
- window_class.hInstance = instance_;
- window_class.hIcon = NULL;
- window_class.hCursor = NULL;
- window_class.hbrBackground = NULL;
- window_class.lpszMenuName = NULL;
- window_class.lpszClassName = kMessageWindowClassName;
- window_class.hIconSm = NULL;
- atom_ = RegisterClassEx(&window_class);
- if (atom_ == 0) {
- LOG_GETLASTERROR(ERROR)
- << "Failed to register the window class for a message-only window";
- }
-}
-
-MessageWindow::WindowClass::~WindowClass() {
- if (atom_ != 0) {
- BOOL result = UnregisterClass(MAKEINTATOM(atom_), instance_);
- DCHECK(result);
- }
-}
-
MessageWindow::MessageWindow()
- : window_(NULL) {
+ : atom_(0),
+ window_(NULL) {
}
MessageWindow::~MessageWindow() {
@@ -75,6 +27,13 @@ MessageWindow::~MessageWindow() {
BOOL result = DestroyWindow(window_);
DCHECK(result);
}
+
+ if (atom_ != 0) {
+ BOOL result = UnregisterClass(
+ MAKEINTATOM(atom_),
+ base::GetModuleFromAddress(&MessageWindow::WindowProc));
+ DCHECK(result);
+ }
}
bool MessageWindow::Create(const MessageCallback& message_callback) {
@@ -86,23 +45,41 @@ bool MessageWindow::CreateNamed(const MessageCallback& message_callback,
return DoCreate(message_callback, window_name.c_str());
}
-// static
-HWND MessageWindow::FindWindow(const string16& window_name) {
- return FindWindowEx(HWND_MESSAGE, NULL, kMessageWindowClassName,
- window_name.c_str());
-}
-
bool MessageWindow::DoCreate(const MessageCallback& message_callback,
- const wchar_t* window_name) {
+ const wchar_t* window_name) {
DCHECK(CalledOnValidThread());
+ DCHECK(!atom_);
DCHECK(message_callback_.is_null());
DCHECK(!window_);
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);
+ // Register a separate window class for each instance of |MessageWindow|.
+ string16 class_name = base::StringPrintf(kClassNameFormat, this);
+ HINSTANCE instance = base::GetModuleFromAddress(&MessageWindow::WindowProc);
+
+ WNDCLASSEX window_class;
+ window_class.cbSize = sizeof(window_class);
+ window_class.style = 0;
+ window_class.lpfnWndProc = &base::win::WrappedWindowProc<WindowProc>;
+ window_class.cbClsExtra = 0;
+ window_class.cbWndExtra = 0;
+ window_class.hInstance = instance;
+ window_class.hIcon = NULL;
+ window_class.hCursor = NULL;
+ window_class.hbrBackground = NULL;
+ window_class.lpszMenuName = NULL;
+ window_class.lpszClassName = class_name.c_str();
+ window_class.hIconSm = NULL;
+ atom_ = RegisterClassEx(&window_class);
+ if (atom_ == 0) {
+ LOG_GETLASTERROR(ERROR)
+ << "Failed to register the window class for a message-only window";
+ return false;
+ }
+
+ window_ = CreateWindow(MAKEINTATOM(atom_), window_name, 0, 0, 0, 0, 0,
+ HWND_MESSAGE, 0, instance, this);
if (!window_) {
LOG_GETLASTERROR(ERROR) << "Failed to create a message-only window";
return false;
diff --git a/base/win/message_window.h b/base/win/message_window.h
index d255eec..4fd5074 100644
--- a/base/win/message_window.h
+++ b/base/win/message_window.h
@@ -20,9 +20,6 @@ namespace win {
// Implements a message-only window.
class BASE_EXPORT MessageWindow : public base::NonThreadSafe {
public:
- // Used to register a process-wide message window class.
- class WindowClass;
-
// Implement this callback to handle messages received by the message window.
// If the callback returns |false|, the first four parameters are passed to
// DefWindowProc(). Otherwise, |*result| is returned by the window procedure.
@@ -44,14 +41,7 @@ class BASE_EXPORT MessageWindow : public base::NonThreadSafe {
HWND hwnd() const { return window_; }
- // Retrieves a handle of the first message-only window with matching
- // |windows_name|.
- static HWND FindWindow(const string16& window_name);
-
private:
- // Give |WindowClass| access to WindowProc().
- friend class WindowClass;
-
// Contains the actual window creation code.
bool DoCreate(const MessageCallback& message_callback,
const wchar_t* window_name);
@@ -60,6 +50,9 @@ class BASE_EXPORT MessageWindow : public base::NonThreadSafe {
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wparam,
LPARAM lparam);
+ // Atom representing the registered window class.
+ ATOM atom_;
+
// Invoked to handle messages received by the window.
MessageCallback message_callback_;
diff --git a/base/win/message_window_unittest.cc b/base/win/message_window_unittest.cc
index 00248bf..c933ef7 100644
--- a/base/win/message_window_unittest.cc
+++ b/base/win/message_window_unittest.cc
@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "base/bind.h"
-#include "base/guid.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/message_window.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -32,7 +31,6 @@ TEST(MessageWindowTest, Create) {
EXPECT_TRUE(window.Create(base::Bind(&HandleMessage)));
}
-// Checks that a named window can be created.
TEST(MessageWindowTest, CreateNamed) {
win::MessageWindow window;
EXPECT_TRUE(window.CreateNamed(base::Bind(&HandleMessage),
@@ -47,15 +45,4 @@ TEST(MessageWindowTest, SendMessage) {
EXPECT_EQ(SendMessage(window.hwnd(), WM_USER, 100, 0), 100);
}
-// Verifies that a named window can be found by name.
-TEST(MessageWindowTest, FindWindow) {
- string16 name = UTF8ToUTF16(base::GenerateGUID());
- win::MessageWindow window;
- EXPECT_TRUE(window.CreateNamed(base::Bind(&HandleMessage), name));
-
- HWND hwnd = win::MessageWindow::FindWindow(name);
- EXPECT_TRUE(hwnd != NULL);
- EXPECT_EQ(SendMessage(hwnd, WM_USER, 200, 0), 200);
-}
-
} // namespace base