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 // 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 | |
| 309 if (g_disable_prompt) | |
| 310 return false; | |
| 311 | |
| 312 #if defined(OS_LINUX) | |
| 304 base::string16 relaunch_button_text = l10n_util::GetStringUTF16( | 313 base::string16 relaunch_button_text = l10n_util::GetStringUTF16( |
| 305 IDS_PROFILE_IN_USE_LINUX_RELAUNCH); | 314 IDS_PROFILE_IN_USE_LINUX_RELAUNCH); |
| 306 LOG(ERROR) << base::SysWideToNativeMB(base::UTF16ToWide(error)).c_str(); | 315 return ShowProcessSingletonDialog(error, relaunch_button_text); |
| 307 if (!g_disable_prompt) | 316 #elif defined(OS_MACOSX) |
| 308 return ShowProcessSingletonDialog(error, relaunch_button_text); | 317 // On Mac, always usurp the lock. |
| 318 return true; | |
| 319 #endif | |
| 320 | |
| 321 NOTREACHED(); | |
| 309 return false; | 322 return false; |
| 310 } | 323 } |
| 311 | 324 |
| 312 bool IsChromeProcess(pid_t pid) { | 325 bool IsChromeProcess(pid_t pid) { |
| 313 base::FilePath other_chrome_path(base::GetProcessExecutablePath(pid)); | 326 base::FilePath other_chrome_path(base::GetProcessExecutablePath(pid)); |
| 314 return (!other_chrome_path.empty() && | 327 return (!other_chrome_path.empty() && |
| 315 other_chrome_path.BaseName() == | 328 other_chrome_path.BaseName() == |
| 316 base::FilePath(chrome::kBrowserProcessExecutableName)); | 329 base::FilePath(chrome::kBrowserProcessExecutableName)); |
| 317 } | 330 } |
| 318 | 331 |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 888 return false; | 901 return false; |
| 889 } | 902 } |
| 890 | 903 |
| 891 // Create the socket file somewhere in /tmp which is usually mounted as a | 904 // Create the socket file somewhere in /tmp which is usually mounted as a |
| 892 // normal filesystem. Some network filesystems (notably AFS) are screwy and | 905 // normal filesystem. Some network filesystems (notably AFS) are screwy and |
| 893 // do not support Unix domain sockets. | 906 // do not support Unix domain sockets. |
| 894 if (!socket_dir_.CreateUniqueTempDir()) { | 907 if (!socket_dir_.CreateUniqueTempDir()) { |
| 895 LOG(ERROR) << "Failed to create socket directory."; | 908 LOG(ERROR) << "Failed to create socket directory."; |
| 896 return false; | 909 return false; |
| 897 } | 910 } |
| 911 | |
| 912 // Check that the directory was created with the correct permissions. | |
| 913 int dir_mode = 0; | |
| 914 CHECK(base::GetPosixFilePermissions(socket_dir_.path(), &dir_mode) && | |
| 915 dir_mode == base::FILE_PERMISSION_USER_MASK) | |
| 916 << "Temp directory mode is not 700: " << std::oct << dir_mode; | |
|
Scott Hess - ex-Googler
2014/04/24 21:54:43
std::oct? Searches ... you just blew my mind! I'
| |
| 917 | |
| 898 // Setup the socket symlink and the two cookies. | 918 // Setup the socket symlink and the two cookies. |
| 899 base::FilePath socket_target_path = | 919 base::FilePath socket_target_path = |
| 900 socket_dir_.path().Append(chrome::kSingletonSocketFilename); | 920 socket_dir_.path().Append(chrome::kSingletonSocketFilename); |
| 901 base::FilePath cookie(GenerateCookie()); | 921 base::FilePath cookie(GenerateCookie()); |
| 902 base::FilePath remote_cookie_path = | 922 base::FilePath remote_cookie_path = |
| 903 socket_dir_.path().Append(chrome::kSingletonCookieFilename); | 923 socket_dir_.path().Append(chrome::kSingletonCookieFilename); |
| 904 UnlinkPath(socket_path_); | 924 UnlinkPath(socket_path_); |
| 905 UnlinkPath(cookie_path_); | 925 UnlinkPath(cookie_path_); |
| 906 if (!SymlinkPath(socket_target_path, socket_path_) || | 926 if (!SymlinkPath(socket_target_path, socket_path_) || |
| 907 !SymlinkPath(cookie, cookie_path_) || | 927 !SymlinkPath(cookie, cookie_path_) || |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 977 } | 997 } |
| 978 | 998 |
| 979 void ProcessSingleton::KillProcess(int pid) { | 999 void ProcessSingleton::KillProcess(int pid) { |
| 980 // TODO(james.su@gmail.com): Is SIGKILL ok? | 1000 // TODO(james.su@gmail.com): Is SIGKILL ok? |
| 981 int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL); | 1001 int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL); |
| 982 // ESRCH = No Such Process (can happen if the other process is already in | 1002 // 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). | 1003 // progress of shutting down and finishes before we try to kill it). |
| 984 DCHECK(rv == 0 || errno == ESRCH) << "Error killing process: " | 1004 DCHECK(rv == 0 || errno == ESRCH) << "Error killing process: " |
| 985 << safe_strerror(errno); | 1005 << safe_strerror(errno); |
| 986 } | 1006 } |
| OLD | NEW |