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

Unified Diff: ui/gfx/win/singleton_hwnd.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.h
diff --git a/ui/gfx/win/singleton_hwnd.h b/ui/gfx/win/singleton_hwnd.h
index 5dbfe90d2171b7964c90c5cc947759961ef4313a..789a60ff364dbe68033aba0dd35a39b62f515adf 100644
--- a/ui/gfx/win/singleton_hwnd.h
+++ b/ui/gfx/win/singleton_hwnd.h
@@ -8,34 +8,22 @@
#include <windows.h>
#include <vector>
-#include "base/basictypes.h"
-#include "base/callback_forward.h"
#include "base/observer_list.h"
+#include "ui/gfx/gfx_export.h"
#include "ui/gfx/win/window_impl.h"
template<typename T> struct DefaultSingletonTraits;
namespace gfx {
+class SingletonHwndObserver;
+
// Singleton message-only HWND that allows interested clients to receive WM_*
// notifications.
class GFX_EXPORT SingletonHwnd : public WindowImpl {
public:
static SingletonHwnd* GetInstance();
- // Observer interface for receiving Windows WM_* notifications.
- class Observer {
- public:
- virtual void OnWndProc(HWND hwnd,
- UINT message,
- WPARAM wparam,
- LPARAM lparam) = 0;
- };
-
- // Add/remove observer to receive WM_* notifications.
- void AddObserver(Observer* observer);
- void RemoveObserver(Observer* observer);
-
// Windows callback for WM_* notifications.
BOOL ProcessWindowMessage(HWND window,
UINT message,
@@ -45,13 +33,18 @@ class GFX_EXPORT SingletonHwnd : public WindowImpl {
DWORD msg_map_id) override;
private:
+ friend class SingletonHwndObserver;
friend struct DefaultSingletonTraits<SingletonHwnd>;
SingletonHwnd();
~SingletonHwnd() override;
+ // Add/remove SingletonHwndObserver to forward WM_* notifications.
+ void AddObserver(SingletonHwndObserver* observer);
+ void RemoveObserver(SingletonHwndObserver* observer);
+
// List of registered observers.
- ObserverList<Observer> observer_list_;
+ ObserverList<SingletonHwndObserver, true> observer_list_;
DISALLOW_COPY_AND_ASSIGN(SingletonHwnd);
};

Powered by Google App Engine
This is Rietveld 408576698