| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_COMMON_SERVICE_PROCESS_UTIL_POSIX_H_ | 5 #ifndef CHROME_COMMON_SERVICE_PROCESS_UTIL_POSIX_H_ |
| 6 #define CHROME_COMMON_SERVICE_PROCESS_UTIL_POSIX_H_ | 6 #define CHROME_COMMON_SERVICE_PROCESS_UTIL_POSIX_H_ |
| 7 | 7 |
| 8 #include "service_process_util.h" | 8 #include "service_process_util.h" |
| 9 | 9 |
| 10 #include <signal.h> | 10 #include <signal.h> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 class CommandLine; | 25 class CommandLine; |
| 26 CFDictionaryRef CreateServiceProcessLaunchdPlist(CommandLine* cmd_line, | 26 CFDictionaryRef CreateServiceProcessLaunchdPlist(CommandLine* cmd_line, |
| 27 bool for_auto_launch); | 27 bool for_auto_launch); |
| 28 #endif // OS_MACOSX | 28 #endif // OS_MACOSX |
| 29 | 29 |
| 30 namespace base { | 30 namespace base { |
| 31 class WaitableEvent; | 31 class WaitableEvent; |
| 32 } | 32 } |
| 33 | 33 |
| 34 // Watches for |kShutDownMessage| to be written to the file descriptor it is | 34 // Watches for |kTerminateMessage| to be written to the file descriptor it is |
| 35 // watching. When it reads |kShutDownMessage|, it performs |shutdown_task_|. | 35 // watching. When it reads |kTerminateMessage|, it performs |terminate_task_|. |
| 36 // Used here to monitor the socket listening to g_signal_socket. | 36 // Used here to monitor the socket listening to g_signal_socket. |
| 37 class ServiceProcessShutdownMonitor | 37 class ServiceProcessTerminateMonitor |
| 38 : public MessageLoopForIO::Watcher { | 38 : public MessageLoopForIO::Watcher { |
| 39 public: | 39 public: |
| 40 | 40 |
| 41 enum { | 41 enum { |
| 42 kShutDownMessage = 0xdecea5e | 42 kTerminateMessage = 0xdecea5e |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 explicit ServiceProcessShutdownMonitor(Task* shutdown_task); | 45 explicit ServiceProcessTerminateMonitor(Task* terminate_task); |
| 46 virtual ~ServiceProcessShutdownMonitor(); | 46 virtual ~ServiceProcessTerminateMonitor(); |
| 47 | 47 |
| 48 // MessageLoopForIO::Watcher overrides | 48 // MessageLoopForIO::Watcher overrides |
| 49 virtual void OnFileCanReadWithoutBlocking(int fd); | 49 virtual void OnFileCanReadWithoutBlocking(int fd); |
| 50 virtual void OnFileCanWriteWithoutBlocking(int fd); | 50 virtual void OnFileCanWriteWithoutBlocking(int fd); |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 scoped_ptr<Task> shutdown_task_; | 53 scoped_ptr<Task> terminate_task_; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 struct ServiceProcessState::StateData | 56 struct ServiceProcessState::StateData |
| 57 : public base::RefCountedThreadSafe<ServiceProcessState::StateData> { | 57 : public base::RefCountedThreadSafe<ServiceProcessState::StateData> { |
| 58 StateData(); | 58 StateData(); |
| 59 | 59 |
| 60 // WatchFileDescriptor needs to be set up by the thread that is going | 60 // WatchFileDescriptor needs to be set up by the thread that is going |
| 61 // to be monitoring it. | 61 // to be monitoring it. |
| 62 void SignalReady(base::WaitableEvent* signal, bool* success); | 62 void SignalReady(base::WaitableEvent* signal, bool* success); |
| 63 | 63 |
| 64 | 64 |
| 65 // TODO(jhawkins): Either make this a class or rename these public member | 65 // TODO(jhawkins): Either make this a class or rename these public member |
| 66 // variables to remove the trailing underscore. | 66 // variables to remove the trailing underscore. |
| 67 | 67 |
| 68 #if defined(OS_MACOSX) | 68 #if defined(OS_MACOSX) |
| 69 bool WatchExecutable(); | 69 bool WatchExecutable(); |
| 70 | 70 |
| 71 base::mac::ScopedCFTypeRef<CFDictionaryRef> launchd_conf_; | 71 base::mac::ScopedCFTypeRef<CFDictionaryRef> launchd_conf_; |
| 72 base::files::FilePathWatcher executable_watcher_; | 72 base::files::FilePathWatcher executable_watcher_; |
| 73 #endif // OS_MACOSX | 73 #endif // OS_MACOSX |
| 74 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 74 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 75 scoped_ptr<MultiProcessLock> initializing_lock_; | 75 scoped_ptr<MultiProcessLock> initializing_lock_; |
| 76 scoped_ptr<MultiProcessLock> running_lock_; | 76 scoped_ptr<MultiProcessLock> running_lock_; |
| 77 #endif | 77 #endif |
| 78 scoped_ptr<ServiceProcessShutdownMonitor> shut_down_monitor_; | 78 scoped_ptr<ServiceProcessTerminateMonitor> terminate_monitor_; |
| 79 MessageLoopForIO::FileDescriptorWatcher watcher_; | 79 MessageLoopForIO::FileDescriptorWatcher watcher_; |
| 80 int sockets_[2]; | 80 int sockets_[2]; |
| 81 struct sigaction old_action_; | 81 struct sigaction old_action_; |
| 82 bool set_action_; | 82 bool set_action_; |
| 83 | 83 |
| 84 protected: | 84 protected: |
| 85 friend class base::RefCountedThreadSafe<ServiceProcessState::StateData>; | 85 friend class base::RefCountedThreadSafe<ServiceProcessState::StateData>; |
| 86 virtual ~StateData(); | 86 virtual ~StateData(); |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 #endif // CHROME_COMMON_SERVICE_PROCESS_UTIL_POSIX_H_ | 89 #endif // CHROME_COMMON_SERVICE_PROCESS_UTIL_POSIX_H_ |
| OLD | NEW |