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 "chrome/common/service_process_util.h" | 8 #include "chrome/common/service_process_util.h" |
9 | 9 |
10 #include <signal.h> | 10 #include <signal.h> |
11 | 11 |
12 #include <memory> | 12 #include <memory> |
13 | 13 |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/memory/ref_counted.h" | |
16 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
17 #include "base/single_thread_task_runner.h" | |
18 #include "build/build_config.h" | 16 #include "build/build_config.h" |
19 | 17 |
20 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 18 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
21 #include "chrome/common/multi_process_lock.h" | 19 #include "chrome/common/multi_process_lock.h" |
22 MultiProcessLock* TakeServiceRunningLock(bool waiting); | 20 MultiProcessLock* TakeServiceRunningLock(bool waiting); |
23 #endif | 21 #endif |
24 | 22 |
25 #if defined(OS_MACOSX) | 23 #if defined(OS_MACOSX) |
26 #include "base/files/file_path_watcher.h" | 24 #include "base/files/file_path_watcher.h" |
27 #include "base/mac/scoped_cftyperef.h" | 25 #include "base/mac/scoped_cftyperef.h" |
(...skipping 24 matching lines...) Expand all Loading... |
52 ~ServiceProcessTerminateMonitor() override; | 50 ~ServiceProcessTerminateMonitor() override; |
53 | 51 |
54 // MessageLoopForIO::Watcher overrides | 52 // MessageLoopForIO::Watcher overrides |
55 void OnFileCanReadWithoutBlocking(int fd) override; | 53 void OnFileCanReadWithoutBlocking(int fd) override; |
56 void OnFileCanWriteWithoutBlocking(int fd) override; | 54 void OnFileCanWriteWithoutBlocking(int fd) override; |
57 | 55 |
58 private: | 56 private: |
59 base::Closure terminate_task_; | 57 base::Closure terminate_task_; |
60 }; | 58 }; |
61 | 59 |
62 struct ServiceProcessState::StateData { | 60 struct ServiceProcessState::StateData |
| 61 : public base::RefCountedThreadSafe<ServiceProcessState::StateData> { |
63 StateData(); | 62 StateData(); |
64 ~StateData(); | |
65 | 63 |
66 // WatchFileDescriptor needs to be set up by the thread that is going | 64 // WatchFileDescriptor needs to be set up by the thread that is going |
67 // to be monitoring it. | 65 // to be monitoring it. |
68 void SignalReady(base::WaitableEvent* signal, bool* success); | 66 void SignalReady(base::WaitableEvent* signal, bool* success); |
69 | 67 |
70 #if defined(OS_MACOSX) | 68 #if defined(OS_MACOSX) |
71 bool WatchExecutable(); | 69 bool WatchExecutable(); |
72 | 70 |
73 base::ScopedCFTypeRef<CFDictionaryRef> launchd_conf; | 71 base::ScopedCFTypeRef<CFDictionaryRef> launchd_conf; |
74 base::FilePathWatcher executable_watcher; | 72 base::FilePathWatcher executable_watcher; |
75 #else | 73 #endif // OS_MACOSX |
| 74 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
76 std::unique_ptr<MultiProcessLock> initializing_lock; | 75 std::unique_ptr<MultiProcessLock> initializing_lock; |
77 std::unique_ptr<MultiProcessLock> running_lock; | 76 std::unique_ptr<MultiProcessLock> running_lock; |
78 #endif | 77 #endif |
79 std::unique_ptr<ServiceProcessTerminateMonitor> terminate_monitor; | 78 std::unique_ptr<ServiceProcessTerminateMonitor> terminate_monitor; |
80 base::MessageLoopForIO::FileDescriptorWatcher watcher; | 79 base::MessageLoopForIO::FileDescriptorWatcher watcher; |
81 int sockets[2]; | 80 int sockets[2]; |
82 struct sigaction old_action; | 81 struct sigaction old_action; |
83 bool set_action; | 82 bool set_action; |
84 | 83 |
85 // The SingleThreadTaskRunner on which SignalReady and the destructor are | 84 protected: |
86 // invoked. | 85 friend class base::RefCountedThreadSafe<ServiceProcessState::StateData>; |
87 scoped_refptr<base::SingleThreadTaskRunner> task_runner; | 86 virtual ~StateData(); |
88 }; | 87 }; |
89 | 88 |
90 #endif // CHROME_COMMON_SERVICE_PROCESS_UTIL_POSIX_H_ | 89 #endif // CHROME_COMMON_SERVICE_PROCESS_UTIL_POSIX_H_ |
OLD | NEW |