| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_H_ | 5 #ifndef CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_ |
| 6 #define CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_ | 6 #define CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_ |
| 7 | 7 |
| 8 #include "base/files/scoped_file.h" | 8 #include "base/files/scoped_file.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/process/kill.h" | 11 #include "base/process/kill.h" |
| 12 #include "base/process/launch.h" | 12 #include "base/process/launch.h" |
| 13 #include "base/process/process.h" | 13 #include "base/process/process.h" |
| 14 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/common/sandboxed_process_launcher_delegate.h" | |
| 19 | 18 |
| 20 namespace base { | 19 namespace base { |
| 21 class CommandLine; | 20 class CommandLine; |
| 22 } | 21 } |
| 23 | 22 |
| 24 namespace content { | 23 namespace content { |
| 24 class SandboxedProcessLauncherDelegate; |
| 25 | 25 |
| 26 // Launches a process asynchronously and notifies the client of the process | 26 // Launches a process asynchronously and notifies the client of the process |
| 27 // handle when it's available. It's used to avoid blocking the calling thread | 27 // handle when it's available. It's used to avoid blocking the calling thread |
| 28 // on the OS since often it can take > 100 ms to create the process. | 28 // on the OS since often it can take > 100 ms to create the process. |
| 29 class CONTENT_EXPORT ChildProcessLauncher : public base::NonThreadSafe { | 29 class CONTENT_EXPORT ChildProcessLauncher : public base::NonThreadSafe { |
| 30 public: | 30 public: |
| 31 class CONTENT_EXPORT Client { | 31 class CONTENT_EXPORT Client { |
| 32 public: | 32 public: |
| 33 // Will be called on the thread that the ChildProcessLauncher was | 33 // Will be called on the thread that the ChildProcessLauncher was |
| 34 // constructed on. | 34 // constructed on. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 int child_process_id); | 88 int child_process_id); |
| 89 | 89 |
| 90 void UpdateTerminationStatus(bool known_dead); | 90 void UpdateTerminationStatus(bool known_dead); |
| 91 | 91 |
| 92 // This is always called on the client thread after an attempt | 92 // This is always called on the client thread after an attempt |
| 93 // to launch the child process on the launcher thread. | 93 // to launch the child process on the launcher thread. |
| 94 // It makes sure we always perform the necessary cleanup if the | 94 // It makes sure we always perform the necessary cleanup if the |
| 95 // client went away. | 95 // client went away. |
| 96 static void DidLaunch(base::WeakPtr<ChildProcessLauncher> instance, | 96 static void DidLaunch(base::WeakPtr<ChildProcessLauncher> instance, |
| 97 bool terminate_on_shutdown, | 97 bool terminate_on_shutdown, |
| 98 ZygoteHandle zygote, | 98 bool zygote, |
| 99 #if defined(OS_ANDROID) | 99 #if defined(OS_ANDROID) |
| 100 base::ScopedFD ipcfd, | 100 base::ScopedFD ipcfd, |
| 101 #endif | 101 #endif |
| 102 base::Process process); | 102 base::Process process); |
| 103 | 103 |
| 104 // Notifies the client about the result of the operation. | 104 // Notifies the client about the result of the operation. |
| 105 void Notify(ZygoteHandle zygote, | 105 void Notify(bool zygote, |
| 106 #if defined(OS_ANDROID) | 106 #if defined(OS_ANDROID) |
| 107 base::ScopedFD ipcfd, | 107 base::ScopedFD ipcfd, |
| 108 #endif | 108 #endif |
| 109 base::Process process); | 109 base::Process process); |
| 110 | 110 |
| 111 #if defined(MOJO_SHELL_CLIENT) | 111 #if defined(MOJO_SHELL_CLIENT) |
| 112 // When this process is run from an external Mojo shell, this function will | 112 // When this process is run from an external Mojo shell, this function will |
| 113 // create a channel and pass one end to the spawned process and register the | 113 // create a channel and pass one end to the spawned process and register the |
| 114 // other end with the external shell, allowing the spawned process to bind an | 114 // other end with the external shell, allowing the spawned process to bind an |
| 115 // Application request from the shell. | 115 // Application request from the shell. |
| 116 void CreateMojoShellChannel(base::CommandLine* command_line, | 116 void CreateMojoShellChannel(base::CommandLine* command_line, |
| 117 int child_process_id); | 117 int child_process_id); |
| 118 #endif | 118 #endif |
| 119 | 119 |
| 120 Client* client_; | 120 Client* client_; |
| 121 BrowserThread::ID client_thread_id_; | 121 BrowserThread::ID client_thread_id_; |
| 122 base::Process process_; | 122 base::Process process_; |
| 123 base::TerminationStatus termination_status_; | 123 base::TerminationStatus termination_status_; |
| 124 int exit_code_; | 124 int exit_code_; |
| 125 ZygoteHandle zygote_; | 125 bool zygote_; |
| 126 bool starting_; | 126 bool starting_; |
| 127 // Controls whether the child process should be terminated on browser | 127 // Controls whether the child process should be terminated on browser |
| 128 // shutdown. Default behavior is to terminate the child. | 128 // shutdown. Default behavior is to terminate the child. |
| 129 const bool terminate_child_on_shutdown_; | 129 const bool terminate_child_on_shutdown_; |
| 130 | 130 |
| 131 base::WeakPtrFactory<ChildProcessLauncher> weak_factory_; | 131 base::WeakPtrFactory<ChildProcessLauncher> weak_factory_; |
| 132 | 132 |
| 133 DISALLOW_COPY_AND_ASSIGN(ChildProcessLauncher); | 133 DISALLOW_COPY_AND_ASSIGN(ChildProcessLauncher); |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 } // namespace content | 136 } // namespace content |
| 137 | 137 |
| 138 #endif // CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_ | 138 #endif // CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_ |
| OLD | NEW |