Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / common / service_process_util_posix.h
blob16031e6d61198f83c1370ebf57a74ffaf7fb2b63
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"
10 #include <signal.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);
20 #endif
22 #if defined(OS_MACOSX)
23 #include "base/files/file_path_watcher.h"
24 #include "base/mac/scoped_cftyperef.h"
26 namespace base {
27 class CommandLine;
30 CFDictionaryRef CreateServiceProcessLaunchdPlist(base::CommandLine* cmd_line,
31 bool for_auto_launch);
32 #endif // OS_MACOSX
34 namespace base {
35 class WaitableEvent;
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 {
42 public:
44 enum {
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;
55 private:
56 base::Closure terminate_task_;
59 struct ServiceProcessState::StateData
60 : public base::RefCountedThreadSafe<ServiceProcessState::StateData> {
61 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;
72 #endif // OS_MACOSX
73 #if defined(OS_POSIX) && !defined(OS_MACOSX)
74 scoped_ptr<MultiProcessLock> initializing_lock;
75 scoped_ptr<MultiProcessLock> running_lock;
76 #endif
77 scoped_ptr<ServiceProcessTerminateMonitor> terminate_monitor;
78 base::MessageLoopForIO::FileDescriptorWatcher watcher;
79 int sockets[2];
80 struct sigaction old_action;
81 bool set_action;
83 protected:
84 friend class base::RefCountedThreadSafe<ServiceProcessState::StateData>;
85 virtual ~StateData();
88 #endif // CHROME_COMMON_SERVICE_PROCESS_UTIL_POSIX_H_