Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Provides a way to handle exceptions that happen while a WindowProc is | 5 // Provides a way to handle exceptions that happen while a WindowProc is |
| 6 // running. The behavior of exceptions generated inside a WindowProc is OS | 6 // running. The behavior of exceptions generated inside a WindowProc is OS |
| 7 // dependent, but it is possible that the OS just ignores the exception and | 7 // dependent, but it is possible that the OS just ignores the exception and |
| 8 // continues execution, which leads to unpredictable behavior for Chrome. | 8 // continues execution, which leads to unpredictable behavior for Chrome. |
| 9 | 9 |
| 10 #ifndef BASE_WIN_WRAPPED_WINDOW_PROC_H_ | 10 #ifndef BASE_WIN_WRAPPED_WINDOW_PROC_H_ |
| 11 #define BASE_WIN_WRAPPED_WINDOW_PROC_H_ | 11 #define BASE_WIN_WRAPPED_WINDOW_PROC_H_ |
| 12 | 12 |
| 13 #include <windows.h> | 13 #include <windows.h> |
| 14 | 14 |
| 15 #include "base/base_export.h" | 15 #include "base/base_export.h" |
| 16 #include "base/profiler/scoped_profile.h" | |
| 16 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 17 | 18 |
| 18 namespace base { | 19 namespace base { |
| 19 namespace win { | 20 namespace win { |
| 20 | 21 |
| 21 // An exception filter for a WindowProc. The return value determines how the | 22 // An exception filter for a WindowProc. The return value determines how the |
| 22 // exception should be handled, following standard SEH rules. However, the | 23 // exception should be handled, following standard SEH rules. However, the |
| 23 // expected behavior for this function is to not return, instead of returning | 24 // expected behavior for this function is to not return, instead of returning |
| 24 // EXCEPTION_EXECUTE_HANDLER or similar, given that in general we are not | 25 // EXCEPTION_EXECUTE_HANDLER or similar, given that in general we are not |
| 25 // prepared to handle exceptions. | 26 // prepared to handle exceptions. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 // | 63 // |
| 63 // WNDCLASSEX wc = {0}; | 64 // WNDCLASSEX wc = {0}; |
| 64 // wc.lpfnWndProc = WrappedWindowProc<MyWinProc>; | 65 // wc.lpfnWndProc = WrappedWindowProc<MyWinProc>; |
| 65 // wc.lpszClassName = class_name; | 66 // wc.lpszClassName = class_name; |
| 66 // ... | 67 // ... |
| 67 // RegisterClassEx(&wc); | 68 // RegisterClassEx(&wc); |
| 68 // | 69 // |
| 69 // CreateWindowW(class_name, window_name, ... | 70 // CreateWindowW(class_name, window_name, ... |
| 70 // | 71 // |
| 71 template <WNDPROC proc> | 72 template <WNDPROC proc> |
| 72 LRESULT CALLBACK WrappedWindowProc(HWND hwnd, UINT message, | 73 LRESULT CALLBACK ProfiledWrappedWindowProc(HWND hwnd, |
| 73 WPARAM wparam, LPARAM lparam) { | 74 UINT message, |
| 75 WPARAM wparam, | |
| 76 LPARAM lparam) { | |
| 77 // The template parameter <proc> identifies the wrapped function. | |
| 78 tracked_objects::ScopedProfile scoped_profile( | |
|
grt (UTC plus 2)
2017/05/16 07:27:35
are you doing this in its own function template be
Sigurður Ásgeirsson
2017/05/16 13:16:58
This was pure habit - seems the ScopedProfile work
| |
| 79 FROM_HERE, tracked_objects::ScopedProfile::ENABLED); | |
| 80 | |
| 81 return proc(hwnd, message, wparam, lparam); | |
| 82 } | |
| 83 | |
| 84 template <WNDPROC proc> | |
| 85 LRESULT CALLBACK | |
| 86 WrappedWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { | |
| 74 LRESULT rv = 0; | 87 LRESULT rv = 0; |
| 75 __try { | 88 __try { |
| 76 rv = proc(hwnd, message, wparam, lparam); | 89 rv = ProfiledWrappedWindowProc<proc>(hwnd, message, wparam, lparam); |
| 77 } __except(CallExceptionFilter(GetExceptionInformation())) { | 90 } __except(CallExceptionFilter(GetExceptionInformation())) { |
| 78 } | 91 } |
| 79 return rv; | 92 return rv; |
| 80 } | 93 } |
| 81 | 94 |
| 82 } // namespace win | 95 } // namespace win |
| 83 } // namespace base | 96 } // namespace base |
| 84 | 97 |
| 85 #endif // BASE_WIN_WRAPPED_WINDOW_PROC_H_ | 98 #endif // BASE_WIN_WRAPPED_WINDOW_PROC_H_ |
| OLD | NEW |