diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-18 22:04:28 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-18 22:04:28 +0000 |
commit | 19d7e9684e85feae1ecf9959baf07a94b01b1bce (patch) | |
tree | bd30e91dc44ae37bad8670b88eaca77ece65699a /chrome/browser/process_singleton_linux.cc | |
parent | 3851091de6451d26ba85318a9c36bd7f2923d2d8 (diff) | |
download | chromium_src-19d7e9684e85feae1ecf9959baf07a94b01b1bce.zip chromium_src-19d7e9684e85feae1ecf9959baf07a94b01b1bce.tar.gz chromium_src-19d7e9684e85feae1ecf9959baf07a94b01b1bce.tar.bz2 |
Implement skeletal ProcessSingleton on Linux to cut down on NOTIMPLEMENTED()s.
We now will refuse to run a second browser process if one is already running;
making the second invocation bring up new windows in the first remains left to
be implemented.
Review URL: http://codereview.chromium.org/20448
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9980 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/process_singleton_linux.cc')
-rw-r--r-- | chrome/browser/process_singleton_linux.cc | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/chrome/browser/process_singleton_linux.cc b/chrome/browser/process_singleton_linux.cc new file mode 100644 index 0000000..4ca8f17 --- /dev/null +++ b/chrome/browser/process_singleton_linux.cc @@ -0,0 +1,71 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/process_singleton.h" + +#include <errno.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> + +#include "base/logging.h" +#include "base/string_util.h" + +ProcessSingleton::ProcessSingleton(const FilePath& user_data_dir) { + socket_path_ = user_data_dir.Append("Singleton Socket"); +} + +ProcessSingleton::~ProcessSingleton() { +} + +bool ProcessSingleton::NotifyOtherProcess() { + int sock; + sockaddr_un addr; + SetupSocket(&sock, &addr); + + if (connect(sock, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) < 0 && + (errno == ENOENT || errno == ECONNREFUSED)) { + return false; // Tell the caller there's nobody to notify. + } + + // TODO(port): pass in info to the other process. + NOTIMPLEMENTED() << " don't know how to notify other process about us."; + + return true; // We did our best, so we die here. +} + +void ProcessSingleton::Create() { + int sock; + sockaddr_un addr; + SetupSocket(&sock, &addr); + + if (unlink(socket_path_.value().c_str()) < 0) + DCHECK_EQ(errno, ENOENT); + + if (bind(sock, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) < 0) + LOG(ERROR) << "bind() failed: " << strerror(errno); + + if (listen(sock, 5) < 0) + NOTREACHED() << "listen failed: " << strerror(errno); + + // TODO(port): register this socket as something we care about getting + // input on, process messages, etc. + NOTIMPLEMENTED() << " need to listen on the singleton socket."; +} + +void ProcessSingleton::HuntForZombieChromeProcesses() { + // On Windows, this examines all the chrome.exe processes to see if one + // is hung. TODO(port): should we do anything here? + NOTIMPLEMENTED(); +} + +void ProcessSingleton::SetupSocket(int* sock, struct sockaddr_un* addr) { + *sock = socket(PF_UNIX, SOCK_STREAM, 0); + if (*sock < 0) + LOG(FATAL) << "socket() failed: " << strerror(errno); + + addr->sun_family = AF_UNIX; + base::strlcpy(addr->sun_path, socket_path_.value().c_str(), + sizeof(addr->sun_path)); +} |