Fix a leak in wm::AnimateOnChildWindowVisibilityChanged().
[chromium-blink-merge.git] / chrome / common / service_process_util_posix.h
blobc1d02b926eea802e3313ee0b3ca25a455a4a88f8
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 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 virtual ~ServiceProcessTerminateMonitor();
51 // MessageLoopForIO::Watcher overrides
52 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
53 virtual 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);
68 // TODO(jhawkins): Either make this a class or rename these public member
69 // variables to remove the trailing underscore.
71 #if defined(OS_MACOSX)
72 bool WatchExecutable();
74 base::ScopedCFTypeRef<CFDictionaryRef> launchd_conf_;
75 base::FilePathWatcher executable_watcher_;
76 #endif // OS_MACOSX
77 #if defined(OS_POSIX) && !defined(OS_MACOSX)
78 scoped_ptr<MultiProcessLock> initializing_lock_;
79 scoped_ptr<MultiProcessLock> running_lock_;
80 #endif
81 scoped_ptr<ServiceProcessTerminateMonitor> terminate_monitor_;
82 base::MessageLoopForIO::FileDescriptorWatcher watcher_;
83 int sockets_[2];
84 struct sigaction old_action_;
85 bool set_action_;
87 protected:
88 friend class base::RefCountedThreadSafe<ServiceProcessState::StateData>;
89 virtual ~StateData();
92 #endif // CHROME_COMMON_SERVICE_PROCESS_UTIL_POSIX_H_