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

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

Issue 1092183005: Fix Up SingletonHwnd Observer Lifetime Issues (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Allow null SingletonHwnd Hwnd 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_observer.cc
diff --git a/ui/gfx/win/singleton_hwnd_observer.cc b/ui/gfx/win/singleton_hwnd_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f439105e659d2a8aba8f0b4cef38ce602bfff918
--- /dev/null
+++ b/ui/gfx/win/singleton_hwnd_observer.cc
@@ -0,0 +1,35 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gfx/win/singleton_hwnd_observer.h"
+
+#include "ui/gfx/win/singleton_hwnd.h"
+
+namespace gfx {
+
+SingletonHwndObserver::SingletonHwndObserver(const WndProc& wnd_proc)
+ : wnd_proc_(wnd_proc) {
+ DCHECK(!wnd_proc.is_null());
+ SingletonHwnd::GetInstance()->AddObserver(this);
+}
+
+SingletonHwndObserver::~SingletonHwndObserver() {
+ ClearWndProc();
+}
+
+void SingletonHwndObserver::ClearWndProc() {
+ if (!wnd_proc_.is_null()) {
+ SingletonHwnd::GetInstance()->RemoveObserver(this);
+ wnd_proc_.Reset();
+ }
+}
+
+void SingletonHwndObserver::OnWndProc(HWND hwnd,
+ UINT message,
+ WPARAM wparam,
+ LPARAM lparam) {
+ wnd_proc_.Run(hwnd, message, wparam, lparam);
+}
+
+} // namespace gfx
« ui/gfx/sys_color_change_listener.cc ('K') | « ui/gfx/win/singleton_hwnd_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698