Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / common / service_process_util_posix.h
blob2e03e4652d3cd15b0aa9f6f76faabf649022e2c7
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 "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 class CommandLine;
27 CFDictionaryRef CreateServiceProcessLaunchdPlist(CommandLine* cmd_line,
28 bool for_auto_launch);
29 #endif // OS_MACOSX
31 namespace base {
32 class WaitableEvent;
35 // Watches for |kTerminateMessage| to be written to the file descriptor it is
36 // watching. When it reads |kTerminateMessage|, it performs |terminate_task_|.
37 // Used here to monitor the socket listening to g_signal_socket.
38 class ServiceProcessTerminateMonitor : public base::MessageLoopForIO::Watcher {
39 public:
41 enum {
42 kTerminateMessage = 0xdecea5e
45 explicit ServiceProcessTerminateMonitor(const base::Closure& terminate_task);
46 virtual ~ServiceProcessTerminateMonitor();
48 // MessageLoopForIO::Watcher overrides
49 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
50 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
52 private:
53 base::Closure terminate_task_;
56 struct ServiceProcessState::StateData
57 : public base::RefCountedThreadSafe<ServiceProcessState::StateData> {
58 StateData();
60 // WatchFileDescriptor needs to be set up by the thread that is going
61 // to be monitoring it.
62 void SignalReady(base::WaitableEvent* signal, bool* success);
65 // TODO(jhawkins): Either make this a class or rename these public member
66 // variables to remove the trailing underscore.
68 #if defined(OS_MACOSX)
69 bool WatchExecutable();
71 base::ScopedCFTypeRef<CFDictionaryRef> launchd_conf_;
72 base::FilePathWatcher executable_watcher_;
73 #endif // OS_MACOSX
74 #if defined(OS_POSIX) && !defined(OS_MACOSX)
75 scoped_ptr<MultiProcessLock> initializing_lock_;
76 scoped_ptr<MultiProcessLock> running_lock_;
77 #endif
78 scoped_ptr<ServiceProcessTerminateMonitor> terminate_monitor_;
79 base::MessageLoopForIO::FileDescriptorWatcher watcher_;
80 int sockets_[2];
81 struct sigaction old_action_;
82 bool set_action_;
84 protected:
85 friend class base::RefCountedThreadSafe<ServiceProcessState::StateData>;
86 virtual ~StateData();
89 #endif // CHROME_COMMON_SERVICE_PROCESS_UTIL_POSIX_H_