Chromium Code Reviews| 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..b211de168bb0b5fa198dcca1286ed58ae34ab3ee 100644 |
| --- a/ui/gfx/win/window_impl.cc |
| +++ b/ui/gfx/win/window_impl.cc |
| @@ -50,6 +50,8 @@ class ClassRegistrar { |
| static ClassRegistrar* GetInstance(); |
| + void UnregisterClasses(); |
| + |
| // 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 +59,22 @@ class ClassRegistrar { |
| private: |
| // Represents a registered window class. |
| struct RegisteredClass { |
| - RegisteredClass(const ClassInfo& info, ATOM atom); |
| + RegisteredClass(const ClassInfo& info, |
| + base::string16 name, |
|
Bernhard Bauer
2014/09/12 08:22:33
Pass by const reference?
|
| + 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(); |
| @@ -88,6 +99,18 @@ ClassRegistrar* ClassRegistrar::GetInstance() { |
| LeakySingletonTraits<ClassRegistrar> >::get(); |
| } |
| +void ClassRegistrar::UnregisterClasses() { |
| + for (RegisteredClasses::iterator i = registered_classes_.begin(); |
| + i != registered_classes_.end(); ++i) { |
| + if (UnregisterClass(MAKEINTATOM(i->atom), i->instance)) { |
| + registered_classes_.erase(i); |
| + } else { |
| + LOG(ERROR) << "Failed to unregister class " << i->name |
| + << ". Error = " << GetLastError(); |
| + } |
| + } |
| +} |
| + |
| ATOM ClassRegistrar::RetrieveClassAtom(const ClassInfo& class_info) { |
| base::AutoLock auto_lock(lock_); |
| for (RegisteredClasses::const_iterator i = registered_classes_.begin(); |
| @@ -117,15 +140,20 @@ 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) {} |
| @@ -149,6 +177,11 @@ WindowImpl::~WindowImpl() { |
| ClearUserData(); |
| } |
| +// static |
| +void WindowImpl::SetUnregisterClassesAtExit(bool unregister_classes_at_exit) { |
|
Bernhard Bauer
2014/09/12 08:22:33
This parameter isn't used (and not declared in the
|
| + base::AtExitManager::RegisterCallback(&WindowImpl::UnregisterClasses, NULL); |
| +} |
| + |
| void WindowImpl::Init(HWND parent, const Rect& bounds) { |
| if (window_style_ == 0) |
| window_style_ = parent ? kWindowDefaultChildStyle : kWindowDefaultStyle; |
| @@ -273,4 +306,9 @@ ATOM WindowImpl::GetWindowClassAtom() { |
| return ClassRegistrar::GetInstance()->RetrieveClassAtom(class_info); |
| } |
| +// static |
| +void WindowImpl::UnregisterClasses(void* dummy) { |
|
Bernhard Bauer
2014/09/12 08:22:33
AtExitManager::RegisterCallback also takes a base:
|
| + ClassRegistrar::GetInstance()->UnregisterClasses(); |
| +} |
| + |
| } // namespace gfx |