OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 SANDBOX_LINUX_SERVICES_SCOPED_PROCESS_H_ | 5 #ifndef SANDBOX_LINUX_SERVICES_SCOPED_PROCESS_H_ |
6 #define SANDBOX_LINUX_SERVICES_SCOPED_PROCESS_H_ | 6 #define SANDBOX_LINUX_SERVICES_SCOPED_PROCESS_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
| 11 #include "sandbox/linux/sandbox_export.h" |
11 | 12 |
12 namespace sandbox { | 13 namespace sandbox { |
13 | 14 |
14 // fork() a child process that will run a Closure. | 15 // fork() a child process that will run a Closure. |
15 // After the Closure has run, the child will pause forever. If this object | 16 // After the Closure has run, the child will pause forever. If this object |
16 // is detroyed, the child will be destroyed, even if the closure did not | 17 // is detroyed, the child will be destroyed, even if the closure did not |
17 // finish running. It's ok to signal the child from outside of this class to | 18 // finish running. It's ok to signal the child from outside of this class to |
18 // destroy it. | 19 // destroy it. |
19 // This class cannot be instanciated from a multi-threaded process, as it needs | 20 // This class cannot be instanciated from a multi-threaded process, as it needs |
20 // to fork(). | 21 // to fork(). |
21 class ScopedProcess { | 22 class SANDBOX_EXPORT ScopedProcess { |
22 public: | 23 public: |
23 // A new process will be created and |child_callback| will run in the child | 24 // A new process will be created and |child_callback| will run in the child |
24 // process. This callback is allowed to terminate the process or to simply | 25 // process. This callback is allowed to terminate the process or to simply |
25 // return. If the callback returns, the process will wait forever. | 26 // return. If the callback returns, the process will wait forever. |
26 explicit ScopedProcess(const base::Closure& child_callback); | 27 explicit ScopedProcess(const base::Closure& child_callback); |
27 ~ScopedProcess(); | 28 ~ScopedProcess(); |
28 | 29 |
29 // Wait for the process to exit. | 30 // Wait for the process to exit. |
30 // |got_signaled| tells how to interpret the return value: either as an exit | 31 // |got_signaled| tells how to interpret the return value: either as an exit |
31 // code, or as a signal number. | 32 // code, or as a signal number. |
(...skipping 13 matching lines...) Expand all Loading... |
45 | 46 |
46 base::ProcessId child_process_id_; | 47 base::ProcessId child_process_id_; |
47 base::ProcessId process_id_; | 48 base::ProcessId process_id_; |
48 int pipe_fds_[2]; | 49 int pipe_fds_[2]; |
49 DISALLOW_COPY_AND_ASSIGN(ScopedProcess); | 50 DISALLOW_COPY_AND_ASSIGN(ScopedProcess); |
50 }; | 51 }; |
51 | 52 |
52 } // namespace sandbox | 53 } // namespace sandbox |
53 | 54 |
54 #endif // SANDBOX_LINUX_SERVICES_SCOPED_PROCESS_H_ | 55 #endif // SANDBOX_LINUX_SERVICES_SCOPED_PROCESS_H_ |
OLD | NEW |