Index: ui/gfx/win/window_impl.cc |
diff --git a/ui/gfx/win/window_impl.cc b/ui/gfx/win/window_impl.cc |
index ff9fe57cf9dd8e5a2e21a6ea270c8c995e276084..c9cfe537c159361f963732601f9faa6b8ff0e8c4 100644 |
--- a/ui/gfx/win/window_impl.cc |
+++ b/ui/gfx/win/window_impl.cc |
@@ -50,6 +50,10 @@ class ClassRegistrar { |
static ClassRegistrar* GetInstance(); |
+ void set_unregister_at_exit(bool unregister_at_exit) { |
+ unregister_at_exit_ = unregister_at_exit; |
+ } |
+ |
// Returns the atom identifying the class matching |class_info|, |
// creating and registering a new class if the class is not yet known. |
ATOM RetrieveClassAtom(const ClassInfo& class_info); |
@@ -57,13 +61,22 @@ class ClassRegistrar { |
private: |
// Represents a registered window class. |
struct RegisteredClass { |
- RegisteredClass(const ClassInfo& info, ATOM atom); |
+ RegisteredClass(const ClassInfo& info, |
+ base::string16 name, |
+ ATOM atom, |
+ HINSTANCE instance); |
// Info used to create the class. |
ClassInfo info; |
+ // The name given to the window class |
+ base::string16 name; |
+ |
// The atom identifying the window class. |
ATOM atom; |
+ |
+ // The handle of the module containing the window proceedure. |
+ HMODULE instance; |
}; |
ClassRegistrar(); |
@@ -75,17 +88,30 @@ class ClassRegistrar { |
// Counter of how many classes have been registered so far. |
int registered_count_; |
+ // If true all registered classes will be unregistered upon exit. |
+ bool unregister_at_exit_; |
+ |
base::Lock lock_; |
DISALLOW_COPY_AND_ASSIGN(ClassRegistrar); |
}; |
-ClassRegistrar::~ClassRegistrar() {} |
+ClassRegistrar::~ClassRegistrar() { |
+ if (!unregister_at_exit_) |
+ return; |
+ |
+ for (RegisteredClasses::iterator i = registered_classes_.begin(); |
+ i != registered_classes_.end(); ++i) { |
+ if (!UnregisterClass(MAKEINTATOM(i->atom), i->instance)) { |
+ LOG(ERROR) << "Failed to unregister class " << i->name |
+ << ". Error = " << GetLastError(); |
+ } |
+ } |
+ } |
// static |
ClassRegistrar* ClassRegistrar::GetInstance() { |
- return Singleton<ClassRegistrar, |
- LeakySingletonTraits<ClassRegistrar> >::get(); |
+ return Singleton<ClassRegistrar>::get(); |
} |
ATOM ClassRegistrar::RetrieveClassAtom(const ClassInfo& class_info) { |
@@ -117,17 +143,24 @@ ATOM ClassRegistrar::RetrieveClassAtom(const ClassInfo& class_info) { |
ATOM atom = RegisterClassEx(&window_class); |
CHECK(atom) << GetLastError(); |
- registered_classes_.push_back(RegisteredClass(class_info, atom)); |
+ registered_classes_.push_back(RegisteredClass( |
+ class_info, name, atom, instance)); |
return atom; |
} |
ClassRegistrar::RegisteredClass::RegisteredClass(const ClassInfo& info, |
- ATOM atom) |
+ base::string16 name, |
+ ATOM atom, |
+ HMODULE instance) |
: info(info), |
- atom(atom) {} |
+ name(name), |
+ atom(atom), |
+ instance(instance) {} |
-ClassRegistrar::ClassRegistrar() : registered_count_(0) {} |
+ClassRegistrar::ClassRegistrar() |
+ : registered_count_(0), |
+ unregister_at_exit_(false) {} |
/////////////////////////////////////////////////////////////////////////////// |
@@ -149,6 +182,12 @@ WindowImpl::~WindowImpl() { |
ClearUserData(); |
} |
+// static |
+void WindowImpl::SetUnregisterClassesAtExit(bool unregister_classes_at_exit) { |
+ ClassRegistrar::GetInstance()->set_unregister_at_exit( |
+ unregister_classes_at_exit); |
+} |
+ |
void WindowImpl::Init(HWND parent, const Rect& bounds) { |
if (window_style_ == 0) |
window_style_ = parent ? kWindowDefaultChildStyle : kWindowDefaultStyle; |