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

Side by Side Diff: chrome/browser/process_singleton_win.cc

Issue 1844023002: Capture a report on failed browser rendez-vous. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: GYP fixup Created 4 years, 8 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
« no previous file with comments | « chrome/browser/BUILD.gn ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/process_singleton.h" 5 #include "chrome/browser/process_singleton.h"
6 6
7 #include <windows.h>
7 #include <shellapi.h> 8 #include <shellapi.h>
8 #include <stddef.h> 9 #include <stddef.h>
9 10
10 #include "base/base_paths.h" 11 #include "base/base_paths.h"
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/command_line.h" 13 #include "base/command_line.h"
13 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/path_service.h"
15 #include "base/process/process.h" 17 #include "base/process/process.h"
16 #include "base/process/process_info.h" 18 #include "base/process/process_info.h"
17 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
19 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
20 #include "base/time/time.h" 22 #include "base/time/time.h"
21 #include "base/win/registry.h" 23 #include "base/win/registry.h"
22 #include "base/win/scoped_handle.h" 24 #include "base/win/scoped_handle.h"
23 #include "base/win/windows_version.h" 25 #include "base/win/windows_version.h"
24 #include "chrome/browser/browser_process.h" 26 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/browser_process_platform_part.h" 27 #include "chrome/browser/browser_process_platform_part.h"
26 #include "chrome/browser/chrome_process_finder_win.h" 28 #include "chrome/browser/chrome_process_finder_win.h"
27 #include "chrome/browser/shell_integration.h" 29 #include "chrome/browser/shell_integration.h"
28 #include "chrome/browser/ui/simple_message_box.h" 30 #include "chrome/browser/ui/simple_message_box.h"
31 #include "chrome/common/channel_info.h"
29 #include "chrome/common/chrome_constants.h" 32 #include "chrome/common/chrome_constants.h"
30 #include "chrome/common/chrome_paths.h" 33 #include "chrome/common/chrome_paths.h"
31 #include "chrome/common/chrome_paths_internal.h" 34 #include "chrome/common/chrome_paths_internal.h"
32 #include "chrome/common/chrome_switches.h" 35 #include "chrome/common/chrome_switches.h"
33 #include "chrome/grit/chromium_strings.h" 36 #include "chrome/grit/chromium_strings.h"
37 #include "chrome/installer/util/google_update_settings.h"
38 #include "chrome/installer/util/util_constants.h"
34 #include "chrome/installer/util/wmi.h" 39 #include "chrome/installer/util/wmi.h"
40 #include "components/version_info/version_info.h"
35 #include "content/public/common/result_codes.h" 41 #include "content/public/common/result_codes.h"
36 #include "net/base/escape.h" 42 #include "net/base/escape.h"
43 #include "third_party/kasko/kasko_features.h"
37 #include "ui/base/l10n/l10n_util.h" 44 #include "ui/base/l10n/l10n_util.h"
38 #include "ui/gfx/win/hwnd_util.h" 45 #include "ui/gfx/win/hwnd_util.h"
39 46
47 #if BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS)
48 #include "chrome/app/chrome_crash_reporter_client.h"
49 #include "chrome/chrome_watcher/kasko_util.h"
50 #endif // BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS)
51
40 namespace { 52 namespace {
41 53
42 const char kLockfile[] = "lockfile"; 54 const char kLockfile[] = "lockfile";
43 55
44 // A helper class that acquires the given |mutex| while the AutoLockMutex is in 56 // A helper class that acquires the given |mutex| while the AutoLockMutex is in
45 // scope. 57 // scope.
46 class AutoLockMutex { 58 class AutoLockMutex {
47 public: 59 public:
48 explicit AutoLockMutex(HANDLE mutex) : mutex_(mutex) { 60 explicit AutoLockMutex(HANDLE mutex) : mutex_(mutex) {
49 DWORD result = ::WaitForSingleObject(mutex_, INFINITE); 61 DWORD result = ::WaitForSingleObject(mutex_, INFINITE);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 return true; 184 return true;
173 } 185 }
174 186
175 bool DisplayShouldKillMessageBox() { 187 bool DisplayShouldKillMessageBox() {
176 return chrome::ShowQuestionMessageBox( 188 return chrome::ShowQuestionMessageBox(
177 NULL, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), 189 NULL, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
178 l10n_util::GetStringUTF16(IDS_BROWSER_HUNGBROWSER_MESSAGE)) != 190 l10n_util::GetStringUTF16(IDS_BROWSER_HUNGBROWSER_MESSAGE)) !=
179 chrome::MESSAGE_BOX_RESULT_NO; 191 chrome::MESSAGE_BOX_RESULT_NO;
180 } 192 }
181 193
194 #if BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS)
195 // Capture a failed rendez-vous hang report of the other process. Kasko needs
196 // the exception context to live either in the dumper or the dumpee. This
197 // means we cannot rely on kasko reporters from either browser watcher, and
198 // instead spin up a new reporter.
199 void SendFailedRdvReport(const base::Process& process, DWORD thread_id) {
200 // Check whether reports can be uploaded. This involves checking group policy,
201 // stats collection consent and whether running on a bot. The correct approach
202 // would be to rely on crash_reporter::GetUploadsEnabled(). However, on
203 // Windows, the crash client is only expected to be linked into chrome.exe
204 // (not the dlls). That means CrashPad globals are not set and we cannot call
205 // crash_reporter::GetUploadsEnabled(). As a temporary measure until Kasko is
206 // no longer used, we duplicate CrashPad's logic here.
207 ChromeCrashReporterClient crash_reporter_client;
208
209 bool enable_uploads = false;
210 if (!crash_reporter_client.ReportingIsEnforcedByPolicy(&enable_uploads)) {
211 // Breakpad provided a --disable-breakpad switch to disable crash dumping
212 // (not just uploading) here. Crashpad doesn't need it: dumping is enabled
213 // unconditionally and uploading is gated on consent, which tests/bots
214 // shouldn't have. As a precaution, uploading is also disabled on bots
215 // even if consent is present.
216 enable_uploads = crash_reporter_client.GetCollectStatsConsent() &&
217 !crash_reporter_client.IsRunningUnattended();
218 }
219
220 if (!enable_uploads)
221 return;
222
223 // TODO(manzagop): add a metric for the number of captured hang reports, for
224 // comparison with uploaded count?
225
226 // Only report on canary (or unspecified).
227 const version_info::Channel channel = chrome::GetChannel();
228 if (channel != version_info::Channel::UNKNOWN &&
229 channel != version_info::Channel::CANARY) {
230 return;
231 }
232 // TODO(manzagop): add a metric for the number of times this does not match.
233 if (!EnsureTargetProcessValidForCapture(process))
234 return;
235
236 // Initialize a reporter, capture a report and shutdown the reporter.
237 base::FilePath watcher_data_directory;
238 if (PathService::Get(chrome::DIR_WATCHER_DATA, &watcher_data_directory)) {
239 base::string16 endpoint =
240 L"chrome_kasko_rdv_" +
241 base::UintToString16(base::Process::Current().Pid());
242
243 bool launched_kasko = InitializeKaskoReporter(
244 endpoint, watcher_data_directory.value().c_str());
245 if (launched_kasko) {
246 DumpHungProcess(thread_id, installer::kChromeChannelCanary, L"failed-rdv",
247 process);
248 // We immediately request Kasko shutdown. This may block until the
249 // completion of ongoing background tasks (e.g., upload). If the report is
250 // not uploaded by this reporter, any other Kasko reporter may upload it.
251 ShutdownKaskoReporter();
252 }
253 }
254 }
255 #endif // BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS)
256
182 } // namespace 257 } // namespace
183 258
184 // Microsoft's Softricity virtualization breaks the sandbox processes. 259 // Microsoft's Softricity virtualization breaks the sandbox processes.
185 // So, if we detect the Softricity DLL we use WMI Win32_Process.Create to 260 // So, if we detect the Softricity DLL we use WMI Win32_Process.Create to
186 // break out of the virtualization environment. 261 // break out of the virtualization environment.
187 // http://code.google.com/p/chromium/issues/detail?id=43650 262 // http://code.google.com/p/chromium/issues/detail?id=43650
188 bool ProcessSingleton::EscapeVirtualization( 263 bool ProcessSingleton::EscapeVirtualization(
189 const base::FilePath& user_data_dir) { 264 const base::FilePath& user_data_dir) {
190 if (::GetModuleHandle(L"sftldr_wow64.dll") || 265 if (::GetModuleHandle(L"sftldr_wow64.dll") ||
191 ::GetModuleHandle(L"sftldr.dll")) { 266 ::GetModuleHandle(L"sftldr.dll")) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 case chrome::NOTIFY_SUCCESS: 317 case chrome::NOTIFY_SUCCESS:
243 return PROCESS_NOTIFIED; 318 return PROCESS_NOTIFIED;
244 case chrome::NOTIFY_FAILED: 319 case chrome::NOTIFY_FAILED:
245 remote_window_ = NULL; 320 remote_window_ = NULL;
246 return PROCESS_NONE; 321 return PROCESS_NONE;
247 case chrome::NOTIFY_WINDOW_HUNG: 322 case chrome::NOTIFY_WINDOW_HUNG:
248 // Fall through and potentially terminate the hung browser. 323 // Fall through and potentially terminate the hung browser.
249 break; 324 break;
250 } 325 }
251 326
327 // The window is hung.
252 DWORD process_id = 0; 328 DWORD process_id = 0;
253 DWORD thread_id = ::GetWindowThreadProcessId(remote_window_, &process_id); 329 DWORD thread_id = ::GetWindowThreadProcessId(remote_window_, &process_id);
254 if (!thread_id || !process_id) { 330 if (!thread_id || !process_id) {
255 remote_window_ = NULL; 331 remote_window_ = NULL;
256 return PROCESS_NONE; 332 return PROCESS_NONE;
257 } 333 }
334
335 // Get a handle to the process that created the window.
258 base::Process process = base::Process::Open(process_id); 336 base::Process process = base::Process::Open(process_id);
259 337
260 // The window is hung. Scan for every window to find a visible one. 338 // Optionally send a failed rendez-vous report.
339 // Note: we nominate the thread that created the window as the root of the
340 // search for a hung thread.
341 #if defined(GOOGLE_CHROME_BUILD)
342 #if BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS)
343 SendFailedRdvReport(process, thread_id);
344 #endif // BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS)
345 #endif // GOOGLE_CHROME_BUILD
346
347 // Scan for every window to find a visible one.
261 bool visible_window = false; 348 bool visible_window = false;
262 ::EnumThreadWindows(thread_id, 349 ::EnumThreadWindows(thread_id,
263 &BrowserWindowEnumeration, 350 &BrowserWindowEnumeration,
264 reinterpret_cast<LPARAM>(&visible_window)); 351 reinterpret_cast<LPARAM>(&visible_window));
265 352
266 // If there is a visible browser window, ask the user before killing it. 353 // If there is a visible browser window, ask the user before killing it.
267 if (visible_window && !should_kill_remote_process_callback_.Run()) { 354 if (visible_window && !should_kill_remote_process_callback_.Run()) {
268 // The user denied. Quit silently. 355 // The user denied. Quit silently.
269 return PROCESS_NOTIFIED; 356 return PROCESS_NOTIFIED;
270 } 357 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 return window_.hwnd() != NULL; 435 return window_.hwnd() != NULL;
349 } 436 }
350 437
351 void ProcessSingleton::Cleanup() { 438 void ProcessSingleton::Cleanup() {
352 } 439 }
353 440
354 void ProcessSingleton::OverrideShouldKillRemoteProcessCallbackForTesting( 441 void ProcessSingleton::OverrideShouldKillRemoteProcessCallbackForTesting(
355 const ShouldKillRemoteProcessCallback& display_dialog_callback) { 442 const ShouldKillRemoteProcessCallback& display_dialog_callback) {
356 should_kill_remote_process_callback_ = display_dialog_callback; 443 should_kill_remote_process_callback_ = display_dialog_callback;
357 } 444 }
OLDNEW
« no previous file with comments | « chrome/browser/BUILD.gn ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698