Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(611)

Side by Side Diff: chrome/browser/hang_monitor/hung_window_detector.cc

Issue 10272007: Generate crash dumps when a hung PPAPI plugin is force terminated. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
7 6
8 #include <windows.h> 7 #include <windows.h>
9 #include <atlbase.h> 8 #include <atlbase.h>
10 9
11 #include "base/logging.h" 10 #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
14 // How long do we wait for the terminated thread or process to die (in ms) 16 // How long do we wait for the terminated thread or process to die (in ms)
15 static const int kTerminateTimeout = 2000; 17 static const int kTerminateTimeout = 2000;
16 // How long do we wait for the crash to be generated (in ms). 18
17 static const int kGenerateDumpTimeout = 10000; 19 } // namespace
18 20
19 const wchar_t HungWindowDetector::kHungChildWindowTimeout[] = 21 const wchar_t HungWindowDetector::kHungChildWindowTimeout[] =
20 L"Chrome_HungChildWindowTimeout"; 22 L"Chrome_HungChildWindowTimeout";
21 23
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
41 HungWindowDetector::HungWindowDetector(HungWindowNotification* notification) 24 HungWindowDetector::HungWindowDetector(HungWindowNotification* notification)
42 : notification_(notification), 25 : notification_(notification),
43 top_level_window_(NULL), 26 top_level_window_(NULL),
44 message_response_timeout_(0), 27 message_response_timeout_(0),
45 enumerating_(false) { 28 enumerating_(false) {
46 DCHECK(NULL != notification_); 29 DCHECK(NULL != notification_);
47 } 30 }
48 // NOTE: It is the caller's responsibility to make sure that 31 // NOTE: It is the caller's responsibility to make sure that
49 // callbacks on this object have been stopped before 32 // callbacks on this object have been stopped before
50 // destroying this object 33 // destroying this object
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 if (NULL == child_process.m_h) { 154 if (NULL == child_process.m_h) {
172 break; 155 break;
173 } 156 }
174 // Before swinging the axe, do some sanity checks to make 157 // Before swinging the axe, do some sanity checks to make
175 // sure this window still belongs to the same process 158 // sure this window still belongs to the same process
176 DWORD process_id_check = 0; 159 DWORD process_id_check = 0;
177 GetWindowThreadProcessId(child_window, &process_id_check); 160 GetWindowThreadProcessId(child_window, &process_id_check);
178 if (process_id_check != child_window_process_id) { 161 if (process_id_check != child_window_process_id) {
179 break; 162 break;
180 } 163 }
164
181 // Before terminating the process we try collecting a dump. Which 165 // Before terminating the process we try collecting a dump. Which
182 // a transient thread in the child process will do for us. 166 // a transient thread in the child process will do for us.
183 HANDLE remote_thread = 167 CrashDumpAndTerminateHungChildProcess(child_process);
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);
198 child_process.Close(); 168 child_process.Close();
199 break; 169 break;
200 } 170 }
201 default: { 171 default: {
202 break; 172 break;
203 } 173 }
204 } 174 }
205 } else { 175 } else {
206 RemoveProp(child_window, kHungChildWindowTimeout); 176 RemoveProp(child_window, kHungChildWindowTimeout);
207 } 177 }
208 } 178 }
209 179
210 return continue_hang_detection; 180 return continue_hang_detection;
211 } 181 }
212 182
213 BOOL CALLBACK HungWindowDetector::ChildWndEnumProc(HWND child_window, 183 BOOL CALLBACK HungWindowDetector::ChildWndEnumProc(HWND child_window,
214 LPARAM param) { 184 LPARAM param) {
215 HungWindowDetector* detector_instance = 185 HungWindowDetector* detector_instance =
216 reinterpret_cast<HungWindowDetector*>(param); 186 reinterpret_cast<HungWindowDetector*>(param);
217 if (NULL == detector_instance) { 187 if (NULL == detector_instance) {
218 NOTREACHED(); 188 NOTREACHED();
219 return FALSE; 189 return FALSE;
220 } 190 }
221 191
222 return detector_instance->CheckChildWindow(child_window); 192 return detector_instance->CheckChildWindow(child_window);
223 } 193 }
OLDNEW
« no previous file with comments | « chrome/browser/hang_monitor/hang_crash_dump_win.cc ('k') | chrome/browser/ui/hung_plugin_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698