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/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/process/process.h" | 17 #include "base/process/process.h" |
18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
19 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
20 #include "mojo/edk/embedder/platform_channel_pair.h" | 20 #include "mojo/edk/embedder/platform_channel_pair.h" |
21 #include "mojo/public/cpp/system/message_pipe.h" | 21 #include "mojo/public/cpp/system/message_pipe.h" |
22 #include "mojo/shell/runner/child/child_controller.mojom.h" | 22 #include "mojo/shell/runner/child/child_controller.mojom.h" |
23 #include "mojo/shell/runner/host/child_process_host.h" | 23 #include "mojo/shell/runner/host/child_process_host.h" |
24 #include "third_party/mojo/src/mojo/edk/embedder/channel_info_forward.h" | |
25 #include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h" | |
26 #include "third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h" | |
27 | 24 |
28 namespace base { | 25 namespace base { |
29 class TaskRunner; | 26 class TaskRunner; |
30 } | 27 } |
31 | 28 |
32 namespace mojo { | 29 namespace mojo { |
33 namespace shell { | 30 namespace shell { |
34 | 31 |
35 // This class represents a "child process host". Handles launching and | 32 // This class represents a "child process host". Handles launching and |
36 // connecting a platform-specific "pipe" to the child, and supports joining the | 33 // connecting a platform-specific "pipe" to the child, and supports joining the |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 bool reject_pipe_ = false; | 91 bool reject_pipe_ = false; |
95 ScopedMessagePipeHandle pipe_; | 92 ScopedMessagePipeHandle pipe_; |
96 | 93 |
97 DISALLOW_COPY_AND_ASSIGN(PipeHolder); | 94 DISALLOW_COPY_AND_ASSIGN(PipeHolder); |
98 }; | 95 }; |
99 | 96 |
100 void DoLaunch(); | 97 void DoLaunch(); |
101 | 98 |
102 void AppCompleted(int32_t result); | 99 void AppCompleted(int32_t result); |
103 | 100 |
104 // Callback for |embedder::CreateChannel()|. | |
105 void DidCreateChannel(embedder::ChannelInfo* channel_info); | |
106 | |
107 // Called once |pipe_holder_| is bound to a pipe. | 101 // Called once |pipe_holder_| is bound to a pipe. |
108 void OnMessagePipeCreated(); | 102 void OnMessagePipeCreated(); |
109 | 103 |
110 // Called when the child process is launched and when the bootstrap | 104 // Called when the child process is launched and when the bootstrap |
111 // message pipe is created. Once both things have happened (which may happen | 105 // message pipe is created. Once both things have happened (which may happen |
112 // in either order), |process_ready_callback_| is invoked. | 106 // in either order), |process_ready_callback_| is invoked. |
113 void MaybeNotifyProcessReady(); | 107 void MaybeNotifyProcessReady(); |
114 | 108 |
115 // Callback used to receive the child message pipe from the ports EDK. | 109 // Callback used to receive the child message pipe from the ports EDK. |
116 // This may be called on any thread. It will always stash the pipe in | 110 // This may be called on any thread. It will always stash the pipe in |
117 // |holder|, and it will then attempt to call |callback| on | 111 // |holder|, and it will then attempt to call |callback| on |
118 // |callback_task_runner| (which may or may not still be running tasks.) | 112 // |callback_task_runner| (which may or may not still be running tasks.) |
119 static void OnParentMessagePipeCreated( | 113 static void OnParentMessagePipeCreated( |
120 scoped_refptr<PipeHolder> holder, | 114 scoped_refptr<PipeHolder> holder, |
121 scoped_refptr<base::TaskRunner> callback_task_runner, | 115 scoped_refptr<base::TaskRunner> callback_task_runner, |
122 const base::Closure& callback, | 116 const base::Closure& callback, |
123 ScopedMessagePipeHandle pipe); | 117 ScopedMessagePipeHandle pipe); |
124 | 118 |
125 scoped_refptr<base::TaskRunner> launch_process_runner_; | 119 scoped_refptr<base::TaskRunner> launch_process_runner_; |
126 bool start_sandboxed_; | 120 bool start_sandboxed_; |
127 const base::FilePath app_path_; | 121 const base::FilePath app_path_; |
128 base::Process child_process_; | 122 base::Process child_process_; |
129 // Used for the ChildController binding. | 123 // Used for the ChildController binding. |
130 embedder::PlatformChannelPair platform_channel_pair_; | 124 edk::PlatformChannelPair platform_channel_pair_; |
131 mojom::ChildControllerPtr controller_; | 125 mojom::ChildControllerPtr controller_; |
132 embedder::ChannelInfo* channel_info_; | |
133 mojom::ChildController::StartAppCallback on_app_complete_; | 126 mojom::ChildController::StartAppCallback on_app_complete_; |
134 embedder::HandlePassingInformation handle_passing_info_; | 127 edk::HandlePassingInformation handle_passing_info_; |
135 | 128 |
136 // Used only when --use-new-edk is specified. Used to back the NodeChannel | 129 // Used to back the NodeChannel between the parent and child node. |
137 // between the parent and child node. | |
138 scoped_ptr<edk::PlatformChannelPair> node_channel_; | 130 scoped_ptr<edk::PlatformChannelPair> node_channel_; |
139 | 131 |
140 // Since Start() calls a method on another thread, we use an event to block | 132 // Since Start() calls a method on another thread, we use an event to block |
141 // the main thread if it tries to destruct |this| while launching the process. | 133 // the main thread if it tries to destruct |this| while launching the process. |
142 base::WaitableEvent start_child_process_event_; | 134 base::WaitableEvent start_child_process_event_; |
143 | 135 |
144 // A token the child can use to connect a primordial pipe to the host. | 136 // A token the child can use to connect a primordial pipe to the host. |
145 std::string primordial_pipe_token_; | 137 std::string primordial_pipe_token_; |
146 | 138 |
147 // Holds the message pipe to the child process until it is either closed or | 139 // Holds the message pipe to the child process until it is either closed or |
148 // bound to the controller interface. | 140 // bound to the controller interface. |
149 scoped_refptr<PipeHolder> pipe_holder_; | 141 scoped_refptr<PipeHolder> pipe_holder_; |
150 | 142 |
151 // Invoked exactly once, as soon as the child process's ID is known and | 143 // Invoked exactly once, as soon as the child process's ID is known and |
152 // a pipe to the child has been established. | 144 // a pipe to the child has been established. |
153 ProcessReadyCallback process_ready_callback_; | 145 ProcessReadyCallback process_ready_callback_; |
154 | 146 |
155 base::WeakPtrFactory<ChildProcessHost> weak_factory_; | 147 base::WeakPtrFactory<ChildProcessHost> weak_factory_; |
156 | 148 |
157 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); | 149 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); |
158 }; | 150 }; |
159 | 151 |
160 } // namespace shell | 152 } // namespace shell |
161 } // namespace mojo | 153 } // namespace mojo |
162 | 154 |
163 #endif // MOJO_SHELL_RUNNER_HOST_CHILD_PROCESS_HOST_H_ | 155 #endif // MOJO_SHELL_RUNNER_HOST_CHILD_PROCESS_HOST_H_ |
OLD | NEW |