#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/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#if defined(OS_POSIX) && !defined(OS_MACOSX)
#include "chrome/common/multi_process_lock.h"
MultiProcessLock* TakeServiceRunningLock(bool waiting);
#endif
#if defined(OS_MACOSX)
#include "base/files/file_path_watcher.h"
#include "base/mac/scoped_cftyperef.h"
namespace base {
class CommandLine;
}
CFDictionaryRef CreateServiceProcessLaunchdPlist(base::CommandLine* cmd_line,
bool for_auto_launch);
#endif
namespace base {
class WaitableEvent;
}
class ServiceProcessTerminateMonitor : public base::MessageLoopForIO::Watcher {
public:
enum {
kTerminateMessage = 0xdecea5e
};
explicit ServiceProcessTerminateMonitor(const base::Closure& terminate_task);
virtual ~ServiceProcessTerminateMonitor();
virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
private:
base::Closure terminate_task_;
};
struct ServiceProcessState::StateData
: public base::RefCountedThreadSafe<ServiceProcessState::StateData> {
StateData();
void SignalReady(base::WaitableEvent* signal, bool* success);
#if defined(OS_MACOSX)
bool WatchExecutable();
base::ScopedCFTypeRef<CFDictionaryRef> launchd_conf_;
base::FilePathWatcher executable_watcher_;
#endif
#if defined(OS_POSIX) && !defined(OS_MACOSX)
scoped_ptr<MultiProcessLock> initializing_lock_;
scoped_ptr<MultiProcessLock> running_lock_;
#endif
scoped_ptr<ServiceProcessTerminateMonitor> terminate_monitor_;
base::MessageLoopForIO::FileDescriptorWatcher watcher_;
int sockets_[2];
struct sigaction old_action_;
bool set_action_;
protected:
friend class base::RefCountedThreadSafe<ServiceProcessState::StateData>;
virtual ~StateData();
};
#endif