Chromium Code Reviews| Index: ui/base/win/singleton_hwnd.h | 
| =================================================================== | 
| --- ui/base/win/singleton_hwnd.h (revision 0) | 
| +++ ui/base/win/singleton_hwnd.h (revision 0) | 
| @@ -0,0 +1,51 @@ | 
| +// Copyright (c) 2012 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_BASE_WIN_SINGLETON_HWND_H_ | 
| +#define UI_BASE_WIN_SINGLETON_HWND_H_ | 
| +#pragma once | 
| + | 
| +#include <windows.h> | 
| +#include <vector> | 
| + | 
| +#include "base/basictypes.h" | 
| +#include "base/callback_forward.h" | 
| + | 
| +template<typename T> struct DefaultSingletonTraits; | 
| + | 
| +namespace ui { | 
| + | 
| +typedef base::Callback<void(HWND, UINT, WPARAM, LPARAM)> WndProcCallback; | 
| + | 
| +// Singleton message-only HWND that allows interested clients to receive WM_* | 
| +// notifications. | 
| 
 
msw
2012/02/15 00:33:16
Note that not all WM_* messages are supported; poi
 
asvitkine_google
2012/02/15 15:10:44
Done.
 
 | 
| +class SingletonHwnd { | 
| 
 
msw
2012/02/15 00:33:16
Why not use/extend existing code like MessagePumpO
 
asvitkine_google
2012/02/15 15:10:44
I'm not familiar with that class... from a quick g
 
msw
2012/02/15 19:23:28
You're creating an HWND to listen for arbitrary WM
 
 | 
| + public: | 
| + // Singleton getter. | 
| 
 
msw
2012/02/15 00:33:16
nit: remove obvious comment.
 
asvitkine_google
2012/02/15 15:10:44
Done.
 
 | 
| + static SingletonHwnd* GetInstance(); | 
| + | 
| + // Registers a listener callback for WM_* notifications. | 
| 
 
msw
2012/02/15 00:33:16
Did you consider using [Add|Remove]Observer termin
 
asvitkine_google
2012/02/15 15:10:44
You're right - I think base/observer_list.h is the
 
 | 
| + void RegisterListener(const WndProcCallback& callback); | 
| 
 
msw
2012/02/15 00:33:16
Is there no way to UnregisterListener?
 
asvitkine_google
2012/02/15 15:10:44
Added.
 
 | 
| + | 
| + // Windows callback for WM_* notifications. | 
| + void OnWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); | 
| + | 
| + private: | 
| + friend struct DefaultSingletonTraits<SingletonHwnd>; | 
| + | 
| + SingletonHwnd(); | 
| + ~SingletonHwnd(); | 
| + | 
| + // Listener HWND for WM_* notifications. | 
| + HWND listener_window_; | 
| + | 
| + // List of registered listener callbacks. | 
| + std::vector<WndProcCallback> listeners_; | 
| + | 
| + DISALLOW_COPY_AND_ASSIGN(SingletonHwnd); | 
| +}; | 
| + | 
| +} // namespace ui | 
| + | 
| +#endif // UI_BASE_WIN_SINGLETON_HWND_H_ |