1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_COMMON_SERVICE_PROCESS_UTIL_POSIX_H_
6 #define CHROME_COMMON_SERVICE_PROCESS_UTIL_POSIX_H_
8 #include "chrome/common/service_process_util.h"
12 #include "base/basictypes.h"
13 #include "base/callback.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop.h"
17 #if defined(OS_POSIX) && !defined(OS_MACOSX)
18 #include "chrome/common/multi_process_lock.h"
19 MultiProcessLock
* TakeServiceRunningLock(bool waiting
);
22 #if defined(OS_MACOSX)
23 #include "base/files/file_path_watcher.h"
24 #include "base/mac/scoped_cftyperef.h"
30 CFDictionaryRef
CreateServiceProcessLaunchdPlist(base::CommandLine
* cmd_line
,
31 bool for_auto_launch
);
38 // Watches for |kTerminateMessage| to be written to the file descriptor it is
39 // watching. When it reads |kTerminateMessage|, it performs |terminate_task_|.
40 // Used here to monitor the socket listening to g_signal_socket.
41 class ServiceProcessTerminateMonitor
: public base::MessageLoopForIO::Watcher
{
45 kTerminateMessage
= 0xdecea5e
48 explicit ServiceProcessTerminateMonitor(const base::Closure
& terminate_task
);
49 ~ServiceProcessTerminateMonitor() override
;
51 // MessageLoopForIO::Watcher overrides
52 void OnFileCanReadWithoutBlocking(int fd
) override
;
53 void OnFileCanWriteWithoutBlocking(int fd
) override
;
56 base::Closure terminate_task_
;
59 struct ServiceProcessState::StateData
60 : public base::RefCountedThreadSafe
<ServiceProcessState::StateData
> {
63 // WatchFileDescriptor needs to be set up by the thread that is going
64 // to be monitoring it.
65 void SignalReady(base::WaitableEvent
* signal
, bool* success
);
67 #if defined(OS_MACOSX)
68 bool WatchExecutable();
70 base::ScopedCFTypeRef
<CFDictionaryRef
> launchd_conf
;
71 base::FilePathWatcher executable_watcher
;
73 #if defined(OS_POSIX) && !defined(OS_MACOSX)
74 scoped_ptr
<MultiProcessLock
> initializing_lock
;
75 scoped_ptr
<MultiProcessLock
> running_lock
;
77 scoped_ptr
<ServiceProcessTerminateMonitor
> terminate_monitor
;
78 base::MessageLoopForIO::FileDescriptorWatcher watcher
;
80 struct sigaction old_action
;
84 friend class base::RefCountedThreadSafe
<ServiceProcessState::StateData
>;
88 #endif // CHROME_COMMON_SERVICE_PROCESS_UTIL_POSIX_H_