Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: base/process/launch.h

Issue 831363002: Add the ability to run a callback between fork and exec. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use a delegate class instead of a Closure. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/process/launch.cc » ('j') | base/process/launch_posix.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 // This file contains functions for launching subprocesses. 5 // This file contains functions for launching subprocesses.
6 6
7 #ifndef BASE_PROCESS_LAUNCH_H_ 7 #ifndef BASE_PROCESS_LAUNCH_H_
8 #define BASE_PROCESS_LAUNCH_H_ 8 #define BASE_PROCESS_LAUNCH_H_
9 9
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/base_export.h" 14 #include "base/base_export.h"
15 #include "base/basictypes.h" 15 #include "base/basictypes.h"
16 #include "base/callback.h"
16 #include "base/environment.h" 17 #include "base/environment.h"
17 #include "base/process/process.h" 18 #include "base/process/process.h"
18 #include "base/process/process_handle.h" 19 #include "base/process/process_handle.h"
19 #include "base/strings/string_piece.h" 20 #include "base/strings/string_piece.h"
20 21
21 #if defined(OS_POSIX) 22 #if defined(OS_POSIX)
22 #include "base/posix/file_descriptor_shuffle.h" 23 #include "base/posix/file_descriptor_shuffle.h"
23 #elif defined(OS_WIN) 24 #elif defined(OS_WIN)
24 #include <windows.h> 25 #include <windows.h>
25 #endif 26 #endif
26 27
27 namespace base { 28 namespace base {
28 29
29 class CommandLine; 30 class CommandLine;
30 31
31 #if defined(OS_WIN) 32 #if defined(OS_WIN)
32 typedef std::vector<HANDLE> HandlesToInheritVector; 33 typedef std::vector<HANDLE> HandlesToInheritVector;
33 #endif 34 #endif
34 // TODO(viettrungluu): Only define this on POSIX? 35 // TODO(viettrungluu): Only define this on POSIX?
35 typedef std::vector<std::pair<int, int> > FileHandleMappingVector; 36 typedef std::vector<std::pair<int, int> > FileHandleMappingVector;
36 37
37 // Options for launching a subprocess that are passed to LaunchProcess(). 38 // Options for launching a subprocess that are passed to LaunchProcess().
38 // The default constructor constructs the object with default options. 39 // The default constructor constructs the object with default options.
39 struct BASE_EXPORT LaunchOptions { 40 struct BASE_EXPORT LaunchOptions {
41 #if defined(OS_POSIX)
42 // Delegate to be run in between fork and exec in the subprocess (see
43 // pre_exec_delegate below)
44 class BASE_EXPORT PreExecDelegate {
45 public:
46 virtual ~PreExecDelegate() {}
jln (very slow on Chromium) 2015/01/07 00:40:37 Style: add trivial constructor
rickyz (no longer on Chrome) 2015/01/07 01:39:07 Done.
47
48 // Since this is to be run between fork and exec, and fork may have happened
49 // while multiple threads were running, this code needs to be async safe.
50 virtual void RunAsyncSafe() = 0;
51 };
jln (very slow on Chromium) 2015/01/07 00:40:37 Style: DISALLOW_COPY_AND_ASSIGN
rickyz (no longer on Chrome) 2015/01/07 01:39:06 Done.
52 #endif
jln (very slow on Chromium) 2015/01/07 00:40:37 style: // defined(OS_POSIX)
rickyz (no longer on Chrome) 2015/01/07 01:39:06 Done.
53
40 LaunchOptions(); 54 LaunchOptions();
41 ~LaunchOptions(); 55 ~LaunchOptions();
42 56
43 // If true, wait for the process to complete. 57 // If true, wait for the process to complete.
44 bool wait; 58 bool wait;
45 59
46 #if defined(OS_WIN) 60 #if defined(OS_WIN)
47 bool start_hidden; 61 bool start_hidden;
48 62
49 // If non-null, inherit exactly the list of handles in this vector (these 63 // If non-null, inherit exactly the list of handles in this vector (these
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 129
116 #if defined(OS_LINUX) 130 #if defined(OS_LINUX)
117 // If non-zero, start the process using clone(), using flags as provided. 131 // If non-zero, start the process using clone(), using flags as provided.
118 int clone_flags; 132 int clone_flags;
119 133
120 // By default, child processes will have the PR_SET_NO_NEW_PRIVS bit set. If 134 // By default, child processes will have the PR_SET_NO_NEW_PRIVS bit set. If
121 // true, then this bit will not be set in the new child process. 135 // true, then this bit will not be set in the new child process.
122 bool allow_new_privs; 136 bool allow_new_privs;
123 #endif // defined(OS_LINUX) 137 #endif // defined(OS_LINUX)
124 138
139 #if defined(OS_POSIX)
140 // If non-null, a delegate to be run immediately prior to executing the new
141 // program in the child process. Warning: If LaunchProcess was called in the
142 // presence of multiple threads, this essentially needs to be async-signal
jln (very slow on Chromium) 2015/01/07 00:40:37 s/this/"code running in this delegate"
rickyz (no longer on Chrome) 2015/01/07 01:39:07 Done.
143 // safe.
144 PreExecDelegate* pre_exec_delegate;
jln (very slow on Chromium) 2015/01/07 00:40:37 scoped_ptr?
mdempsky 2015/01/07 01:03:50 scoped_ptr would mean the LaunchOptions take owner
rickyz (no longer on Chrome) 2015/01/07 01:39:07 scoped_ptr doesn't work here because we make copie
mdempsky 2015/01/07 02:12:59 It seems intuitive to me that if you reuse the sam
145 #endif
146
125 #if defined(OS_CHROMEOS) 147 #if defined(OS_CHROMEOS)
126 // If non-negative, the specified file descriptor will be set as the launched 148 // If non-negative, the specified file descriptor will be set as the launched
127 // process' controlling terminal. 149 // process' controlling terminal.
128 int ctrl_terminal_fd; 150 int ctrl_terminal_fd;
129 #endif // defined(OS_CHROMEOS) 151 #endif // defined(OS_CHROMEOS)
130 152
131 #if defined(OS_MACOSX) 153 #if defined(OS_MACOSX)
132 // If this name is non-empty, the new child, after fork() but before exec(), 154 // If this name is non-empty, the new child, after fork() but before exec(),
133 // will look up this server name in the bootstrap namespace. The resulting 155 // will look up this server name in the bootstrap namespace. The resulting
134 // service port will be replaced as the bootstrap port in the child. Because 156 // service port will be replaced as the bootstrap port in the child. Because
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 void ReplaceBootstrapPort(const std::string& replacement_bootstrap_name); 285 void ReplaceBootstrapPort(const std::string& replacement_bootstrap_name);
264 #endif // defined(OS_MACOSX) 286 #endif // defined(OS_MACOSX)
265 287
266 // Creates a LaunchOptions object suitable for launching processes in a test 288 // Creates a LaunchOptions object suitable for launching processes in a test
267 // binary. This should not be called in production/released code. 289 // binary. This should not be called in production/released code.
268 BASE_EXPORT LaunchOptions LaunchOptionsForTest(); 290 BASE_EXPORT LaunchOptions LaunchOptionsForTest();
269 291
270 } // namespace base 292 } // namespace base
271 293
272 #endif // BASE_PROCESS_LAUNCH_H_ 294 #endif // BASE_PROCESS_LAUNCH_H_
OLDNEW
« no previous file with comments | « no previous file | base/process/launch.cc » ('j') | base/process/launch_posix.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698