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 <windows.h> |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| 11 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/process/process.h" | 16 #include "base/process/process.h" |
| 17 #include "base/process/process_info.h" | 17 #include "base/process/process_info.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "base/win/registry.h" | 22 #include "base/win/registry.h" |
| 23 #include "base/win/scoped_handle.h" | 23 #include "base/win/scoped_handle.h" |
| 24 #include "base/win/windows_version.h" | 24 #include "base/win/windows_version.h" |
| 25 #include "chrome/browser/browser_process.h" | |
| 26 #include "chrome/browser/browser_process_platform_part.h" | |
| 27 #include "chrome/browser/shell_integration.h" | 25 #include "chrome/browser/shell_integration.h" |
| 28 #include "chrome/browser/ui/simple_message_box.h" | 26 #include "chrome/browser/ui/simple_message_box.h" |
| 29 #include "chrome/browser/win/chrome_process_finder.h" | 27 #include "chrome/browser/win/chrome_process_finder.h" |
| 30 #include "chrome/common/chrome_constants.h" | 28 #include "chrome/common/chrome_constants.h" |
| 31 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
| 32 #include "chrome/common/chrome_paths_internal.h" | 30 #include "chrome/common/chrome_paths_internal.h" |
| 33 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
| 34 #include "chrome/grit/chromium_strings.h" | 32 #include "chrome/grit/chromium_strings.h" |
| 35 #include "chrome/installer/util/wmi.h" | 33 #include "chrome/installer/util/wmi.h" |
| 36 #include "content/public/common/result_codes.h" | 34 #include "content/public/common/result_codes.h" |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 } | 274 } |
| 277 | 275 |
| 278 // Time to take action. Kill the browser process. | 276 // Time to take action. Kill the browser process. |
| 279 process.Terminate(content::RESULT_CODE_HUNG, true); | 277 process.Terminate(content::RESULT_CODE_HUNG, true); |
| 280 remote_window_ = NULL; | 278 remote_window_ = NULL; |
| 281 return PROCESS_NONE; | 279 return PROCESS_NONE; |
| 282 } | 280 } |
| 283 | 281 |
| 284 ProcessSingleton::NotifyResult | 282 ProcessSingleton::NotifyResult |
| 285 ProcessSingleton::NotifyOtherProcessOrCreate() { | 283 ProcessSingleton::NotifyOtherProcessOrCreate() { |
| 286 ProcessSingleton::NotifyResult result = PROCESS_NONE; | 284 for (int i = 0; i < 2; ++i) { |
| 287 if (!Create()) { | 285 if (Create()) { |
|
grt (UTC plus 2)
2016/08/26 20:24:00
nit: omit braces for single-line conditional and b
| |
| 288 result = NotifyOtherProcess(); | 286 return PROCESS_NONE; // This is the single browser process. |
| 289 if (result == PROCESS_NONE) | 287 } |
| 290 result = PROFILE_IN_USE; | 288 ProcessSingleton::NotifyResult result = NotifyOtherProcess(); |
| 291 } else { | 289 if (result == PROCESS_NOTIFIED || result == LOCK_ERROR) { |
| 292 g_browser_process->platform_part()->PlatformSpecificCommandLineProcessing( | 290 // The single browser process was notified, the user chose not to |
| 293 *base::CommandLine::ForCurrentProcess()); | 291 // terminate a hung browser, or the lock file could not be created. |
| 292 // Nothing more to do. | |
| 293 return result; | |
| 294 } | |
| 295 DCHECK_EQ(PROCESS_NONE, result); | |
| 296 // The process could not be notified for some reason, or it was hung and | |
| 297 // terminated. Retry once if this is the first time; otherwise, fall through | |
| 298 // to report that the process must exit because the profile is in use. | |
| 294 } | 299 } |
| 295 return result; | 300 return PROFILE_IN_USE; |
| 296 } | 301 } |
| 297 | 302 |
| 298 // Look for a Chrome instance that uses the same profile directory. If there | 303 // Look for a Chrome instance that uses the same profile directory. If there |
| 299 // isn't one, create a message window with its title set to the profile | 304 // isn't one, create a message window with its title set to the profile |
| 300 // directory path. | 305 // directory path. |
| 301 bool ProcessSingleton::Create() { | 306 bool ProcessSingleton::Create() { |
| 302 static const wchar_t kMutexName[] = L"Local\\ChromeProcessSingletonStartup!"; | 307 static const wchar_t kMutexName[] = L"Local\\ChromeProcessSingletonStartup!"; |
| 303 | 308 |
| 304 remote_window_ = chrome::FindRunningChromeWindow(user_data_dir_); | 309 remote_window_ = chrome::FindRunningChromeWindow(user_data_dir_); |
| 305 if (!remote_window_ && !EscapeVirtualization(user_data_dir_)) { | 310 if (!remote_window_ && !EscapeVirtualization(user_data_dir_)) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 return window_.hwnd() != NULL; | 359 return window_.hwnd() != NULL; |
| 355 } | 360 } |
| 356 | 361 |
| 357 void ProcessSingleton::Cleanup() { | 362 void ProcessSingleton::Cleanup() { |
| 358 } | 363 } |
| 359 | 364 |
| 360 void ProcessSingleton::OverrideShouldKillRemoteProcessCallbackForTesting( | 365 void ProcessSingleton::OverrideShouldKillRemoteProcessCallbackForTesting( |
| 361 const ShouldKillRemoteProcessCallback& display_dialog_callback) { | 366 const ShouldKillRemoteProcessCallback& display_dialog_callback) { |
| 362 should_kill_remote_process_callback_ = display_dialog_callback; | 367 should_kill_remote_process_callback_ = display_dialog_callback; |
| 363 } | 368 } |
| OLD | NEW |