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 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/process/kill.h" | 13 #include "base/process/kill.h" |
| 14 #include "base/process/process.h" |
14 #include "base/process/process_info.h" | 15 #include "base/process/process_info.h" |
15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
19 #include "base/win/metro.h" | 20 #include "base/win/metro.h" |
20 #include "base/win/registry.h" | 21 #include "base/win/registry.h" |
21 #include "base/win/scoped_handle.h" | 22 #include "base/win/scoped_handle.h" |
22 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
23 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 remote_window_ = NULL; | 260 remote_window_ = NULL; |
260 break; | 261 break; |
261 } | 262 } |
262 | 263 |
263 DWORD process_id = 0; | 264 DWORD process_id = 0; |
264 DWORD thread_id = ::GetWindowThreadProcessId(remote_window_, &process_id); | 265 DWORD thread_id = ::GetWindowThreadProcessId(remote_window_, &process_id); |
265 if (!thread_id || !process_id) { | 266 if (!thread_id || !process_id) { |
266 remote_window_ = NULL; | 267 remote_window_ = NULL; |
267 return PROCESS_NONE; | 268 return PROCESS_NONE; |
268 } | 269 } |
| 270 base::Process process = base::Process::Open(process_id); |
269 | 271 |
270 // The window is hung. Scan for every window to find a visible one. | 272 // The window is hung. Scan for every window to find a visible one. |
271 bool visible_window = false; | 273 bool visible_window = false; |
272 ::EnumThreadWindows(thread_id, | 274 ::EnumThreadWindows(thread_id, |
273 &BrowserWindowEnumeration, | 275 &BrowserWindowEnumeration, |
274 reinterpret_cast<LPARAM>(&visible_window)); | 276 reinterpret_cast<LPARAM>(&visible_window)); |
275 | 277 |
276 // If there is a visible browser window, ask the user before killing it. | 278 // If there is a visible browser window, ask the user before killing it. |
277 if (visible_window && | 279 if (visible_window && |
278 chrome::ShowMessageBox( | 280 chrome::ShowMessageBox( |
279 NULL, | 281 NULL, |
280 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), | 282 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), |
281 l10n_util::GetStringUTF16(IDS_BROWSER_HUNGBROWSER_MESSAGE), | 283 l10n_util::GetStringUTF16(IDS_BROWSER_HUNGBROWSER_MESSAGE), |
282 chrome::MESSAGE_BOX_TYPE_QUESTION) == chrome::MESSAGE_BOX_RESULT_NO) { | 284 chrome::MESSAGE_BOX_TYPE_QUESTION) == chrome::MESSAGE_BOX_RESULT_NO) { |
283 // The user denied. Quit silently. | 285 // The user denied. Quit silently. |
284 return PROCESS_NOTIFIED; | 286 return PROCESS_NOTIFIED; |
285 } | 287 } |
286 | 288 |
287 // Time to take action. Kill the browser process. | 289 // Time to take action. Kill the browser process. |
288 base::KillProcessById(process_id, content::RESULT_CODE_HUNG, true); | 290 base::KillProcess(process.Handle(), content::RESULT_CODE_HUNG, true); |
289 remote_window_ = NULL; | 291 remote_window_ = NULL; |
290 return PROCESS_NONE; | 292 return PROCESS_NONE; |
291 } | 293 } |
292 | 294 |
293 ProcessSingleton::NotifyResult | 295 ProcessSingleton::NotifyResult |
294 ProcessSingleton::NotifyOtherProcessOrCreate() { | 296 ProcessSingleton::NotifyOtherProcessOrCreate() { |
295 ProcessSingleton::NotifyResult result = PROCESS_NONE; | 297 ProcessSingleton::NotifyResult result = PROCESS_NONE; |
296 if (!Create()) { | 298 if (!Create()) { |
297 result = NotifyOtherProcess(); | 299 result = NotifyOtherProcess(); |
298 if (result == PROCESS_NONE) | 300 if (result == PROCESS_NONE) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 ::SetEvent(metro_activation_event.Get()); | 422 ::SetEvent(metro_activation_event.Get()); |
421 } | 423 } |
422 } | 424 } |
423 } | 425 } |
424 | 426 |
425 return window_.hwnd() != NULL; | 427 return window_.hwnd() != NULL; |
426 } | 428 } |
427 | 429 |
428 void ProcessSingleton::Cleanup() { | 430 void ProcessSingleton::Cleanup() { |
429 } | 431 } |
OLD | NEW |