| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 MOJO_SHELL_RUNNER_HOST_CHILD_PROCESS_HOST_H_ | 5 #ifndef MOJO_SHELL_RUNNER_HOST_CHILD_PROCESS_HOST_H_ |
| 6 #define MOJO_SHELL_RUNNER_HOST_CHILD_PROCESS_HOST_H_ | 6 #define MOJO_SHELL_RUNNER_HOST_CHILD_PROCESS_HOST_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/command_line.h" |
| 13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 17 #include "base/process/process.h" | 19 #include "base/process/process.h" |
| 18 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
| 19 #include "base/synchronization/waitable_event.h" | 21 #include "base/synchronization/waitable_event.h" |
| 20 #include "mojo/edk/embedder/platform_channel_pair.h" | 22 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 21 #include "mojo/public/cpp/system/message_pipe.h" | 23 #include "mojo/public/cpp/system/message_pipe.h" |
| 22 #include "mojo/shell/public/cpp/identity.h" | 24 #include "mojo/shell/public/cpp/identity.h" |
| 23 #include "mojo/shell/public/interfaces/shell_client_factory.mojom.h" | 25 #include "mojo/shell/public/interfaces/shell_client_factory.mojom.h" |
| 24 #include "mojo/shell/runner/host/child_process_host.h" | 26 #include "mojo/shell/runner/host/child_process_host.h" |
| 25 | 27 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 52 // mojo application we wish to start. | 54 // mojo application we wish to start. |
| 53 ChildProcessHost(base::TaskRunner* launch_process_runner, | 55 ChildProcessHost(base::TaskRunner* launch_process_runner, |
| 54 NativeRunnerDelegate* delegate, | 56 NativeRunnerDelegate* delegate, |
| 55 bool start_sandboxed, | 57 bool start_sandboxed, |
| 56 const Identity& target, | 58 const Identity& target, |
| 57 const base::FilePath& app_path); | 59 const base::FilePath& app_path); |
| 58 virtual ~ChildProcessHost(); | 60 virtual ~ChildProcessHost(); |
| 59 | 61 |
| 60 // |Start()|s the child process; calls |DidStart()| (on the thread on which | 62 // |Start()|s the child process; calls |DidStart()| (on the thread on which |
| 61 // |Start()| was called) when the child has been started (or failed to start). | 63 // |Start()| was called) when the child has been started (or failed to start). |
| 62 void Start(mojom::ShellClientRequest request, | 64 mojom::ShellClientPtr Start(const String& name, |
| 63 const String& name, | 65 const ProcessReadyCallback& callback, |
| 64 const ProcessReadyCallback& callback, | 66 const base::Closure& quit_closure); |
| 65 const base::Closure& quit_closure); | |
| 66 | 67 |
| 67 // Waits for the child process to terminate. | 68 // Waits for the child process to terminate. |
| 68 void Join(); | 69 void Join(); |
| 69 | 70 |
| 70 protected: | 71 protected: |
| 71 void DidStart(const ProcessReadyCallback& callback); | 72 void DidStart(const ProcessReadyCallback& callback); |
| 72 | 73 |
| 73 private: | 74 private: |
| 74 void DoLaunch(); | 75 void DoLaunch(scoped_ptr<base::CommandLine> child_command_line); |
| 75 | 76 |
| 76 scoped_refptr<base::TaskRunner> launch_process_runner_; | 77 scoped_refptr<base::TaskRunner> launch_process_runner_; |
| 77 NativeRunnerDelegate* delegate_ = nullptr; | 78 NativeRunnerDelegate* delegate_ = nullptr; |
| 78 bool start_sandboxed_ = false; | 79 bool start_sandboxed_ = false; |
| 79 Identity target_; | 80 Identity target_; |
| 80 const base::FilePath app_path_; | 81 const base::FilePath app_path_; |
| 81 base::Process child_process_; | 82 base::Process child_process_; |
| 82 // Used for the ShellClientFactory binding. | 83 |
| 83 edk::PlatformChannelPair platform_channel_pair_; | 84 // Used to initialize the Mojo IPC channel between parent and child. |
| 84 mojom::ShellClientFactoryPtr factory_; | 85 scoped_ptr<edk::PlatformChannelPair> mojo_ipc_channel_; |
| 85 edk::HandlePassingInformation handle_passing_info_; | 86 edk::HandlePassingInformation handle_passing_info_; |
| 86 | 87 |
| 87 // Used to back the NodeChannel between the parent and child node. | |
| 88 scoped_ptr<edk::PlatformChannelPair> node_channel_; | |
| 89 | |
| 90 // Since Start() calls a method on another thread, we use an event to block | 88 // Since Start() calls a method on another thread, we use an event to block |
| 91 // the main thread if it tries to destruct |this| while launching the process. | 89 // the main thread if it tries to destruct |this| while launching the process. |
| 92 base::WaitableEvent start_child_process_event_; | 90 base::WaitableEvent start_child_process_event_; |
| 93 | 91 |
| 94 // A token the child can use to connect a primordial pipe to the host. | |
| 95 std::string primordial_pipe_token_; | |
| 96 | |
| 97 base::WeakPtrFactory<ChildProcessHost> weak_factory_; | 92 base::WeakPtrFactory<ChildProcessHost> weak_factory_; |
| 98 | 93 |
| 99 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); | 94 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); |
| 100 }; | 95 }; |
| 101 | 96 |
| 102 } // namespace shell | 97 } // namespace shell |
| 103 } // namespace mojo | 98 } // namespace mojo |
| 104 | 99 |
| 105 #endif // MOJO_SHELL_RUNNER_HOST_CHILD_PROCESS_HOST_H_ | 100 #endif // MOJO_SHELL_RUNNER_HOST_CHILD_PROCESS_HOST_H_ |
| OLD | NEW |