| 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/scoped_platform_handle.h" | 18 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 19 #include "services/catalog/public/cpp/manifest_parsing_util.h" | 19 #include "services/catalog/public/cpp/manifest_parsing_util.h" |
| 20 | 20 |
| 21 #if defined(OS_ANDROID) |
| 22 #include "base/android/scoped_java_ref.h" |
| 23 #endif |
| 24 |
| 21 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
| 22 #include "sandbox/win/src/sandbox_types.h" | 26 #include "sandbox/win/src/sandbox_types.h" |
| 23 #else | 27 #else |
| 24 #include "content/public/browser/file_descriptor_info.h" | 28 #include "content/public/browser/file_descriptor_info.h" |
| 25 #endif | 29 #endif |
| 26 | 30 |
| 27 #if defined(OS_LINUX) | 31 #if defined(OS_LINUX) |
| 28 #include "content/public/common/zygote_handle.h" | 32 #include "content/public/common/zygote_handle.h" |
| 29 #endif | 33 #endif |
| 30 | 34 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 130 |
| 127 // Note that this could be called before PostLaunchOnLauncherThread() is | 131 // Note that this could be called before PostLaunchOnLauncherThread() is |
| 128 // called. | 132 // called. |
| 129 void PostLaunchOnClientThread(ChildProcessLauncherHelper::Process process, | 133 void PostLaunchOnClientThread(ChildProcessLauncherHelper::Process process, |
| 130 int error_code); | 134 int error_code); |
| 131 | 135 |
| 132 int client_thread_id() const { return client_thread_id_; } | 136 int client_thread_id() const { return client_thread_id_; } |
| 133 | 137 |
| 134 // Returns the termination status and sets |exit_code| if non null. | 138 // Returns the termination status and sets |exit_code| if non null. |
| 135 // See ChildProcessLauncher::GetChildTerminationStatus for more info. | 139 // See ChildProcessLauncher::GetChildTerminationStatus for more info. |
| 136 static base::TerminationStatus GetTerminationStatus( | 140 base::TerminationStatus GetTerminationStatus( |
| 137 const ChildProcessLauncherHelper::Process& process, | 141 const ChildProcessLauncherHelper::Process& process, |
| 138 bool known_dead, | 142 bool known_dead, |
| 139 int* exit_code); | 143 int* exit_code); |
| 140 | 144 |
| 141 // Terminates |process|. | 145 // Terminates |process|. |
| 142 // Returns true if the process was stopped, false if the process had not been | 146 // Returns true if the process was stopped, false if the process had not been |
| 143 // started yet or could not be stopped. | 147 // started yet or could not be stopped. |
| 144 // Note that |exit_code| and |wait| are not used on Android. | 148 // Note that |exit_code| and |wait| are not used on Android. |
| 145 static bool TerminateProcess(const base::Process& process, | 149 static bool TerminateProcess(const base::Process& process, |
| 146 int exit_code, | 150 int exit_code, |
| 147 bool wait); | 151 bool wait); |
| 148 | 152 |
| 149 // Terminates the process with the normal exit code and ensures it has been | 153 // Terminates the process with the normal exit code and ensures it has been |
| 150 // stopped. By returning a normal exit code this ensures UMA won't treat this | 154 // stopped. By returning a normal exit code this ensures UMA won't treat this |
| 151 // as a crash. | 155 // as a crash. |
| 152 // Returns immediately and perform the work on the launcher thread. | 156 // Returns immediately and perform the work on the launcher thread. |
| 153 static void ForceNormalProcessTerminationAsync( | 157 static void ForceNormalProcessTerminationAsync( |
| 154 ChildProcessLauncherHelper::Process process); | 158 ChildProcessLauncherHelper::Process process); |
| 155 | 159 |
| 156 static void SetProcessBackgroundedOnLauncherThread( | 160 void SetProcessBackgroundedOnLauncherThread(base::Process process, |
| 157 base::Process process, bool background); | 161 bool background); |
| 158 | 162 |
| 159 static void SetRegisteredFilesForService( | 163 static void SetRegisteredFilesForService( |
| 160 const std::string& service_name, | 164 const std::string& service_name, |
| 161 catalog::RequiredFileMap required_files); | 165 catalog::RequiredFileMap required_files); |
| 162 | 166 |
| 163 static void ResetRegisteredFilesForTesting(); | 167 static void ResetRegisteredFilesForTesting(); |
| 164 | 168 |
| 169 #if defined(OS_ANDROID) |
| 170 void OnChildProcessStarted(JNIEnv* env, |
| 171 const base::android::JavaParamRef<jobject>& obj, |
| 172 jint handle); |
| 173 #endif // OS_ANDROID |
| 174 |
| 165 private: | 175 private: |
| 166 friend class base::RefCountedThreadSafe<ChildProcessLauncherHelper>; | 176 friend class base::RefCountedThreadSafe<ChildProcessLauncherHelper>; |
| 167 | 177 |
| 168 ~ChildProcessLauncherHelper(); | 178 ~ChildProcessLauncherHelper(); |
| 169 | 179 |
| 170 void LaunchOnLauncherThread(); | 180 void LaunchOnLauncherThread(); |
| 171 | 181 |
| 172 const mojo::edk::PlatformHandle& mojo_client_handle() const { | 182 const mojo::edk::PlatformHandle& mojo_client_handle() const { |
| 173 return mojo_client_handle_.get(); | 183 return mojo_client_handle_.get(); |
| 174 } | 184 } |
| 175 base::CommandLine* command_line() { return command_line_.get(); } | 185 base::CommandLine* command_line() { return command_line_.get(); } |
| 176 int child_process_id() const { return child_process_id_; } | 186 int child_process_id() const { return child_process_id_; } |
| 177 | 187 |
| 178 std::string GetProcessType(); | 188 std::string GetProcessType(); |
| 179 | 189 |
| 180 static void ForceNormalProcessTerminationSync( | 190 static void ForceNormalProcessTerminationSync( |
| 181 ChildProcessLauncherHelper::Process process); | 191 ChildProcessLauncherHelper::Process process); |
| 182 | 192 |
| 183 const int child_process_id_; | 193 const int child_process_id_; |
| 184 const BrowserThread::ID client_thread_id_; | 194 const BrowserThread::ID client_thread_id_; |
| 185 base::TimeTicks begin_launch_time_; | 195 base::TimeTicks begin_launch_time_; |
| 186 std::unique_ptr<base::CommandLine> command_line_; | 196 std::unique_ptr<base::CommandLine> command_line_; |
| 187 std::unique_ptr<SandboxedProcessLauncherDelegate> delegate_; | 197 std::unique_ptr<SandboxedProcessLauncherDelegate> delegate_; |
| 188 base::WeakPtr<ChildProcessLauncher> child_process_launcher_; | 198 base::WeakPtr<ChildProcessLauncher> child_process_launcher_; |
| 189 mojo::edk::ScopedPlatformHandle mojo_client_handle_; | 199 mojo::edk::ScopedPlatformHandle mojo_client_handle_; |
| 190 mojo::edk::ScopedPlatformHandle mojo_server_handle_; | 200 mojo::edk::ScopedPlatformHandle mojo_server_handle_; |
| 191 bool terminate_on_shutdown_; | 201 bool terminate_on_shutdown_; |
| 202 |
| 203 #if defined(OS_ANDROID) |
| 204 base::android::ScopedJavaGlobalRef<jobject> java_peer_; |
| 205 #endif |
| 192 }; | 206 }; |
| 193 | 207 |
| 194 } // namespace internal | 208 } // namespace internal |
| 195 | 209 |
| 196 } // namespace content | 210 } // namespace content |
| 197 | 211 |
| 198 #endif // CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_HELPER_H_ | 212 #endif // CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_HELPER_H_ |
| OLD | NEW |