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 // On Linux, when the user tries to launch a second copy of chrome, we check | 5 // On Linux, when the user tries to launch a second copy of chrome, we check |
6 // for a socket in the user's profile directory. If the socket file is open we | 6 // for a socket in the user's profile directory. If the socket file is open we |
7 // send a message to the first chrome browser process with the current | 7 // send a message to the first chrome browser process with the current |
8 // directory and second process command line flags. The second process then | 8 // directory and second process command line flags. The second process then |
9 // exits. | 9 // exits. |
10 // | 10 // |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 #include "base/sequenced_task_runner_helpers.h" | 67 #include "base/sequenced_task_runner_helpers.h" |
68 #include "base/stl_util.h" | 68 #include "base/stl_util.h" |
69 #include "base/strings/string_number_conversions.h" | 69 #include "base/strings/string_number_conversions.h" |
70 #include "base/strings/string_split.h" | 70 #include "base/strings/string_split.h" |
71 #include "base/strings/stringprintf.h" | 71 #include "base/strings/stringprintf.h" |
72 #include "base/strings/sys_string_conversions.h" | 72 #include "base/strings/sys_string_conversions.h" |
73 #include "base/strings/utf_string_conversions.h" | 73 #include "base/strings/utf_string_conversions.h" |
74 #include "base/threading/platform_thread.h" | 74 #include "base/threading/platform_thread.h" |
75 #include "base/time/time.h" | 75 #include "base/time/time.h" |
76 #include "base/timer/timer.h" | 76 #include "base/timer/timer.h" |
77 #include "chrome/browser/ui/process_singleton_dialog_linux.h" | |
78 #include "chrome/common/chrome_constants.h" | 77 #include "chrome/common/chrome_constants.h" |
79 #include "content/public/browser/browser_thread.h" | 78 #include "content/public/browser/browser_thread.h" |
80 #include "grit/chromium_strings.h" | 79 #include "grit/chromium_strings.h" |
81 #include "grit/generated_resources.h" | 80 #include "grit/generated_resources.h" |
82 #include "net/base/net_util.h" | 81 #include "net/base/net_util.h" |
83 #include "ui/base/l10n/l10n_util.h" | 82 #include "ui/base/l10n/l10n_util.h" |
84 | 83 |
| 84 #if defined(OS_LINUX) |
| 85 #include "chrome/browser/ui/process_singleton_dialog_linux.h" |
| 86 #endif |
| 87 |
85 #if defined(TOOLKIT_VIEWS) && !defined(OS_CHROMEOS) | 88 #if defined(TOOLKIT_VIEWS) && !defined(OS_CHROMEOS) |
86 #include "ui/views/linux_ui/linux_ui.h" | 89 #include "ui/views/linux_ui/linux_ui.h" |
87 #endif | 90 #endif |
88 | 91 |
89 using content::BrowserThread; | 92 using content::BrowserThread; |
90 | 93 |
91 const int ProcessSingleton::kTimeoutInSeconds; | 94 const int ProcessSingleton::kTimeoutInSeconds; |
92 | 95 |
93 namespace { | 96 namespace { |
94 | 97 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 *pid = -1; | 294 *pid = -1; |
292 | 295 |
293 return true; | 296 return true; |
294 } | 297 } |
295 | 298 |
296 // Returns true if the user opted to unlock the profile. | 299 // Returns true if the user opted to unlock the profile. |
297 bool DisplayProfileInUseError(const base::FilePath& lock_path, | 300 bool DisplayProfileInUseError(const base::FilePath& lock_path, |
298 const std::string& hostname, | 301 const std::string& hostname, |
299 int pid) { | 302 int pid) { |
300 base::string16 error = l10n_util::GetStringFUTF16( | 303 base::string16 error = l10n_util::GetStringFUTF16( |
301 IDS_PROFILE_IN_USE_LINUX, | 304 IDS_PROFILE_IN_USE_POSIX, |
302 base::IntToString16(pid), | 305 base::IntToString16(pid), |
303 base::ASCIIToUTF16(hostname)); | 306 base::ASCIIToUTF16(hostname)); |
| 307 LOG(ERROR) << base::SysWideToNativeMB(base::UTF16ToWide(error)).c_str(); |
| 308 if (!g_disable_prompt) { |
| 309 #if defined(OS_LINUX) |
304 base::string16 relaunch_button_text = l10n_util::GetStringUTF16( | 310 base::string16 relaunch_button_text = l10n_util::GetStringUTF16( |
305 IDS_PROFILE_IN_USE_LINUX_RELAUNCH); | 311 IDS_PROFILE_IN_USE_LINUX_RELAUNCH); |
306 LOG(ERROR) << base::SysWideToNativeMB(base::UTF16ToWide(error)).c_str(); | 312 return ShowProcessSingletonDialog(error, relaunch_button_text); |
307 if (!g_disable_prompt) | 313 #endif |
308 return ShowProcessSingletonDialog(error, relaunch_button_text); | 314 } |
309 return false; | 315 return false; |
310 } | 316 } |
311 | 317 |
312 bool IsChromeProcess(pid_t pid) { | 318 bool IsChromeProcess(pid_t pid) { |
313 base::FilePath other_chrome_path(base::GetProcessExecutablePath(pid)); | 319 base::FilePath other_chrome_path(base::GetProcessExecutablePath(pid)); |
314 return (!other_chrome_path.empty() && | 320 return (!other_chrome_path.empty() && |
315 other_chrome_path.BaseName() == | 321 other_chrome_path.BaseName() == |
316 base::FilePath(chrome::kBrowserProcessExecutableName)); | 322 base::FilePath(chrome::kBrowserProcessExecutableName)); |
317 } | 323 } |
318 | 324 |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 } | 983 } |
978 | 984 |
979 void ProcessSingleton::KillProcess(int pid) { | 985 void ProcessSingleton::KillProcess(int pid) { |
980 // TODO(james.su@gmail.com): Is SIGKILL ok? | 986 // TODO(james.su@gmail.com): Is SIGKILL ok? |
981 int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL); | 987 int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL); |
982 // ESRCH = No Such Process (can happen if the other process is already in | 988 // ESRCH = No Such Process (can happen if the other process is already in |
983 // progress of shutting down and finishes before we try to kill it). | 989 // progress of shutting down and finishes before we try to kill it). |
984 DCHECK(rv == 0 || errno == ESRCH) << "Error killing process: " | 990 DCHECK(rv == 0 || errno == ESRCH) << "Error killing process: " |
985 << safe_strerror(errno); | 991 << safe_strerror(errno); |
986 } | 992 } |
OLD | NEW |