Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(558)

Unified Diff: ui/gfx/win/window_impl.cc

Issue 557513002: Deregister window classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make name arg a const ref Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/win/window_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b0c4fa7ad34349c7e10bb7a5663d13287ee65cec 100644
--- a/ui/gfx/win/window_impl.cc
+++ b/ui/gfx/win/window_impl.cc
@@ -6,6 +6,7 @@
#include <list>
+#include "base/bind.h"
#include "base/debug/alias.h"
#include "base/memory/singleton.h"
#include "base/strings/string_number_conversions.h"
@@ -50,6 +51,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 +60,22 @@ class ClassRegistrar {
private:
// Represents a registered window class.
struct RegisteredClass {
- RegisteredClass(const ClassInfo& info, ATOM atom);
+ RegisteredClass(const ClassInfo& info,
+ const 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();
@@ -85,7 +97,19 @@ ClassRegistrar::~ClassRegistrar() {}
// static
ClassRegistrar* ClassRegistrar::GetInstance() {
return Singleton<ClassRegistrar,
- LeakySingletonTraits<ClassRegistrar> >::get();
+ 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) {
@@ -117,15 +141,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)
+ const base::string16& name,
+ ATOM atom,
+ HMODULE instance)
: info(info),
- atom(atom) {}
+ name(name),
+ atom(atom),
+ instance(instance) {}
ClassRegistrar::ClassRegistrar() : registered_count_(0) {}
@@ -149,6 +178,13 @@ WindowImpl::~WindowImpl() {
ClearUserData();
}
+// static
+void WindowImpl::UnregisterClassesAtExit() {
+ base::AtExitManager::RegisterTask(
+ base::Bind(&ClassRegistrar::UnregisterClasses,
+ base::Unretained(ClassRegistrar::GetInstance())));
+}
+
void WindowImpl::Init(HWND parent, const Rect& bounds) {
if (window_style_ == 0)
window_style_ = parent ? kWindowDefaultChildStyle : kWindowDefaultStyle;
« no previous file with comments | « ui/gfx/win/window_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698