Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2301)

Unified Diff: chrome/browser/process_singleton_linux.cc

Issue 11415237: Move many ProcessSingleton methods to "protected" visibility as an upcoming refactoring of ProcessS… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: decouple from https://codereview.chromium.org/11419258/ Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/process_singleton_linux.cc
diff --git a/chrome/browser/process_singleton_linux.cc b/chrome/browser/process_singleton_linux.cc
index 583f4bf20e875559cb4347d68c49d4c2dfb5d80f..5189b1e00cba07e8e8a08c65141cdf7cd15cfc00 100644
--- a/chrome/browser/process_singleton_linux.cc
+++ b/chrome/browser/process_singleton_linux.cc
@@ -708,12 +708,101 @@ ProcessSingleton::ProcessSingleton(const FilePath& user_data_dir)
ProcessSingleton::~ProcessSingleton() {
}
+ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcessOrCreate(
+ const NotificationCallback& notification_callback) {
+ return NotifyOtherProcessWithTimeoutOrCreate(
+ *CommandLine::ForCurrentProcess(),
+ notification_callback,
+ kTimeoutInSeconds);
+}
+
+void ProcessSingleton::Cleanup() {
+ UnlinkPath(socket_path_);
+ UnlinkPath(cookie_path_);
+ UnlinkPath(lock_path_);
+}
+
+void ProcessSingleton::DisablePromptForTesting() {
+ g_disable_prompt = true;
+}
+
ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() {
return NotifyOtherProcessWithTimeout(*CommandLine::ForCurrentProcess(),
kTimeoutInSeconds,
true);
}
+bool ProcessSingleton::Create(
+ const NotificationCallback& notification_callback) {
+ int sock;
+ sockaddr_un addr;
+
+ // The symlink lock is pointed to the hostname and process id, so other
+ // processes can find it out.
+ FilePath symlink_content(base::StringPrintf(
+ "%s%c%u",
+ net::GetHostName().c_str(),
+ kLockDelimiter,
+ current_pid_));
+
+ // Create symbol link before binding the socket, to ensure only one instance
+ // can have the socket open.
+ if (!SymlinkPath(symlink_content, lock_path_)) {
+ // If we failed to create the lock, most likely another instance won the
+ // startup race.
+ return false;
+ }
+
+ // Create the socket file somewhere in /tmp which is usually mounted as a
+ // normal filesystem. Some network filesystems (notably AFS) are screwy and
+ // do not support Unix domain sockets.
+ if (!socket_dir_.CreateUniqueTempDir()) {
+ LOG(ERROR) << "Failed to create socket directory.";
+ return false;
+ }
+ // Setup the socket symlink and the two cookies.
+ FilePath socket_target_path =
+ socket_dir_.path().Append(chrome::kSingletonSocketFilename);
+ FilePath cookie(GenerateCookie());
+ FilePath remote_cookie_path =
+ socket_dir_.path().Append(chrome::kSingletonCookieFilename);
+ UnlinkPath(socket_path_);
+ UnlinkPath(cookie_path_);
+ if (!SymlinkPath(socket_target_path, socket_path_) ||
+ !SymlinkPath(cookie, cookie_path_) ||
+ !SymlinkPath(cookie, remote_cookie_path)) {
+ // We've already locked things, so we can't have lost the startup race,
+ // but something doesn't like us.
+ LOG(ERROR) << "Failed to create symlinks.";
+ if (!socket_dir_.Delete())
+ LOG(ERROR) << "Encountered a problem when deleting socket directory.";
+ return false;
+ }
+
+ SetupSocket(socket_target_path.value(), &sock, &addr);
+
+ if (bind(sock, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) < 0) {
+ PLOG(ERROR) << "Failed to bind() " << socket_target_path.value();
+ CloseSocket(sock);
+ return false;
+ }
+
+ if (listen(sock, 5) < 0)
+ NOTREACHED() << "listen failed: " << safe_strerror(errno);
+
+ notification_callback_ = notification_callback;
+
+ DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO));
+ BrowserThread::PostTask(
+ BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&ProcessSingleton::LinuxWatcher::StartListening,
+ watcher_.get(),
+ sock));
+
+ return true;
+}
+
ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcessWithTimeout(
const CommandLine& cmd_line,
int timeout_seconds,
@@ -835,14 +924,6 @@ ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcessWithTimeout(
return PROCESS_NOTIFIED;
}
-ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcessOrCreate(
- const NotificationCallback& notification_callback) {
- return NotifyOtherProcessWithTimeoutOrCreate(
- *CommandLine::ForCurrentProcess(),
- notification_callback,
- kTimeoutInSeconds);
-}
-
ProcessSingleton::NotifyResult
ProcessSingleton::NotifyOtherProcessWithTimeoutOrCreate(
const CommandLine& command_line,
@@ -875,87 +956,6 @@ void ProcessSingleton::OverrideKillCallbackForTesting(
kill_callback_ = callback;
}
-void ProcessSingleton::DisablePromptForTesting() {
- g_disable_prompt = true;
-}
-
-bool ProcessSingleton::Create(
- const NotificationCallback& notification_callback) {
- int sock;
- sockaddr_un addr;
-
- // The symlink lock is pointed to the hostname and process id, so other
- // processes can find it out.
- FilePath symlink_content(base::StringPrintf(
- "%s%c%u",
- net::GetHostName().c_str(),
- kLockDelimiter,
- current_pid_));
-
- // Create symbol link before binding the socket, to ensure only one instance
- // can have the socket open.
- if (!SymlinkPath(symlink_content, lock_path_)) {
- // If we failed to create the lock, most likely another instance won the
- // startup race.
- return false;
- }
-
- // Create the socket file somewhere in /tmp which is usually mounted as a
- // normal filesystem. Some network filesystems (notably AFS) are screwy and
- // do not support Unix domain sockets.
- if (!socket_dir_.CreateUniqueTempDir()) {
- LOG(ERROR) << "Failed to create socket directory.";
- return false;
- }
- // Setup the socket symlink and the two cookies.
- FilePath socket_target_path =
- socket_dir_.path().Append(chrome::kSingletonSocketFilename);
- FilePath cookie(GenerateCookie());
- FilePath remote_cookie_path =
- socket_dir_.path().Append(chrome::kSingletonCookieFilename);
- UnlinkPath(socket_path_);
- UnlinkPath(cookie_path_);
- if (!SymlinkPath(socket_target_path, socket_path_) ||
- !SymlinkPath(cookie, cookie_path_) ||
- !SymlinkPath(cookie, remote_cookie_path)) {
- // We've already locked things, so we can't have lost the startup race,
- // but something doesn't like us.
- LOG(ERROR) << "Failed to create symlinks.";
- if (!socket_dir_.Delete())
- LOG(ERROR) << "Encountered a problem when deleting socket directory.";
- return false;
- }
-
- SetupSocket(socket_target_path.value(), &sock, &addr);
-
- if (bind(sock, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) < 0) {
- PLOG(ERROR) << "Failed to bind() " << socket_target_path.value();
- CloseSocket(sock);
- return false;
- }
-
- if (listen(sock, 5) < 0)
- NOTREACHED() << "listen failed: " << safe_strerror(errno);
-
- notification_callback_ = notification_callback;
-
- DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO));
- BrowserThread::PostTask(
- BrowserThread::IO,
- FROM_HERE,
- base::Bind(&ProcessSingleton::LinuxWatcher::StartListening,
- watcher_.get(),
- sock));
-
- return true;
-}
-
-void ProcessSingleton::Cleanup() {
- UnlinkPath(socket_path_);
- UnlinkPath(cookie_path_);
- UnlinkPath(lock_path_);
-}
-
bool ProcessSingleton::IsSameChromeInstance(pid_t pid) {
pid_t cur_pid = current_pid_;
while (pid != cur_pid) {

Powered by Google App Engine
This is Rietveld 408576698