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