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

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

Powered by Google App Engine
This is Rietveld 408576698