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

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

Issue 2086403002: Remove the Kasko based out of process browser hang instrumentation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge Created 4 years, 5 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 <windows.h>
8 #include <shellapi.h> 8 #include <shellapi.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
11 #include "base/base_paths.h" 11 #include "base/base_paths.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/path_service.h"
17 #include "base/process/process.h" 16 #include "base/process/process.h"
18 #include "base/process/process_info.h" 17 #include "base/process/process_info.h"
19 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
21 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
22 #include "base/time/time.h" 21 #include "base/time/time.h"
23 #include "base/win/registry.h" 22 #include "base/win/registry.h"
24 #include "base/win/scoped_handle.h" 23 #include "base/win/scoped_handle.h"
25 #include "base/win/windows_version.h" 24 #include "base/win/windows_version.h"
26 #include "chrome/browser/browser_process.h" 25 #include "chrome/browser/browser_process.h"
27 #include "chrome/browser/browser_process_platform_part.h" 26 #include "chrome/browser/browser_process_platform_part.h"
28 #include "chrome/browser/chrome_process_finder_win.h" 27 #include "chrome/browser/chrome_process_finder_win.h"
29 #include "chrome/browser/shell_integration.h" 28 #include "chrome/browser/shell_integration.h"
30 #include "chrome/browser/ui/simple_message_box.h" 29 #include "chrome/browser/ui/simple_message_box.h"
31 #include "chrome/common/channel_info.h"
32 #include "chrome/common/chrome_constants.h" 30 #include "chrome/common/chrome_constants.h"
33 #include "chrome/common/chrome_paths.h" 31 #include "chrome/common/chrome_paths.h"
34 #include "chrome/common/chrome_paths_internal.h" 32 #include "chrome/common/chrome_paths_internal.h"
35 #include "chrome/common/chrome_switches.h" 33 #include "chrome/common/chrome_switches.h"
36 #include "chrome/grit/chromium_strings.h" 34 #include "chrome/grit/chromium_strings.h"
37 #include "chrome/installer/util/google_update_settings.h"
38 #include "chrome/installer/util/util_constants.h"
39 #include "chrome/installer/util/wmi.h" 35 #include "chrome/installer/util/wmi.h"
40 #include "components/version_info/version_info.h"
41 #include "content/public/common/result_codes.h" 36 #include "content/public/common/result_codes.h"
42 #include "net/base/escape.h" 37 #include "net/base/escape.h"
43 #include "third_party/kasko/kasko_features.h"
44 #include "ui/base/l10n/l10n_util.h" 38 #include "ui/base/l10n/l10n_util.h"
45 #include "ui/gfx/win/hwnd_util.h" 39 #include "ui/gfx/win/hwnd_util.h"
46 40
47 #if BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS)
48 #include "chrome/app/chrome_crash_reporter_client_win.h"
49 #include "chrome/chrome_watcher/kasko_util.h"
50 #endif // BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS)
51
52 namespace { 41 namespace {
53 42
54 const char kLockfile[] = "lockfile"; 43 const char kLockfile[] = "lockfile";
55 44
56 // A helper class that acquires the given |mutex| while the AutoLockMutex is in 45 // A helper class that acquires the given |mutex| while the AutoLockMutex is in
57 // scope. 46 // scope.
58 class AutoLockMutex { 47 class AutoLockMutex {
59 public: 48 public:
60 explicit AutoLockMutex(HANDLE mutex) : mutex_(mutex) { 49 explicit AutoLockMutex(HANDLE mutex) : mutex_(mutex) {
61 DWORD result = ::WaitForSingleObject(mutex_, INFINITE); 50 DWORD result = ::WaitForSingleObject(mutex_, INFINITE);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 return true; 173 return true;
185 } 174 }
186 175
187 bool DisplayShouldKillMessageBox() { 176 bool DisplayShouldKillMessageBox() {
188 return chrome::ShowQuestionMessageBox( 177 return chrome::ShowQuestionMessageBox(
189 NULL, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), 178 NULL, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
190 l10n_util::GetStringUTF16(IDS_BROWSER_HUNGBROWSER_MESSAGE)) != 179 l10n_util::GetStringUTF16(IDS_BROWSER_HUNGBROWSER_MESSAGE)) !=
191 chrome::MESSAGE_BOX_RESULT_NO; 180 chrome::MESSAGE_BOX_RESULT_NO;
192 } 181 }
193 182
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.
227 if (chrome::GetChannel() != 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
255 } // namespace 183 } // namespace
256 184
257 // Microsoft's Softricity virtualization breaks the sandbox processes. 185 // Microsoft's Softricity virtualization breaks the sandbox processes.
258 // So, if we detect the Softricity DLL we use WMI Win32_Process.Create to 186 // So, if we detect the Softricity DLL we use WMI Win32_Process.Create to
259 // break out of the virtualization environment. 187 // break out of the virtualization environment.
260 // http://code.google.com/p/chromium/issues/detail?id=43650 188 // http://code.google.com/p/chromium/issues/detail?id=43650
261 bool ProcessSingleton::EscapeVirtualization( 189 bool ProcessSingleton::EscapeVirtualization(
262 const base::FilePath& user_data_dir) { 190 const base::FilePath& user_data_dir) {
263 if (::GetModuleHandle(L"sftldr_wow64.dll") || 191 if (::GetModuleHandle(L"sftldr_wow64.dll") ||
264 ::GetModuleHandle(L"sftldr.dll")) { 192 ::GetModuleHandle(L"sftldr.dll")) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 DWORD process_id = 0; 254 DWORD process_id = 0;
327 DWORD thread_id = ::GetWindowThreadProcessId(remote_window_, &process_id); 255 DWORD thread_id = ::GetWindowThreadProcessId(remote_window_, &process_id);
328 if (!thread_id || !process_id) { 256 if (!thread_id || !process_id) {
329 remote_window_ = NULL; 257 remote_window_ = NULL;
330 return PROCESS_NONE; 258 return PROCESS_NONE;
331 } 259 }
332 260
333 // Get a handle to the process that created the window. 261 // Get a handle to the process that created the window.
334 base::Process process = base::Process::Open(process_id); 262 base::Process process = base::Process::Open(process_id);
335 263
336 // Optionally send a failed rendez-vous report. 264 // TODO(manzagop): capture a hang report.
337 // Note: we nominate the thread that created the window as the root of the
338 // search for a hung thread.
339 #if defined(GOOGLE_CHROME_BUILD)
340 #if BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS)
341 SendFailedRdvReport(process, thread_id);
342 #endif // BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS)
343 #endif // GOOGLE_CHROME_BUILD
344 265
345 // Scan for every window to find a visible one. 266 // Scan for every window to find a visible one.
346 bool visible_window = false; 267 bool visible_window = false;
347 ::EnumThreadWindows(thread_id, 268 ::EnumThreadWindows(thread_id,
348 &BrowserWindowEnumeration, 269 &BrowserWindowEnumeration,
349 reinterpret_cast<LPARAM>(&visible_window)); 270 reinterpret_cast<LPARAM>(&visible_window));
350 271
351 // If there is a visible browser window, ask the user before killing it. 272 // If there is a visible browser window, ask the user before killing it.
352 if (visible_window && !should_kill_remote_process_callback_.Run()) { 273 if (visible_window && !should_kill_remote_process_callback_.Run()) {
353 // The user denied. Quit silently. 274 // The user denied. Quit silently.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 return window_.hwnd() != NULL; 354 return window_.hwnd() != NULL;
434 } 355 }
435 356
436 void ProcessSingleton::Cleanup() { 357 void ProcessSingleton::Cleanup() {
437 } 358 }
438 359
439 void ProcessSingleton::OverrideShouldKillRemoteProcessCallbackForTesting( 360 void ProcessSingleton::OverrideShouldKillRemoteProcessCallbackForTesting(
440 const ShouldKillRemoteProcessCallback& display_dialog_callback) { 361 const ShouldKillRemoteProcessCallback& display_dialog_callback) {
441 should_kill_remote_process_callback_ = display_dialog_callback; 362 should_kill_remote_process_callback_ = display_dialog_callback;
442 } 363 }
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