| 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/shared_memory.h" |
| 10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 11 #include "base/process/kill.h" | 12 #include "base/process/kill.h" |
| 12 #include "base/process/launch.h" | 13 #include "base/process/launch.h" |
| 13 #include "base/process/process.h" | 14 #include "base/process/process.h" |
| 14 #include "base/threading/non_thread_safe.h" | 15 #include "base/threading/non_thread_safe.h" |
| 15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 16 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 19 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
| 19 #include "mojo/edk/embedder/embedder.h" | 20 #include "mojo/edk/embedder/embedder.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // ready. Deleting this object before the process is created is safe, since | 70 // ready. Deleting this object before the process is created is safe, since |
| 70 // the callback won't be called. If the process is still running by the time | 71 // the callback won't be called. If the process is still running by the time |
| 71 // this object destructs, it will be terminated. | 72 // this object destructs, it will be terminated. |
| 72 // Takes ownership of cmd_line. | 73 // Takes ownership of cmd_line. |
| 73 // | 74 // |
| 74 // If |process_error_callback| is provided, it will be called if a Mojo error | 75 // If |process_error_callback| is provided, it will be called if a Mojo error |
| 75 // is encountered when processing messages from the child process. This | 76 // is encountered when processing messages from the child process. This |
| 76 // callback must be safe to call from any thread. | 77 // callback must be safe to call from any thread. |
| 77 ChildProcessLauncher( | 78 ChildProcessLauncher( |
| 78 SandboxedProcessLauncherDelegate* delegate, | 79 SandboxedProcessLauncherDelegate* delegate, |
| 80 base::SharedMemory* field_trial_state, |
| 79 base::CommandLine* cmd_line, | 81 base::CommandLine* cmd_line, |
| 80 int child_process_id, | 82 int child_process_id, |
| 81 Client* client, | 83 Client* client, |
| 82 const std::string& mojo_child_token, | 84 const std::string& mojo_child_token, |
| 83 const mojo::edk::ProcessErrorCallback& process_error_callback, | 85 const mojo::edk::ProcessErrorCallback& process_error_callback, |
| 84 bool terminate_on_shutdown = true); | 86 bool terminate_on_shutdown = true); |
| 85 ~ChildProcessLauncher(); | 87 ~ChildProcessLauncher(); |
| 86 | 88 |
| 87 // True if the process is being launched and so the handle isn't available. | 89 // True if the process is being launched and so the handle isn't available. |
| 88 bool IsStarting(); | 90 bool IsStarting(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 108 // this after the process has started. | 110 // this after the process has started. |
| 109 void SetProcessBackgrounded(bool background); | 111 void SetProcessBackgrounded(bool background); |
| 110 | 112 |
| 111 // Replaces the ChildProcessLauncher::Client for testing purposes. Returns the | 113 // Replaces the ChildProcessLauncher::Client for testing purposes. Returns the |
| 112 // previous client. | 114 // previous client. |
| 113 Client* ReplaceClientForTest(Client* client); | 115 Client* ReplaceClientForTest(Client* client); |
| 114 | 116 |
| 115 private: | 117 private: |
| 116 // Posts a task to the launcher thread to do the actual work. | 118 // Posts a task to the launcher thread to do the actual work. |
| 117 void Launch(SandboxedProcessLauncherDelegate* delegate, | 119 void Launch(SandboxedProcessLauncherDelegate* delegate, |
| 120 base::SharedMemory* field_trial_state, |
| 118 base::CommandLine* cmd_line, | 121 base::CommandLine* cmd_line, |
| 119 int child_process_id); | 122 int child_process_id); |
| 120 | 123 |
| 121 void UpdateTerminationStatus(bool known_dead); | 124 void UpdateTerminationStatus(bool known_dead); |
| 122 | 125 |
| 123 // This is always called on the client thread after an attempt | 126 // This is always called on the client thread after an attempt |
| 124 // to launch the child process on the launcher thread. | 127 // to launch the child process on the launcher thread. |
| 125 // It makes sure we always perform the necessary cleanup if the | 128 // It makes sure we always perform the necessary cleanup if the |
| 126 // client went away. | 129 // client went away. |
| 127 static void DidLaunch(base::WeakPtr<ChildProcessLauncher> instance, | 130 static void DidLaunch(base::WeakPtr<ChildProcessLauncher> instance, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 const std::string mojo_child_token_; | 163 const std::string mojo_child_token_; |
| 161 | 164 |
| 162 base::WeakPtrFactory<ChildProcessLauncher> weak_factory_; | 165 base::WeakPtrFactory<ChildProcessLauncher> weak_factory_; |
| 163 | 166 |
| 164 DISALLOW_COPY_AND_ASSIGN(ChildProcessLauncher); | 167 DISALLOW_COPY_AND_ASSIGN(ChildProcessLauncher); |
| 165 }; | 168 }; |
| 166 | 169 |
| 167 } // namespace content | 170 } // namespace content |
| 168 | 171 |
| 169 #endif // CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_ | 172 #endif // CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_ |
| OLD | NEW |