diff options
author | dmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-24 17:14:36 +0000 |
---|---|---|
committer | dmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-24 17:14:36 +0000 |
commit | 56f0f264ff866052ebcb24e75147cb600e6547a1 (patch) | |
tree | 8b16bded93f914cacbf3cb130fae3539ad4bb268 /chrome/common/service_process_util_posix.h | |
parent | 04a8454da64b62bfad5091efd5cf1143443283f0 (diff) | |
download | chromium_src-56f0f264ff866052ebcb24e75147cb600e6547a1.zip chromium_src-56f0f264ff866052ebcb24e75147cb600e6547a1.tar.gz chromium_src-56f0f264ff866052ebcb24e75147cb600e6547a1.tar.bz2 |
Get service process running standalone on the mac by hooking it into launchd.
BUG=NONE
TEST=BUILD
Review URL: http://codereview.chromium.org/6482016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75893 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/service_process_util_posix.h')
-rw-r--r-- | chrome/common/service_process_util_posix.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/chrome/common/service_process_util_posix.h b/chrome/common/service_process_util_posix.h new file mode 100644 index 0000000..3263fb5 --- /dev/null +++ b/chrome/common/service_process_util_posix.h @@ -0,0 +1,72 @@ +// Copyright (c) 2010 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. + +#ifndef CHROME_COMMON_SERVICE_PROCESS_UTIL_POSIX_H_ +#define CHROME_COMMON_SERVICE_PROCESS_UTIL_POSIX_H_ + +#include "service_process_util.h" + +#include <signal.h> + +#include "base/basictypes.h" +#include "base/message_loop.h" +#include "base/message_pump_libevent.h" +#include "base/scoped_ptr.h" + +#if defined(OS_LINUX) +#include "chrome/common/multi_process_lock.h" +MultiProcessLock* TakeServiceRunningLock(bool waiting); +#endif // OS_LINUX + +#if defined(OS_MACOSX) +#include "base/mac/scoped_cftyperef.h" +class CommandLine; +CFDictionaryRef CreateServiceProcessLaunchdPlist(CommandLine* cmd_line); +#endif // OS_MACOSX + +// Watches for |kShutDownMessage| to be written to the file descriptor it is +// watching. When it reads |kShutDownMessage|, it performs |shutdown_task_|. +// Used here to monitor the socket listening to g_signal_socket. +class ServiceProcessShutdownMonitor + : public base::MessagePumpLibevent::Watcher { + public: + + enum { + kShutDownMessage = 0xdecea5e + }; + + explicit ServiceProcessShutdownMonitor(Task* shutdown_task) + : shutdown_task_(shutdown_task) { + } + virtual ~ServiceProcessShutdownMonitor(); + + // base::MessagePumpLibevent::Watcher overrides + virtual void OnFileCanReadWithoutBlocking(int fd); + virtual void OnFileCanWriteWithoutBlocking(int fd); + + private: + scoped_ptr<Task> shutdown_task_; +}; + +struct ServiceProcessState::StateData + : public base::RefCountedThreadSafe<ServiceProcessState::StateData> { +#if defined(OS_MACOSX) + base::mac::ScopedCFTypeRef<CFDictionaryRef> launchd_conf_; +#endif // OS_MACOSX +#if defined(OS_LINUX) + scoped_ptr<MultiProcessLock> initializing_lock_; + scoped_ptr<MultiProcessLock> running_lock_; +#endif // OS_LINUX + scoped_ptr<ServiceProcessShutdownMonitor> shut_down_monitor_; + base::MessagePumpLibevent::FileDescriptorWatcher watcher_; + int sockets_[2]; + struct sigaction old_action_; + bool set_action_; + + // WatchFileDescriptor needs to be set up by the thread that is going + // to be monitoring it. + void SignalReady(); +}; + +#endif // CHROME_COMMON_SERVICE_PROCESS_UTIL_POSIX_H_ |