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

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

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.h
diff --git a/ui/gfx/win/singleton_hwnd_observer.h b/ui/gfx/win/singleton_hwnd_observer.h
new file mode 100644
index 0000000000000000000000000000000000000000..a1bd52448104c08f29cb06ed412a24dcc7e14079
--- /dev/null
+++ b/ui/gfx/win/singleton_hwnd_observer.h
@@ -0,0 +1,40 @@
+// 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.
+
+#ifndef UI_GFX_WIN_SINGLETON_HWND_OBSERVER_H_
+#define UI_GFX_WIN_SINGLETON_HWND_OBSERVER_H_
+
+#include <windows.h>
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "ui/gfx/gfx_export.h"
+
+namespace gfx {
+
+class SingletonHwnd;
+
+// Singleton lifetime management is tricky. This observer handles the correct
+// cleanup if either the SingletonHwnd or forwarded object is destroyed first.
+class GFX_EXPORT SingletonHwndObserver {
+ public:
+ typedef base::Callback<void(HWND, UINT, WPARAM, LPARAM)> WndProc;
+
+ explicit SingletonHwndObserver(const WndProc& wnd_proc);
+ ~SingletonHwndObserver();
+
+ private:
+ friend class SingletonHwnd;
+
+ void ClearWndProc();
+ void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
+
+ WndProc wnd_proc_;
+
+ DISALLOW_COPY_AND_ASSIGN(SingletonHwndObserver);
+};
+
+} // namespace gfx
+
+#endif // UI_GFX_WIN_SINGLETON_HWND_OBSERVER_H_

Powered by Google App Engine
This is Rietveld 408576698