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/crash/content/app/crashpad.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 Loading... | |
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 if (!crash_reporter::GetUploadsEnabled()) | |
scottmg
2016/04/08 16:04:34
Sorry, I only looked at the other file. As this is
manzagop (departed)
2016/04/08 21:15:56
I went with instantiating a ChromeCrashReporterCli
scottmg
2016/04/08 22:20:55
Adding the dependency and duplicating that code se
manzagop (departed)
2016/04/11 15:26:49
Agreed there's no need to have this reporter. As f
| |
199 return; | |
200 | |
201 // TODO(manzagop): add a metric for the number of captured hang reports, for | |
202 // comparison with uploaded count? | |
203 | |
204 // Only report on canary (or unspecified). | |
205 const version_info::Channel channel = chrome::GetChannel(); | |
206 if (channel != version_info::Channel::UNKNOWN && | |
207 channel != version_info::Channel::CANARY) { | |
208 return; | |
209 } | |
210 // TODO(manzagop): add a metric for the number of times this does not match. | |
211 if (!EnsureTargetProcessValidForCapture(process)) | |
212 return; | |
213 | |
214 // Initialize a reporter, capture a report and shutdown the reporter. | |
215 base::FilePath watcher_data_directory; | |
216 if (PathService::Get(chrome::DIR_WATCHER_DATA, &watcher_data_directory)) { | |
217 base::string16 endpoint = | |
218 L"chrome_kasko_rdv_" + | |
219 base::UintToString16(base::Process::Current().Pid()); | |
220 | |
221 bool launched_kasko = InitializeKaskoReporter( | |
222 endpoint, watcher_data_directory.value().c_str()); | |
223 if (launched_kasko) { | |
224 DumpHungProcess(thread_id, installer::kChromeChannelCanary, L"failed-rdv", | |
225 process); | |
226 // We immediately request Kasko shutdown. This may block until the | |
227 // completion of ongoing background tasks (e.g., upload). If the report is | |
228 // not uploaded by this reporter, any other Kasko reporter may upload it. | |
229 ShutdownKaskoReporter(); | |
230 } | |
231 } | |
232 } | |
233 #endif // BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS) | |
234 #endif // BUILDFLAG(ENABLE_KASKO) | |
235 | |
182 } // namespace | 236 } // namespace |
183 | 237 |
184 // Microsoft's Softricity virtualization breaks the sandbox processes. | 238 // Microsoft's Softricity virtualization breaks the sandbox processes. |
185 // So, if we detect the Softricity DLL we use WMI Win32_Process.Create to | 239 // So, if we detect the Softricity DLL we use WMI Win32_Process.Create to |
186 // break out of the virtualization environment. | 240 // break out of the virtualization environment. |
187 // http://code.google.com/p/chromium/issues/detail?id=43650 | 241 // http://code.google.com/p/chromium/issues/detail?id=43650 |
188 bool ProcessSingleton::EscapeVirtualization( | 242 bool ProcessSingleton::EscapeVirtualization( |
189 const base::FilePath& user_data_dir) { | 243 const base::FilePath& user_data_dir) { |
190 if (::GetModuleHandle(L"sftldr_wow64.dll") || | 244 if (::GetModuleHandle(L"sftldr_wow64.dll") || |
191 ::GetModuleHandle(L"sftldr.dll")) { | 245 ::GetModuleHandle(L"sftldr.dll")) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 case chrome::NOTIFY_SUCCESS: | 296 case chrome::NOTIFY_SUCCESS: |
243 return PROCESS_NOTIFIED; | 297 return PROCESS_NOTIFIED; |
244 case chrome::NOTIFY_FAILED: | 298 case chrome::NOTIFY_FAILED: |
245 remote_window_ = NULL; | 299 remote_window_ = NULL; |
246 return PROCESS_NONE; | 300 return PROCESS_NONE; |
247 case chrome::NOTIFY_WINDOW_HUNG: | 301 case chrome::NOTIFY_WINDOW_HUNG: |
248 // Fall through and potentially terminate the hung browser. | 302 // Fall through and potentially terminate the hung browser. |
249 break; | 303 break; |
250 } | 304 } |
251 | 305 |
306 // The window is hung. | |
252 DWORD process_id = 0; | 307 DWORD process_id = 0; |
253 DWORD thread_id = ::GetWindowThreadProcessId(remote_window_, &process_id); | 308 DWORD thread_id = ::GetWindowThreadProcessId(remote_window_, &process_id); |
254 if (!thread_id || !process_id) { | 309 if (!thread_id || !process_id) { |
255 remote_window_ = NULL; | 310 remote_window_ = NULL; |
256 return PROCESS_NONE; | 311 return PROCESS_NONE; |
257 } | 312 } |
313 | |
314 // Get a handle to the process that created the window. | |
258 base::Process process = base::Process::Open(process_id); | 315 base::Process process = base::Process::Open(process_id); |
259 | 316 |
260 // The window is hung. Scan for every window to find a visible one. | 317 // Optionally send a failed rendez-vous report. |
318 // Note: we nominate the thread that created the window as the root of the | |
319 // search for a hung thread. | |
320 #if defined(GOOGLE_CHROME_BUILD) | |
321 #if BUILDFLAG(ENABLE_KASKO) | |
322 #if BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS) | |
323 SendFailedRdvReport(process, thread_id); | |
324 #endif // BUILDFLAG(ENABLE_KASKO_FAILED_RDV_REPORTS) | |
325 #endif // BUILDFLAG(ENABLE_KASKO) | |
326 #endif // GOOGLE_CHROME_BUILD | |
327 | |
328 // Scan for every window to find a visible one. | |
261 bool visible_window = false; | 329 bool visible_window = false; |
262 ::EnumThreadWindows(thread_id, | 330 ::EnumThreadWindows(thread_id, |
263 &BrowserWindowEnumeration, | 331 &BrowserWindowEnumeration, |
264 reinterpret_cast<LPARAM>(&visible_window)); | 332 reinterpret_cast<LPARAM>(&visible_window)); |
265 | 333 |
266 // If there is a visible browser window, ask the user before killing it. | 334 // If there is a visible browser window, ask the user before killing it. |
267 if (visible_window && !should_kill_remote_process_callback_.Run()) { | 335 if (visible_window && !should_kill_remote_process_callback_.Run()) { |
268 // The user denied. Quit silently. | 336 // The user denied. Quit silently. |
269 return PROCESS_NOTIFIED; | 337 return PROCESS_NOTIFIED; |
270 } | 338 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 return window_.hwnd() != NULL; | 416 return window_.hwnd() != NULL; |
349 } | 417 } |
350 | 418 |
351 void ProcessSingleton::Cleanup() { | 419 void ProcessSingleton::Cleanup() { |
352 } | 420 } |
353 | 421 |
354 void ProcessSingleton::OverrideShouldKillRemoteProcessCallbackForTesting( | 422 void ProcessSingleton::OverrideShouldKillRemoteProcessCallbackForTesting( |
355 const ShouldKillRemoteProcessCallback& display_dialog_callback) { | 423 const ShouldKillRemoteProcessCallback& display_dialog_callback) { |
356 should_kill_remote_process_callback_ = display_dialog_callback; | 424 should_kill_remote_process_callback_ = display_dialog_callback; |
357 } | 425 } |
OLD | NEW |