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_GTK) | 88 #if defined(TOOLKIT_GTK) |
86 #include <gdk/gdk.h> | 89 #include <gdk/gdk.h> |
87 #endif | 90 #endif |
88 #if defined(TOOLKIT_VIEWS) && !defined(OS_CHROMEOS) | 91 #if defined(TOOLKIT_VIEWS) && !defined(OS_CHROMEOS) |
89 #include "ui/views/linux_ui/linux_ui.h" | 92 #include "ui/views/linux_ui/linux_ui.h" |
90 #endif | 93 #endif |
91 | 94 |
92 using content::BrowserThread; | 95 using content::BrowserThread; |
93 | 96 |
94 const int ProcessSingleton::kTimeoutInSeconds; | 97 const int ProcessSingleton::kTimeoutInSeconds; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 *pid = -1; | 297 *pid = -1; |
295 | 298 |
296 return true; | 299 return true; |
297 } | 300 } |
298 | 301 |
299 // Returns true if the user opted to unlock the profile. | 302 // Returns true if the user opted to unlock the profile. |
300 bool DisplayProfileInUseError(const base::FilePath& lock_path, | 303 bool DisplayProfileInUseError(const base::FilePath& lock_path, |
301 const std::string& hostname, | 304 const std::string& hostname, |
302 int pid) { | 305 int pid) { |
303 base::string16 error = l10n_util::GetStringFUTF16( | 306 base::string16 error = l10n_util::GetStringFUTF16( |
304 IDS_PROFILE_IN_USE_LINUX, | 307 IDS_PROFILE_IN_USE_POSIX, |
305 base::IntToString16(pid), | 308 base::IntToString16(pid), |
306 base::ASCIIToUTF16(hostname)); | 309 base::ASCIIToUTF16(hostname)); |
310 LOG(ERROR) << base::SysWideToNativeMB(base::UTF16ToWide(error)).c_str(); | |
311 if (!g_disable_prompt) { | |
312 #if defined(OS_LINUX) | |
307 base::string16 relaunch_button_text = l10n_util::GetStringUTF16( | 313 base::string16 relaunch_button_text = l10n_util::GetStringUTF16( |
308 IDS_PROFILE_IN_USE_LINUX_RELAUNCH); | 314 IDS_PROFILE_IN_USE_LINUX_RELAUNCH); |
309 LOG(ERROR) << base::SysWideToNativeMB(base::UTF16ToWide(error)).c_str(); | 315 return ShowProcessSingletonDialog(error, relaunch_button_text); |
tapted
2014/04/08 17:56:44
Does this need an implementation on mac as well? I
jackhou1
2014/04/14 04:12:10
It's actually less common than what users get now.
mattm
2014/04/17 21:44:54
I'm not sure about osx, but linux doesn't normally
| |
310 if (!g_disable_prompt) | 316 #endif |
311 return ShowProcessSingletonDialog(error, relaunch_button_text); | 317 } |
312 return false; | 318 return false; |
313 } | 319 } |
314 | 320 |
315 bool IsChromeProcess(pid_t pid) { | 321 bool IsChromeProcess(pid_t pid) { |
316 base::FilePath other_chrome_path(base::GetProcessExecutablePath(pid)); | 322 base::FilePath other_chrome_path(base::GetProcessExecutablePath(pid)); |
317 return (!other_chrome_path.empty() && | 323 return (!other_chrome_path.empty() && |
318 other_chrome_path.BaseName() == | 324 other_chrome_path.BaseName() == |
319 base::FilePath(chrome::kBrowserProcessExecutableName)); | 325 base::FilePath(chrome::kBrowserProcessExecutableName)); |
tapted
2014/04/08 17:56:44
This might not work on mac? -- chrome::kBrowserPro
jackhou1
2014/04/14 04:12:10
chrome::kBrowserProcessExecutableName seems to be
| |
320 } | 326 } |
321 | 327 |
322 // A helper class to hold onto a socket. | 328 // A helper class to hold onto a socket. |
323 class ScopedSocket { | 329 class ScopedSocket { |
324 public: | 330 public: |
325 ScopedSocket() : fd_(-1) { Reset(); } | 331 ScopedSocket() : fd_(-1) { Reset(); } |
326 ~ScopedSocket() { Close(); } | 332 ~ScopedSocket() { Close(); } |
327 int fd() { return fd_; } | 333 int fd() { return fd_; } |
328 void Reset() { | 334 void Reset() { |
329 Close(); | 335 Close(); |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
985 } | 991 } |
986 | 992 |
987 void ProcessSingleton::KillProcess(int pid) { | 993 void ProcessSingleton::KillProcess(int pid) { |
988 // TODO(james.su@gmail.com): Is SIGKILL ok? | 994 // TODO(james.su@gmail.com): Is SIGKILL ok? |
989 int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL); | 995 int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL); |
990 // ESRCH = No Such Process (can happen if the other process is already in | 996 // ESRCH = No Such Process (can happen if the other process is already in |
991 // progress of shutting down and finishes before we try to kill it). | 997 // progress of shutting down and finishes before we try to kill it). |
992 DCHECK(rv == 0 || errno == ESRCH) << "Error killing process: " | 998 DCHECK(rv == 0 || errno == ESRCH) << "Error killing process: " |
993 << safe_strerror(errno); | 999 << safe_strerror(errno); |
994 } | 1000 } |
OLD | NEW |