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 #include "chrome/browser/hang_monitor/hung_window_detector.h" | 5 #include "chrome/browser/hang_monitor/hung_window_detector.h" |
| 6 #include "chrome/common/chrome_constants.h" |
6 | 7 |
7 #include <windows.h> | 8 #include <windows.h> |
8 #include <atlbase.h> | 9 #include <atlbase.h> |
9 | 10 |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "chrome/browser/hang_monitor/hang_crash_dump_win.h" | |
12 #include "content/public/common/result_codes.h" | 12 #include "content/public/common/result_codes.h" |
13 | 13 |
14 namespace { | |
15 | |
16 // How long do we wait for the terminated thread or process to die (in ms) | 14 // How long do we wait for the terminated thread or process to die (in ms) |
17 static const int kTerminateTimeout = 2000; | 15 static const int kTerminateTimeout = 2000; |
18 | 16 // How long do we wait for the crash to be generated (in ms). |
19 } // namespace | 17 static const int kGenerateDumpTimeout = 10000; |
20 | 18 |
21 const wchar_t HungWindowDetector::kHungChildWindowTimeout[] = | 19 const wchar_t HungWindowDetector::kHungChildWindowTimeout[] = |
22 L"Chrome_HungChildWindowTimeout"; | 20 L"Chrome_HungChildWindowTimeout"; |
23 | 21 |
| 22 namespace { |
| 23 |
| 24 typedef void (*DumpProcessWithoutCrashFn)(); |
| 25 // This function will be called via an injected thread in the hung plugin |
| 26 // process. calling DumpProcessWithoutCrash causes breakpad to capture a dump of |
| 27 // the process. |
| 28 DWORD WINAPI HungPluginDumpAndExit(void*) { |
| 29 typedef void (__cdecl *DumpProcessFunction)(); |
| 30 DumpProcessFunction request_dump = reinterpret_cast<DumpProcessFunction>( |
| 31 ::GetProcAddress(::GetModuleHandle( |
| 32 chrome::kBrowserProcessExecutableName), |
| 33 "DumpProcessWithoutCrash")); |
| 34 if (request_dump) |
| 35 request_dump(); |
| 36 return 0; |
| 37 } |
| 38 |
| 39 } // namespace |
| 40 |
24 HungWindowDetector::HungWindowDetector(HungWindowNotification* notification) | 41 HungWindowDetector::HungWindowDetector(HungWindowNotification* notification) |
25 : notification_(notification), | 42 : notification_(notification), |
26 top_level_window_(NULL), | 43 top_level_window_(NULL), |
27 message_response_timeout_(0), | 44 message_response_timeout_(0), |
28 enumerating_(false) { | 45 enumerating_(false) { |
29 DCHECK(NULL != notification_); | 46 DCHECK(NULL != notification_); |
30 } | 47 } |
31 // NOTE: It is the caller's responsibility to make sure that | 48 // NOTE: It is the caller's responsibility to make sure that |
32 // callbacks on this object have been stopped before | 49 // callbacks on this object have been stopped before |
33 // destroying this object | 50 // destroying this object |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 if (NULL == child_process.m_h) { | 171 if (NULL == child_process.m_h) { |
155 break; | 172 break; |
156 } | 173 } |
157 // Before swinging the axe, do some sanity checks to make | 174 // Before swinging the axe, do some sanity checks to make |
158 // sure this window still belongs to the same process | 175 // sure this window still belongs to the same process |
159 DWORD process_id_check = 0; | 176 DWORD process_id_check = 0; |
160 GetWindowThreadProcessId(child_window, &process_id_check); | 177 GetWindowThreadProcessId(child_window, &process_id_check); |
161 if (process_id_check != child_window_process_id) { | 178 if (process_id_check != child_window_process_id) { |
162 break; | 179 break; |
163 } | 180 } |
164 | |
165 // Before terminating the process we try collecting a dump. Which | 181 // Before terminating the process we try collecting a dump. Which |
166 // a transient thread in the child process will do for us. | 182 // a transient thread in the child process will do for us. |
167 CrashDumpAndTerminateHungChildProcess(child_process); | 183 HANDLE remote_thread = |
| 184 CreateRemoteThread(child_process, |
| 185 NULL, |
| 186 0, |
| 187 &HungPluginDumpAndExit, |
| 188 0, |
| 189 0, |
| 190 NULL); |
| 191 if (remote_thread) { |
| 192 WaitForSingleObject(remote_thread, kGenerateDumpTimeout); |
| 193 CloseHandle(remote_thread); |
| 194 } |
| 195 |
| 196 TerminateProcess(child_process, content::RESULT_CODE_HUNG); |
| 197 WaitForSingleObject(child_process, kTerminateTimeout); |
168 child_process.Close(); | 198 child_process.Close(); |
169 break; | 199 break; |
170 } | 200 } |
171 default: { | 201 default: { |
172 break; | 202 break; |
173 } | 203 } |
174 } | 204 } |
175 } else { | 205 } else { |
176 RemoveProp(child_window, kHungChildWindowTimeout); | 206 RemoveProp(child_window, kHungChildWindowTimeout); |
177 } | 207 } |
178 } | 208 } |
179 | 209 |
180 return continue_hang_detection; | 210 return continue_hang_detection; |
181 } | 211 } |
182 | 212 |
183 BOOL CALLBACK HungWindowDetector::ChildWndEnumProc(HWND child_window, | 213 BOOL CALLBACK HungWindowDetector::ChildWndEnumProc(HWND child_window, |
184 LPARAM param) { | 214 LPARAM param) { |
185 HungWindowDetector* detector_instance = | 215 HungWindowDetector* detector_instance = |
186 reinterpret_cast<HungWindowDetector*>(param); | 216 reinterpret_cast<HungWindowDetector*>(param); |
187 if (NULL == detector_instance) { | 217 if (NULL == detector_instance) { |
188 NOTREACHED(); | 218 NOTREACHED(); |
189 return FALSE; | 219 return FALSE; |
190 } | 220 } |
191 | 221 |
192 return detector_instance->CheckChildWindow(child_window); | 222 return detector_instance->CheckChildWindow(child_window); |
193 } | 223 } |
OLD | NEW |