Chromium Code Reviews| 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/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/crash/content/app/crashpad.h" | |
|
grt (UTC plus 2)
2016/04/12 14:35:22
unused?
manzagop (departed)
2016/04/12 15:45:41
Yes! Done.
| |
| 43 #include "components/version_info/version_info.h" | |
| 35 #include "content/public/common/result_codes.h" | 44 #include "content/public/common/result_codes.h" |
| 36 #include "net/base/escape.h" | 45 #include "net/base/escape.h" |
| 46 #include "third_party/kasko/kasko_features.h" | |
| 37 #include "ui/base/l10n/l10n_util.h" | 47 #include "ui/base/l10n/l10n_util.h" |
| 38 #include "ui/gfx/win/hwnd_util.h" | 48 #include "ui/gfx/win/hwnd_util.h" |
| 39 | 49 |
| 40 namespace { | 50 namespace { |
| 41 | 51 |
| 42 const char kLockfile[] = "lockfile"; | 52 const char kLockfile[] = "lockfile"; |
| 43 | 53 |
| 44 // A helper class that acquires the given |mutex| while the AutoLockMutex is in | 54 // A helper class that acquires the given |mutex| while the AutoLockMutex is in |
| 45 // scope. | 55 // scope. |
| 46 class AutoLockMutex { | 56 class AutoLockMutex { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 return true; | 182 return true; |
| 173 } | 183 } |
| 174 | 184 |
| 175 bool DisplayShouldKillMessageBox() { | 185 bool DisplayShouldKillMessageBox() { |
| 176 return chrome::ShowQuestionMessageBox( | 186 return chrome::ShowQuestionMessageBox( |
| 177 NULL, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), | 187 NULL, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), |
| 178 l10n_util::GetStringUTF16(IDS_BROWSER_HUNGBROWSER_MESSAGE)) != | 188 l10n_util::GetStringUTF16(IDS_BROWSER_HUNGBROWSER_MESSAGE)) != |
| 179 chrome::MESSAGE_BOX_RESULT_NO; | 189 chrome::MESSAGE_BOX_RESULT_NO; |
| 180 } | 190 } |
| 181 | 191 |
| 192 #if BUILDFLAG(ENABLE_KASKO) | |
| 193 #if BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS) | |
| 194 // Capture a failed rendez-vous hang report of the other process. Kasko needs | |
| 195 // the exception context to live either in the dumper or the dumpee. This | |
| 196 // means we cannot rely on kasko reporters from either browser watcher, and | |
| 197 // instead spin up a new reporter. | |
| 198 void SendFailedRdvReport(const base::Process& process, DWORD thread_id) { | |
| 199 // Check whether reports can be uploaded. This involves checking group policy, | |
| 200 // stats collection consent and whether running on a bot. The correct approach | |
| 201 // would be to rely on crash_reporter::GetUploadsEnabled(). However, on | |
| 202 // Windows, the crash client is only expected to be linked into chrome.exe | |
| 203 // (not the dlls). That means CrashPad globals are not set and we cannot call | |
| 204 // crash_reporter::GetUploadsEnabled(). As a temporary measure until Kasko is | |
| 205 // no longer used, we duplicate CrashPad's logic here. | |
| 206 ChromeCrashReporterClient crash_reporter_client; | |
| 207 | |
| 208 bool enable_uploads = false; | |
| 209 if (!crash_reporter_client.ReportingIsEnforcedByPolicy(&enable_uploads)) { | |
| 210 // Breakpad provided a --disable-breakpad switch to disable crash dumping | |
| 211 // (not just uploading) here. Crashpad doesn't need it: dumping is enabled | |
| 212 // unconditionally and uploading is gated on consent, which tests/bots | |
| 213 // shouldn't have. As a precaution, uploading is also disabled on bots | |
| 214 // even if consent is present. | |
| 215 enable_uploads = crash_reporter_client.GetCollectStatsConsent() && | |
| 216 !crash_reporter_client.IsRunningUnattended(); | |
| 217 } | |
| 218 | |
| 219 if (!enable_uploads) | |
| 220 return; | |
| 221 | |
| 222 // TODO(manzagop): add a metric for the number of captured hang reports, for | |
| 223 // comparison with uploaded count? | |
| 224 | |
| 225 // Only report on canary (or unspecified). | |
| 226 const version_info::Channel channel = chrome::GetChannel(); | |
| 227 if (channel != version_info::Channel::UNKNOWN && | |
| 228 channel != version_info::Channel::CANARY) { | |
| 229 return; | |
| 230 } | |
| 231 // TODO(manzagop): add a metric for the number of times this does not match. | |
| 232 if (!EnsureTargetProcessValidForCapture(process)) | |
| 233 return; | |
| 234 | |
| 235 // Initialize a reporter, capture a report and shutdown the reporter. | |
| 236 base::FilePath watcher_data_directory; | |
| 237 if (PathService::Get(chrome::DIR_WATCHER_DATA, &watcher_data_directory)) { | |
| 238 base::string16 endpoint = | |
| 239 L"chrome_kasko_rdv_" + | |
| 240 base::UintToString16(base::Process::Current().Pid()); | |
| 241 | |
| 242 bool launched_kasko = InitializeKaskoReporter( | |
| 243 endpoint, watcher_data_directory.value().c_str()); | |
| 244 if (launched_kasko) { | |
| 245 DumpHungProcess(thread_id, installer::kChromeChannelCanary, L"failed-rdv", | |
| 246 process); | |
| 247 // We immediately request Kasko shutdown. This may block until the | |
| 248 // completion of ongoing background tasks (e.g., upload). If the report is | |
| 249 // not uploaded by this reporter, any other Kasko reporter may upload it. | |
| 250 ShutdownKaskoReporter(); | |
| 251 } | |
| 252 } | |
| 253 } | |
| 254 #endif // BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS) | |
| 255 #endif // BUILDFLAG(ENABLE_KASKO) | |
| 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 Loading... | |
| 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) | |
| 343 #if BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS) | |
| 344 SendFailedRdvReport(process, thread_id); | |
| 345 #endif // BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS) | |
| 346 #endif // BUILDFLAG(ENABLE_KASKO) | |
| 347 #endif // GOOGLE_CHROME_BUILD | |
| 348 | |
| 349 // Scan for every window to find a visible one. | |
| 261 bool visible_window = false; | 350 bool visible_window = false; |
| 262 ::EnumThreadWindows(thread_id, | 351 ::EnumThreadWindows(thread_id, |
| 263 &BrowserWindowEnumeration, | 352 &BrowserWindowEnumeration, |
| 264 reinterpret_cast<LPARAM>(&visible_window)); | 353 reinterpret_cast<LPARAM>(&visible_window)); |
| 265 | 354 |
| 266 // If there is a visible browser window, ask the user before killing it. | 355 // If there is a visible browser window, ask the user before killing it. |
| 267 if (visible_window && !should_kill_remote_process_callback_.Run()) { | 356 if (visible_window && !should_kill_remote_process_callback_.Run()) { |
| 268 // The user denied. Quit silently. | 357 // The user denied. Quit silently. |
| 269 return PROCESS_NOTIFIED; | 358 return PROCESS_NOTIFIED; |
| 270 } | 359 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 return window_.hwnd() != NULL; | 437 return window_.hwnd() != NULL; |
| 349 } | 438 } |
| 350 | 439 |
| 351 void ProcessSingleton::Cleanup() { | 440 void ProcessSingleton::Cleanup() { |
| 352 } | 441 } |
| 353 | 442 |
| 354 void ProcessSingleton::OverrideShouldKillRemoteProcessCallbackForTesting( | 443 void ProcessSingleton::OverrideShouldKillRemoteProcessCallbackForTesting( |
| 355 const ShouldKillRemoteProcessCallback& display_dialog_callback) { | 444 const ShouldKillRemoteProcessCallback& display_dialog_callback) { |
| 356 should_kill_remote_process_callback_ = display_dialog_callback; | 445 should_kill_remote_process_callback_ = display_dialog_callback; |
| 357 } | 446 } |
| OLD | NEW |