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" |
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/chrome_watcher/kasko_util.h" |
| 32 #include "chrome/common/channel_info.h" |
29 #include "chrome/common/chrome_constants.h" | 33 #include "chrome/common/chrome_constants.h" |
30 #include "chrome/common/chrome_paths.h" | 34 #include "chrome/common/chrome_paths.h" |
31 #include "chrome/common/chrome_paths_internal.h" | 35 #include "chrome/common/chrome_paths_internal.h" |
32 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
33 #include "chrome/grit/chromium_strings.h" | 37 #include "chrome/grit/chromium_strings.h" |
| 38 #include "chrome/installer/util/google_update_settings.h" |
| 39 #include "chrome/installer/util/util_constants.h" |
34 #include "chrome/installer/util/wmi.h" | 40 #include "chrome/installer/util/wmi.h" |
| 41 #include "components/version_info/version_info.h" |
35 #include "content/public/common/result_codes.h" | 42 #include "content/public/common/result_codes.h" |
36 #include "net/base/escape.h" | 43 #include "net/base/escape.h" |
| 44 #include "third_party/kasko/kasko_features.h" |
37 #include "ui/base/l10n/l10n_util.h" | 45 #include "ui/base/l10n/l10n_util.h" |
38 #include "ui/gfx/win/hwnd_util.h" | 46 #include "ui/gfx/win/hwnd_util.h" |
39 | 47 |
40 namespace { | 48 namespace { |
41 | 49 |
42 const char kLockfile[] = "lockfile"; | 50 const char kLockfile[] = "lockfile"; |
43 | 51 |
44 // A helper class that acquires the given |mutex| while the AutoLockMutex is in | 52 // A helper class that acquires the given |mutex| while the AutoLockMutex is in |
45 // scope. | 53 // scope. |
46 class AutoLockMutex { | 54 class AutoLockMutex { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 return true; | 180 return true; |
173 } | 181 } |
174 | 182 |
175 bool DisplayShouldKillMessageBox() { | 183 bool DisplayShouldKillMessageBox() { |
176 return chrome::ShowQuestionMessageBox( | 184 return chrome::ShowQuestionMessageBox( |
177 NULL, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), | 185 NULL, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), |
178 l10n_util::GetStringUTF16(IDS_BROWSER_HUNGBROWSER_MESSAGE)) != | 186 l10n_util::GetStringUTF16(IDS_BROWSER_HUNGBROWSER_MESSAGE)) != |
179 chrome::MESSAGE_BOX_RESULT_NO; | 187 chrome::MESSAGE_BOX_RESULT_NO; |
180 } | 188 } |
181 | 189 |
| 190 #if BUILDFLAG(ENABLE_KASKO) |
| 191 #if BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS) |
| 192 // Capture a failed rendez-vous hang report of the other process. Kasko needs |
| 193 // the exception context to live either in the dumper or the dumpee. This |
| 194 // means we cannot rely on kasko reporters from either browser watcher, and |
| 195 // instead spin up a new reporter. |
| 196 void SendFailedRdvReport(const base::Process& process, DWORD thread_id) { |
| 197 // TODO(manzagop): add a metric for the number of captured hang reports, for |
| 198 // comparison with uploaded count? |
| 199 |
| 200 // Only report on canary (or unspecified). |
| 201 const version_info::Channel channel = chrome::GetChannel(); |
| 202 if (channel != version_info::Channel::UNKNOWN && |
| 203 channel != version_info::Channel::CANARY) { |
| 204 return; |
| 205 } |
| 206 // TODO(manzagop): add a metric for the number of times this does not match. |
| 207 if (!EnsureTargetProcessValidForCapture(process)) |
| 208 return; |
| 209 |
| 210 // Initialize a reporter, capture a report and shutdown the reporter. |
| 211 base::FilePath watcher_data_directory; |
| 212 if (PathService::Get(chrome::DIR_WATCHER_DATA, &watcher_data_directory)) { |
| 213 base::string16 endpoint = |
| 214 L"chrome_kasko_rdv_" + |
| 215 base::UintToString16(base::Process::Current().Pid()); |
| 216 |
| 217 bool launched_kasko = InitializeKaskoReporter( |
| 218 endpoint, watcher_data_directory.value().c_str()); |
| 219 if (launched_kasko) { |
| 220 DumpHungProcess(thread_id, installer::kChromeChannelCanary, L"failed-rdv", |
| 221 process); |
| 222 // We immediately request Kasko shutdown. This may block until the |
| 223 // completion of ongoing background tasks (e.g., upload). If the report is |
| 224 // not uploaded by this reporter, any other Kasko reporter may upload it. |
| 225 ShutdownKaskoReporter(); |
| 226 } |
| 227 } |
| 228 } |
| 229 #endif // BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS) |
| 230 #endif // BUILDFLAG(ENABLE_KASKO) |
| 231 |
182 } // namespace | 232 } // namespace |
183 | 233 |
184 // Microsoft's Softricity virtualization breaks the sandbox processes. | 234 // Microsoft's Softricity virtualization breaks the sandbox processes. |
185 // So, if we detect the Softricity DLL we use WMI Win32_Process.Create to | 235 // So, if we detect the Softricity DLL we use WMI Win32_Process.Create to |
186 // break out of the virtualization environment. | 236 // break out of the virtualization environment. |
187 // http://code.google.com/p/chromium/issues/detail?id=43650 | 237 // http://code.google.com/p/chromium/issues/detail?id=43650 |
188 bool ProcessSingleton::EscapeVirtualization( | 238 bool ProcessSingleton::EscapeVirtualization( |
189 const base::FilePath& user_data_dir) { | 239 const base::FilePath& user_data_dir) { |
190 if (::GetModuleHandle(L"sftldr_wow64.dll") || | 240 if (::GetModuleHandle(L"sftldr_wow64.dll") || |
191 ::GetModuleHandle(L"sftldr.dll")) { | 241 ::GetModuleHandle(L"sftldr.dll")) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 case chrome::NOTIFY_SUCCESS: | 292 case chrome::NOTIFY_SUCCESS: |
243 return PROCESS_NOTIFIED; | 293 return PROCESS_NOTIFIED; |
244 case chrome::NOTIFY_FAILED: | 294 case chrome::NOTIFY_FAILED: |
245 remote_window_ = NULL; | 295 remote_window_ = NULL; |
246 return PROCESS_NONE; | 296 return PROCESS_NONE; |
247 case chrome::NOTIFY_WINDOW_HUNG: | 297 case chrome::NOTIFY_WINDOW_HUNG: |
248 // Fall through and potentially terminate the hung browser. | 298 // Fall through and potentially terminate the hung browser. |
249 break; | 299 break; |
250 } | 300 } |
251 | 301 |
| 302 // The window is hung. |
252 DWORD process_id = 0; | 303 DWORD process_id = 0; |
253 DWORD thread_id = ::GetWindowThreadProcessId(remote_window_, &process_id); | 304 DWORD thread_id = ::GetWindowThreadProcessId(remote_window_, &process_id); |
254 if (!thread_id || !process_id) { | 305 if (!thread_id || !process_id) { |
255 remote_window_ = NULL; | 306 remote_window_ = NULL; |
256 return PROCESS_NONE; | 307 return PROCESS_NONE; |
257 } | 308 } |
| 309 |
| 310 // Get a handle to the process that created the window. |
258 base::Process process = base::Process::Open(process_id); | 311 base::Process process = base::Process::Open(process_id); |
259 | 312 |
260 // The window is hung. Scan for every window to find a visible one. | 313 // Optionally send a failed rendez-vous report. |
| 314 // Note: we nominate the thread that created the window as the root of the |
| 315 // search for a hung thread. |
| 316 #if defined(GOOGLE_CHROME_BUILD) |
| 317 const bool stats_collection_consent = |
| 318 GoogleUpdateSettings::GetCollectStatsConsent(); |
| 319 #if BUILDFLAG(ENABLE_KASKO) |
| 320 #if BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS) |
| 321 if (stats_collection_consent) |
| 322 SendFailedRdvReport(process, thread_id); |
| 323 #endif // BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS) |
| 324 #endif // BUILDFLAG(ENABLE_KASKO) |
| 325 #endif // GOOGLE_CHROME_BUILD |
| 326 |
| 327 // Scan for every window to find a visible one. |
261 bool visible_window = false; | 328 bool visible_window = false; |
262 ::EnumThreadWindows(thread_id, | 329 ::EnumThreadWindows(thread_id, |
263 &BrowserWindowEnumeration, | 330 &BrowserWindowEnumeration, |
264 reinterpret_cast<LPARAM>(&visible_window)); | 331 reinterpret_cast<LPARAM>(&visible_window)); |
265 | 332 |
266 // If there is a visible browser window, ask the user before killing it. | 333 // If there is a visible browser window, ask the user before killing it. |
267 if (visible_window && !should_kill_remote_process_callback_.Run()) { | 334 if (visible_window && !should_kill_remote_process_callback_.Run()) { |
268 // The user denied. Quit silently. | 335 // The user denied. Quit silently. |
269 return PROCESS_NOTIFIED; | 336 return PROCESS_NOTIFIED; |
270 } | 337 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 return window_.hwnd() != NULL; | 415 return window_.hwnd() != NULL; |
349 } | 416 } |
350 | 417 |
351 void ProcessSingleton::Cleanup() { | 418 void ProcessSingleton::Cleanup() { |
352 } | 419 } |
353 | 420 |
354 void ProcessSingleton::OverrideShouldKillRemoteProcessCallbackForTesting( | 421 void ProcessSingleton::OverrideShouldKillRemoteProcessCallbackForTesting( |
355 const ShouldKillRemoteProcessCallback& display_dialog_callback) { | 422 const ShouldKillRemoteProcessCallback& display_dialog_callback) { |
356 should_kill_remote_process_callback_ = display_dialog_callback; | 423 should_kill_remote_process_callback_ = display_dialog_callback; |
357 } | 424 } |
OLD | NEW |