OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_HELPER_H_ | 5 #ifndef CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_HELPER_H_ |
6 #define CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_HELPER_H_ | 6 #define CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_HELPER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/process/kill.h" | 12 #include "base/process/kill.h" |
13 #include "base/process/process.h" | 13 #include "base/process/process.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/common/result_codes.h" | 16 #include "content/public/common/result_codes.h" |
17 #include "mojo/edk/embedder/embedder.h" | 17 #include "mojo/edk/embedder/embedder.h" |
| 18 #include "mojo/edk/embedder/pending_process_connection.h" |
18 #include "mojo/edk/embedder/scoped_platform_handle.h" | 19 #include "mojo/edk/embedder/scoped_platform_handle.h" |
19 | 20 |
20 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
21 #include "sandbox/win/src/sandbox_types.h" | 22 #include "sandbox/win/src/sandbox_types.h" |
22 #else | 23 #else |
23 #include "content/public/browser/file_descriptor_info.h" | 24 #include "content/public/browser/file_descriptor_info.h" |
24 #endif | 25 #endif |
25 | 26 |
26 #if defined(OS_LINUX) | 27 #if defined(OS_LINUX) |
27 #include "content/public/common/zygote_handle.h" | 28 #include "content/public/common/zygote_handle.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 #if defined(OS_LINUX) | 67 #if defined(OS_LINUX) |
67 ZygoteHandle zygote = nullptr; | 68 ZygoteHandle zygote = nullptr; |
68 #endif | 69 #endif |
69 }; | 70 }; |
70 | 71 |
71 ChildProcessLauncherHelper( | 72 ChildProcessLauncherHelper( |
72 int child_process_id, | 73 int child_process_id, |
73 BrowserThread::ID client_thread_id, | 74 BrowserThread::ID client_thread_id, |
74 std::unique_ptr<base::CommandLine> command_line, | 75 std::unique_ptr<base::CommandLine> command_line, |
75 std::unique_ptr<SandboxedProcessLauncherDelegate> delegate, | 76 std::unique_ptr<SandboxedProcessLauncherDelegate> delegate, |
| 77 std::unique_ptr<mojo::edk::PendingProcessConnection> pending_connection, |
| 78 const mojo::edk::ProcessErrorCallback& process_error_callback, |
76 const base::WeakPtr<ChildProcessLauncher>& child_process_launcher, | 79 const base::WeakPtr<ChildProcessLauncher>& child_process_launcher, |
77 bool terminate_on_shutdown); | 80 bool terminate_on_shutdown); |
78 | 81 |
79 // The methods below are defined in the order they are called. | 82 // The methods below are defined in the order they are called. |
80 | 83 |
81 // Starts the flow of launching the process. | 84 // Starts the flow of launching the process. |
82 void StartLaunchOnClientThread(); | 85 void StartLaunchOnClientThread(); |
83 | 86 |
84 // Platform specific. | 87 // Platform specific. |
85 void BeforeLaunchOnClientThread(); | 88 void BeforeLaunchOnClientThread(); |
86 | 89 |
87 // Called in to give implementors a chance at creating a server pipe. | 90 // Called in to give implementors a chance at creating a server pipe. |
88 // Platform specific. | 91 // Platform specific. |
89 mojo::edk::ScopedPlatformHandle PrepareMojoPipeHandlesOnClientThread(); | 92 mojo::edk::ScopedPlatformHandle PrepareMojoPipeHandlesOnClientThread(); |
90 | 93 |
91 // Returns the list of files that should be mapped in the child process. | 94 // Returns the list of files that should be mapped in the child process. |
92 // Platform specific. | 95 // Platform specific. |
93 std::unique_ptr<FileMappedForLaunch> GetFilesToMap(); | 96 std::unique_ptr<FileMappedForLaunch> GetFilesToMap(); |
94 | 97 |
95 // Platform specific. | 98 // Platform specific. |
96 void BeforeLaunchOnLauncherThread( | 99 void BeforeLaunchOnLauncherThread( |
97 const FileMappedForLaunch& files_to_register, | 100 const FileMappedForLaunch& files_to_register, |
98 base::LaunchOptions* options); | 101 base::LaunchOptions* options); |
99 | 102 |
100 // Does the actual starting of the process. | 103 // Does the actual starting of the process. |
101 // |is_synchronous_launch| is set to false if the starting of the process is | 104 // |is_synchronous_launch| is set to false if the starting of the process is |
102 // asynchonous (this is the case on Android), in which case the returned | 105 // asynchonous (this is the case on Android), in which case the returned |
103 // Process is not valid (and PostLaunchOnLauncherThread() will provide the | 106 // Process is not valid (and PostLaunchOnLauncherThread() will provide the |
104 // process once it is available). | 107 // process once it is available). Iff |is_synchronous_launch| is set to false, |
| 108 // the implementation must also take ownership of |*pending_connection| and |
| 109 // |*server_handle| to eventually pass them on to |
| 110 // PostLaunchOnLauncherThread(). |
105 // Platform specific. | 111 // Platform specific. |
106 ChildProcessLauncherHelper::Process LaunchProcessOnLauncherThread( | 112 ChildProcessLauncherHelper::Process LaunchProcessOnLauncherThread( |
107 const base::LaunchOptions& options, | 113 const base::LaunchOptions& options, |
108 std::unique_ptr<FileMappedForLaunch> files_to_register, | 114 std::unique_ptr<FileMappedForLaunch> files_to_register, |
109 bool* is_synchronous_launch, | 115 bool* is_synchronous_launch, |
110 int* launch_result); | 116 int* launch_result, |
| 117 std::unique_ptr<mojo::edk::PendingProcessConnection>* pending_connection, |
| 118 mojo::edk::ScopedPlatformHandle* server_handle); |
111 | 119 |
112 // Called right after the process has been launched, whether it was created | 120 // Called right after the process has been launched, whether it was created |
113 // yet or not. | 121 // yet or not. |
114 // Platform specific. | 122 // Platform specific. |
115 void AfterLaunchOnLauncherThread( | 123 void AfterLaunchOnLauncherThread( |
116 const ChildProcessLauncherHelper::Process& process, | 124 const ChildProcessLauncherHelper::Process& process, |
117 const base::LaunchOptions& options); | 125 const base::LaunchOptions& options); |
118 | 126 |
119 // Called once the process has been created, successfully or not. | 127 // Called once the process has been created, successfully or not. |
120 // If |post_launch_on_client_thread_called| is false, | 128 // If |post_launch_on_client_thread_called| is false, |
121 // this calls PostLaunchOnClientThread on the client thread. | 129 // this calls PostLaunchOnClientThread on the client thread. |
122 void PostLaunchOnLauncherThread(ChildProcessLauncherHelper::Process process, | 130 void PostLaunchOnLauncherThread( |
123 int launch_result, | 131 ChildProcessLauncherHelper::Process process, |
124 bool post_launch_on_client_thread_called); | 132 int launch_result, |
| 133 bool post_launch_on_client_thread_called, |
| 134 std::unique_ptr<mojo::edk::PendingProcessConnection> pending_connection, |
| 135 mojo::edk::ScopedPlatformHandle server_handle); |
125 | 136 |
126 // Note that this could be called before PostLaunchOnLauncherThread() is | 137 // Note that this could be called before PostLaunchOnLauncherThread() is |
127 // called. | 138 // called. |
128 void PostLaunchOnClientThread(ChildProcessLauncherHelper::Process process, | 139 void PostLaunchOnClientThread(ChildProcessLauncherHelper::Process process, |
129 int error_code); | 140 int error_code); |
130 | 141 |
131 int client_thread_id() const { return client_thread_id_; } | 142 int client_thread_id() const { return client_thread_id_; } |
132 | 143 |
133 // Returns the termination status and sets |exit_code| if non null. | 144 // Returns the termination status and sets |exit_code| if non null. |
134 // See ChildProcessLauncher::GetChildTerminationStatus for more info. | 145 // See ChildProcessLauncher::GetChildTerminationStatus for more info. |
(...skipping 18 matching lines...) Expand all Loading... |
153 ChildProcessLauncherHelper::Process process); | 164 ChildProcessLauncherHelper::Process process); |
154 | 165 |
155 static void SetProcessBackgroundedOnLauncherThread( | 166 static void SetProcessBackgroundedOnLauncherThread( |
156 base::Process process, bool background); | 167 base::Process process, bool background); |
157 | 168 |
158 private: | 169 private: |
159 friend class base::RefCountedThreadSafe<ChildProcessLauncherHelper>; | 170 friend class base::RefCountedThreadSafe<ChildProcessLauncherHelper>; |
160 | 171 |
161 ~ChildProcessLauncherHelper(); | 172 ~ChildProcessLauncherHelper(); |
162 | 173 |
163 void LaunchOnLauncherThread(); | 174 void LaunchOnLauncherThread( |
| 175 std::unique_ptr<mojo::edk::PendingProcessConnection> pending_connection, |
| 176 mojo::edk::ScopedPlatformHandle server_handle); |
164 | 177 |
165 const mojo::edk::PlatformHandle& mojo_client_handle() const { | 178 const mojo::edk::PlatformHandle& mojo_client_handle() const { |
166 return mojo_client_handle_.get(); | 179 return mojo_client_handle_.get(); |
167 } | 180 } |
168 base::CommandLine* command_line() { return command_line_.get(); } | 181 base::CommandLine* command_line() { return command_line_.get(); } |
169 int child_process_id() const { return child_process_id_; } | 182 int child_process_id() const { return child_process_id_; } |
170 | 183 |
171 std::string GetProcessType(); | 184 std::string GetProcessType(); |
172 | 185 |
173 static void ForceNormalProcessTerminationSync( | 186 static void ForceNormalProcessTerminationSync( |
174 ChildProcessLauncherHelper::Process process); | 187 ChildProcessLauncherHelper::Process process); |
175 | 188 |
176 const int child_process_id_; | 189 const int child_process_id_; |
177 const BrowserThread::ID client_thread_id_; | 190 const BrowserThread::ID client_thread_id_; |
178 base::TimeTicks begin_launch_time_; | 191 base::TimeTicks begin_launch_time_; |
179 std::unique_ptr<base::CommandLine> command_line_; | 192 std::unique_ptr<base::CommandLine> command_line_; |
180 std::unique_ptr<SandboxedProcessLauncherDelegate> delegate_; | 193 std::unique_ptr<SandboxedProcessLauncherDelegate> delegate_; |
| 194 std::unique_ptr<mojo::edk::PendingProcessConnection> pending_connection_; |
| 195 const mojo::edk::ProcessErrorCallback process_error_callback_; |
181 base::WeakPtr<ChildProcessLauncher> child_process_launcher_; | 196 base::WeakPtr<ChildProcessLauncher> child_process_launcher_; |
182 mojo::edk::ScopedPlatformHandle mojo_client_handle_; | 197 mojo::edk::ScopedPlatformHandle mojo_client_handle_; |
183 mojo::edk::ScopedPlatformHandle mojo_server_handle_; | |
184 bool terminate_on_shutdown_; | 198 bool terminate_on_shutdown_; |
185 }; | 199 }; |
186 | 200 |
187 } // namespace internal | 201 } // namespace internal |
188 | 202 |
189 } // namespace content | 203 } // namespace content |
190 | 204 |
191 #endif // CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_HELPER_H_ | 205 #endif // CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_HELPER_H_ |
OLD | NEW |