Chromium Code Reviews| 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..6fb70b1c2e2bb231766f1a583b27216670df267c |
| --- /dev/null |
| +++ b/ui/gfx/win/singleton_hwnd_observer.cc |
| @@ -0,0 +1,38 @@ |
| +// 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); |
| + |
| + if (message == WM_NCDESTROY) |
| + ClearWndProc(); |
|
sky
2015/04/28 23:35:04
Having any code after Run is dangerous as the call
robliao
2015/04/29 00:25:43
The original implementation was resilient against
|
| +} |
| + |
| +} // namespace gfx |