OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/gfx/win/singleton_hwnd_observer.h" | |
6 | |
7 #include "ui/gfx/win/singleton_hwnd.h" | |
8 | |
9 namespace gfx { | |
10 | |
11 SingletonHwndObserver::SingletonHwndObserver(const WndProc& wnd_proc) : | |
12 wnd_proc_(wnd_proc) { | |
13 DCHECK(!wnd_proc.is_null()); | |
14 SingletonHwnd::GetInstance()->AddObserver(this); | |
15 } | |
16 | |
17 SingletonHwndObserver::~SingletonHwndObserver() { | |
18 ClearWndProc(); | |
19 } | |
20 | |
21 void SingletonHwndObserver::ClearWndProc() { | |
22 if (!wnd_proc_.is_null()) | |
23 SingletonHwnd::GetInstance()->RemoveObserver(this); | |
24 | |
25 wnd_proc_.Reset(); | |
26 } | |
27 | |
28 void SingletonHwndObserver::OnWndProc(HWND hwnd, | |
29 UINT message, | |
30 WPARAM wparam, | |
31 LPARAM lparam) { | |
32 wnd_proc_.Run(hwnd, message, wparam, lparam); | |
33 | |
34 if (message == WM_NCDESTROY) | |
35 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
| |
36 } | |
37 | |
38 } // namespace gfx | |
OLD | NEW |