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 <shellapi.h> | 7 #include <shellapi.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/process/process.h" | 15 #include "base/process/process.h" |
16 #include "base/process/process_info.h" | 16 #include "base/process/process_info.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
21 #include "base/win/registry.h" | 21 #include "base/win/registry.h" |
22 #include "base/win/scoped_handle.h" | 22 #include "base/win/scoped_handle.h" |
23 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
25 #include "chrome/browser/browser_process_platform_part.h" | 25 #include "chrome/browser/browser_process_platform_part.h" |
26 #include "chrome/browser/chrome_process_finder_win.h" | 26 #include "chrome/browser/chrome_process_finder_win.h" |
27 #include "chrome/browser/shell_integration.h" | 27 #include "chrome/browser/shell_integration.h" |
28 #include "chrome/browser/ui/simple_message_box.h" | 28 #include "chrome/browser/ui/simple_message_box.h" |
29 #include "chrome/chrome_watcher/kasko_util.h" | |
29 #include "chrome/common/chrome_constants.h" | 30 #include "chrome/common/chrome_constants.h" |
30 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
31 #include "chrome/common/chrome_paths_internal.h" | 32 #include "chrome/common/chrome_paths_internal.h" |
32 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
33 #include "chrome/grit/chromium_strings.h" | 34 #include "chrome/grit/chromium_strings.h" |
35 #include "chrome/installer/util/browser_distribution.h" | |
36 #include "chrome/installer/util/util_constants.h" | |
34 #include "chrome/installer/util/wmi.h" | 37 #include "chrome/installer/util/wmi.h" |
35 #include "content/public/common/result_codes.h" | 38 #include "content/public/common/result_codes.h" |
36 #include "net/base/escape.h" | 39 #include "net/base/escape.h" |
40 #include "third_party/kasko/kasko_features.h" | |
37 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
38 #include "ui/gfx/win/hwnd_util.h" | 42 #include "ui/gfx/win/hwnd_util.h" |
39 | 43 |
40 namespace { | 44 namespace { |
41 | 45 |
42 const char kLockfile[] = "lockfile"; | 46 const char kLockfile[] = "lockfile"; |
43 | 47 |
44 // A helper class that acquires the given |mutex| while the AutoLockMutex is in | 48 // A helper class that acquires the given |mutex| while the AutoLockMutex is in |
45 // scope. | 49 // scope. |
46 class AutoLockMutex { | 50 class AutoLockMutex { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 case chrome::NOTIFY_SUCCESS: | 246 case chrome::NOTIFY_SUCCESS: |
243 return PROCESS_NOTIFIED; | 247 return PROCESS_NOTIFIED; |
244 case chrome::NOTIFY_FAILED: | 248 case chrome::NOTIFY_FAILED: |
245 remote_window_ = NULL; | 249 remote_window_ = NULL; |
246 return PROCESS_NONE; | 250 return PROCESS_NONE; |
247 case chrome::NOTIFY_WINDOW_HUNG: | 251 case chrome::NOTIFY_WINDOW_HUNG: |
248 // Fall through and potentially terminate the hung browser. | 252 // Fall through and potentially terminate the hung browser. |
249 break; | 253 break; |
250 } | 254 } |
251 | 255 |
256 // The window is hung. | |
252 DWORD process_id = 0; | 257 DWORD process_id = 0; |
253 DWORD thread_id = ::GetWindowThreadProcessId(remote_window_, &process_id); | 258 DWORD thread_id = ::GetWindowThreadProcessId(remote_window_, &process_id); |
254 if (!thread_id || !process_id) { | 259 if (!thread_id || !process_id) { |
255 remote_window_ = NULL; | 260 remote_window_ = NULL; |
256 return PROCESS_NONE; | 261 return PROCESS_NONE; |
257 } | 262 } |
258 base::Process process = base::Process::Open(process_id); | 263 base::Process process = base::Process::Open(process_id); |
259 | 264 |
260 // The window is hung. Scan for every window to find a visible one. | 265 #if BUILDFLAG(ENABLE_KASKO) |
Sigurður Ásgeirsson
2016/03/31 19:28:49
As we discussed, there is a race on the PID here,
manzagop (departed)
2016/04/01 16:09:00
Done.
| |
266 // Capture a failed rendez-vous hang report of the other process. Kasko needs | |
267 // the exception context to live either in the dumper of the dumpee. This | |
268 // means we cannot rely on kasko reporters from either browser watcher, and | |
269 // instead spin up a new reporter. Note that we will exit shortly after | |
270 // capturing the report, meaning the report may not get uploaded by this | |
271 // reporter. | |
272 // DO NOT SUBMIT: add a build flag for capturign RDV hangs | |
273 // #if BUILDFLAG(ENABLE_KASKO_RDV_HANG_REPORTS) | |
274 // TODO(manzagop): add a metric for the number of captured hang reports, for | |
275 // comparison with uploaded count? | |
276 | |
277 // Check the channel | |
278 // DO NOT SUBMIT: only on canary. | |
279 // base::string16 channel_name = GoogleUpdateSettings::GetChromeChannel(!Insta llUtil::IsPerUserInstall(cmd_line.GetProgram())); | |
280 // if (base::StringPiece16(channel_name) == L"" || | |
281 // base::StringPiece16(channel_name) == installer::kChromeChannelCanary) | |
282 | |
283 base::FilePath data_base_dir; | |
284 chrome::GetDefaultUserDataDirectory(&data_base_dir); | |
285 base::string16 endpoint = | |
286 L"chrome_kasko_hangs_" + | |
287 base::UintToString16(base::Process::Current().Pid()); | |
288 | |
289 bool launched_kasko = | |
290 InitializeKaskoReporter(endpoint, data_base_dir.value().c_str()); | |
291 if (launched_kasko) { | |
292 // DO NOT SUBMIT: add a specific crash keys (RDV hang). | |
293 DumpHungProcess(thread_id, installer::kChromeChannelCanary, process); | |
294 ShutdownKaskoReporter(); | |
295 } | |
296 #endif // BUILDFLAG(ENABLE_KASKO) | |
297 | |
298 // Scan for every window to find a visible one. | |
261 bool visible_window = false; | 299 bool visible_window = false; |
262 ::EnumThreadWindows(thread_id, | 300 ::EnumThreadWindows(thread_id, |
263 &BrowserWindowEnumeration, | 301 &BrowserWindowEnumeration, |
264 reinterpret_cast<LPARAM>(&visible_window)); | 302 reinterpret_cast<LPARAM>(&visible_window)); |
265 | 303 |
266 // If there is a visible browser window, ask the user before killing it. | 304 // If there is a visible browser window, ask the user before killing it. |
267 if (visible_window && !should_kill_remote_process_callback_.Run()) { | 305 if (visible_window && !should_kill_remote_process_callback_.Run()) { |
268 // The user denied. Quit silently. | 306 // The user denied. Quit silently. |
269 return PROCESS_NOTIFIED; | 307 return PROCESS_NOTIFIED; |
270 } | 308 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 return window_.hwnd() != NULL; | 386 return window_.hwnd() != NULL; |
349 } | 387 } |
350 | 388 |
351 void ProcessSingleton::Cleanup() { | 389 void ProcessSingleton::Cleanup() { |
352 } | 390 } |
353 | 391 |
354 void ProcessSingleton::OverrideShouldKillRemoteProcessCallbackForTesting( | 392 void ProcessSingleton::OverrideShouldKillRemoteProcessCallbackForTesting( |
355 const ShouldKillRemoteProcessCallback& display_dialog_callback) { | 393 const ShouldKillRemoteProcessCallback& display_dialog_callback) { |
356 should_kill_remote_process_callback_ = display_dialog_callback; | 394 should_kill_remote_process_callback_ = display_dialog_callback; |
357 } | 395 } |
OLD | NEW |