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

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

Issue 1092183005: Fix Up SingletonHwnd Observer Lifetime Issues (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Convert to scoped_ptr Created 5 years, 8 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
Index: ui/gfx/win/singleton_hwnd.cc
diff --git a/ui/gfx/win/singleton_hwnd.cc b/ui/gfx/win/singleton_hwnd.cc
index fc4d11f2d5e0d8146d9a3fa5c0f666e2e3c86676..79d51512545ea2b82211d54035e70624132328e5 100644
--- a/ui/gfx/win/singleton_hwnd.cc
+++ b/ui/gfx/win/singleton_hwnd.cc
@@ -6,6 +6,7 @@
#include "base/memory/singleton.h"
#include "base/message_loop/message_loop.h"
+#include "ui/gfx/win/singleton_hwnd_observer.h"
namespace gfx {
@@ -14,23 +15,13 @@ SingletonHwnd* SingletonHwnd::GetInstance() {
return Singleton<SingletonHwnd>::get();
}
-void SingletonHwnd::AddObserver(Observer* observer) {
- observer_list_.AddObserver(observer);
-}
-
-void SingletonHwnd::RemoveObserver(Observer* observer) {
- if (!hwnd())
- return;
- observer_list_.RemoveObserver(observer);
-}
-
BOOL SingletonHwnd::ProcessWindowMessage(HWND window,
UINT message,
WPARAM wparam,
LPARAM lparam,
LRESULT& result,
DWORD msg_map_id) {
- FOR_EACH_OBSERVER(Observer,
+ FOR_EACH_OBSERVER(SingletonHwndObserver,
observer_list_,
OnWndProc(window, message, wparam, lparam));
return false;
@@ -47,6 +38,18 @@ SingletonHwnd::SingletonHwnd() {
}
SingletonHwnd::~SingletonHwnd() {
+ // WindowImpl will clean up the hwnd value on WM_NCDESTROY.
+ DestroyWindow(hwnd());
+ DCHECK(!observer_list_.might_have_observers());
sky 2015/04/28 13:20:34 Instead of this define observer_list_ like base::O
robliao 2015/04/28 14:11:55 Neat. Done.
+}
+
+void SingletonHwnd::AddObserver(SingletonHwndObserver* observer) {
+ DCHECK(hwnd());
+ observer_list_.AddObserver(observer);
+}
+
+void SingletonHwnd::RemoveObserver(SingletonHwndObserver* observer) {
+ observer_list_.RemoveObserver(observer);
}
} // namespace gfx

Powered by Google App Engine
This is Rietveld 408576698