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

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: Minor indent fix 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..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
« 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