diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-27 20:51:51 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-27 20:51:51 +0000 |
commit | aef15bdabed270718140d5ec2eee49878bd91384 (patch) | |
tree | 2a5e395791ca9d9691987018a201c5b2ff70cf12 | |
parent | ffeba6d07caa89ac69f1c2ef0c19aa3b1bbe4117 (diff) | |
download | chromium_src-aef15bdabed270718140d5ec2eee49878bd91384.zip chromium_src-aef15bdabed270718140d5ec2eee49878bd91384.tar.gz chromium_src-aef15bdabed270718140d5ec2eee49878bd91384.tar.bz2 |
Relanding this.
The Ole unitialization was failing on one of the Vista build-bot.
It is not clear when the Ole initialization is balanced when a CRichEditCtrl is created/destructed.
So I now turn it off explicitly.
This CL makes sure we unregister our Windows window classes when shut-down.
It also balances-out an OLE initialization performed by the CRichEditCTRL.
This is necessary for allowing to reload chrome.dll in a process, which is what
the browser tests will do.
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/101004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14649 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/message_pump_win.cc | 3 | ||||
-rw-r--r-- | chrome/browser/process_singleton_win.cc | 7 | ||||
-rw-r--r-- | chrome/views/widget/widget_win.cc | 102 |
3 files changed, 71 insertions, 41 deletions
diff --git a/base/message_pump_win.cc b/base/message_pump_win.cc index 3af1991..737676c 100644 --- a/base/message_pump_win.cc +++ b/base/message_pump_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -88,6 +88,7 @@ MessagePumpForUI::MessagePumpForUI() { MessagePumpForUI::~MessagePumpForUI() { DestroyWindow(message_hwnd_); + UnregisterClass(kWndClass, GetModuleHandle(NULL)); } void MessagePumpForUI::ScheduleWork() { diff --git a/chrome/browser/process_singleton_win.cc b/chrome/browser/process_singleton_win.cc index 99d2d5f..c34a4d1 100644 --- a/chrome/browser/process_singleton_win.cc +++ b/chrome/browser/process_singleton_win.cc @@ -45,8 +45,10 @@ ProcessSingleton::ProcessSingleton(const FilePath& user_data_dir) } ProcessSingleton::~ProcessSingleton() { - if (window_) + if (window_) { DestroyWindow(window_); + UnregisterClass(chrome::kMessageWindowClass, GetModuleHandle(NULL)); + } } bool ProcessSingleton::NotifyOtherProcess() { @@ -142,7 +144,8 @@ void ProcessSingleton::Create() { wc.lpfnWndProc = ProcessSingleton::WndProcStatic; wc.hInstance = hinst; wc.lpszClassName = chrome::kMessageWindowClass; - RegisterClassEx(&wc); + ATOM clazz = RegisterClassEx(&wc); + DCHECK(clazz); std::wstring user_data_dir; PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); diff --git a/chrome/views/widget/widget_win.cc b/chrome/views/widget/widget_win.cc index a362f21..bdd709f 100644 --- a/chrome/views/widget/widget_win.cc +++ b/chrome/views/widget/widget_win.cc @@ -42,13 +42,6 @@ NativeControlWin* GetNativeControlWinForHWND(HWND hwnd) { ::GetProp(hwnd, NativeControlWin::kNativeControlWinKey)); } -// Used to locate the WidgetWin issuing the current Create. Only valid for the -// life of Create. -// -// This obviously assumes we only create WidgetWins from the same thread, -// which is currently the case. -static WidgetWin* instance_issuing_create = NULL; - /////////////////////////////////////////////////////////////////////////////// // Window class tracking. @@ -66,36 +59,75 @@ struct ClassInfo { background(NULL) {} // Compares two ClassInfos. Returns true if all members match. - bool Equals(const ClassInfo& other) { + bool Equals(const ClassInfo& other) const { return (other.style == style && other.background == background); } }; -// Represents a registered window class. -struct RegisteredClass { - RegisteredClass(const ClassInfo& info, - const std::wstring& name, - ATOM atom) - : info(info), - name(name), - atom(atom) { +class ClassRegistrar { + public: + ~ClassRegistrar() { + for (RegisteredClasses::iterator i = registered_classes_.begin(); + i != registered_classes_.end(); ++i) { + UnregisterClass(i->name.c_str(), NULL); + } } - // Info used to create the class. - ClassInfo info; + // Puts the name for the class matching |class_info| in |class_name|, creating + // a new name if the class is not yet known. + // Returns true if this class was already known, false otherwise. + bool RetrieveClassName(const ClassInfo& class_info, std::wstring* name) { + for (RegisteredClasses::const_iterator i = registered_classes_.begin(); + i != registered_classes_.end(); ++i) { + if (class_info.Equals(i->info)) { + name->assign(i->name); + return true; + } + } - // The name given to the window. - std::wstring name; + name->assign(std::wstring(WidgetWin::kBaseClassName) + + IntToWString(registered_count_++)); + return false; + } - // The ATOM returned from creating the window. - ATOM atom; -}; + void RegisterClass(const ClassInfo& class_info, + const std::wstring& name, + ATOM atom) { + registered_classes_.push_back(RegisteredClass(class_info, name, atom)); + } + + private: + // Represents a registered window class. + struct RegisteredClass { + RegisteredClass(const ClassInfo& info, + const std::wstring& name, + ATOM atom) + : info(info), + name(name), + atom(atom) { + } -typedef std::list<RegisteredClass> RegisteredClasses; + // Info used to create the class. + ClassInfo info; -// The list of registered classes. -static RegisteredClasses* registered_classes = NULL; + // The name given to the window. + std::wstring name; + // The ATOM returned from creating the window. + ATOM atom; + }; + + ClassRegistrar() : registered_count_(0) { } + friend struct DefaultSingletonTraits<ClassRegistrar>; + + typedef std::list<RegisteredClass> RegisteredClasses; + RegisteredClasses registered_classes_; + + // Counter of how many classes have ben registered so far. + int registered_count_; + + DISALLOW_COPY_AND_ASSIGN(ClassRegistrar); +}; /////////////////////////////////////////////////////////////////////////////// // WidgetWin, public @@ -855,19 +887,12 @@ void WidgetWin::UpdateWindowFromContents(HDC dib_dc) { } std::wstring WidgetWin::GetWindowClassName() { - if (!registered_classes) - registered_classes = new RegisteredClasses(); ClassInfo class_info(initial_class_style()); - for (RegisteredClasses::iterator i = registered_classes->begin(); - i != registered_classes->end(); ++i) { - if (class_info.Equals(i->info)) - return i->name; - } + std::wstring name; + if (Singleton<ClassRegistrar>()->RetrieveClassName(class_info, &name)) + return name; // No class found, need to register one. - static int registered_count = 0; - std::wstring name = - std::wstring(kBaseClassName) + IntToWString(registered_count++); WNDCLASSEX class_ex; class_ex.cbSize = sizeof(WNDCLASSEX); class_ex.style = class_info.style; @@ -884,8 +909,9 @@ std::wstring WidgetWin::GetWindowClassName() { class_ex.hIconSm = class_ex.hIcon; ATOM atom = RegisterClassEx(&class_ex); DCHECK(atom); - RegisteredClass registered_class(class_info, name, atom); - registered_classes->push_back(registered_class); + + Singleton<ClassRegistrar>()->RegisterClass(class_info, name, atom); + return name; } |