Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: mojo/shell/runner/child/runner_connection.cc

Issue 1761153002: Replace ChildController with ShellClientFactory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@29binding
Patch Set: . Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/shell/runner/child/child_controller.mojom ('k') | mojo/shell/runner/host/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "mojo/shell/runner/child/runner_connection.h" 5 #include "mojo/shell/runner/child/runner_connection.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/command_line.h" 13 #include "base/command_line.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/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/thread_task_runner_handle.h" 17 #include "base/thread_task_runner_handle.h"
18 #include "base/threading/thread.h" 18 #include "base/threading/thread.h"
19 #include "base/threading/thread_checker.h" 19 #include "base/threading/thread_checker.h"
20 #include "mojo/edk/embedder/embedder.h" 20 #include "mojo/edk/embedder/embedder.h"
21 #include "mojo/edk/embedder/platform_channel_pair.h" 21 #include "mojo/edk/embedder/platform_channel_pair.h"
22 #include "mojo/edk/embedder/scoped_platform_handle.h" 22 #include "mojo/edk/embedder/scoped_platform_handle.h"
23 #include "mojo/message_pump/message_pump_mojo.h" 23 #include "mojo/message_pump/message_pump_mojo.h"
24 #include "mojo/public/cpp/bindings/binding.h" 24 #include "mojo/public/cpp/bindings/binding.h"
25 #include "mojo/shell/runner/child/child_controller.mojom.h" 25 #include "mojo/shell/public/interfaces/shell_client_factory.mojom.h"
26 #include "mojo/shell/runner/common/switches.h" 26 #include "mojo/shell/runner/common/switches.h"
27 27
28 namespace mojo { 28 namespace mojo {
29 namespace shell { 29 namespace shell {
30 namespace { 30 namespace {
31 31
32 // Blocks a thread until another thread unblocks it, at which point it unblocks 32 // Blocks a thread until another thread unblocks it, at which point it unblocks
33 // and runs a closure provided by that thread. 33 // and runs a closure provided by that thread.
34 class Blocker { 34 class Blocker {
35 public: 35 public:
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 121
122 base::Thread controller_thread_; 122 base::Thread controller_thread_;
123 scoped_refptr<base::SingleThreadTaskRunner> controller_runner_; 123 scoped_refptr<base::SingleThreadTaskRunner> controller_runner_;
124 124
125 // Accessed only on the controller thread. 125 // Accessed only on the controller thread.
126 scoped_ptr<ChildControllerImpl> controller_; 126 scoped_ptr<ChildControllerImpl> controller_;
127 127
128 DISALLOW_COPY_AND_ASSIGN(RunnerConnectionImpl); 128 DISALLOW_COPY_AND_ASSIGN(RunnerConnectionImpl);
129 }; 129 };
130 130
131 class ChildControllerImpl : public mojom::ChildController { 131 class ChildControllerImpl : public mojom::ShellClientFactory {
132 public: 132 public:
133 ~ChildControllerImpl() override { 133 ~ChildControllerImpl() override {
134 DCHECK(thread_checker_.CalledOnValidThread()); 134 DCHECK(thread_checker_.CalledOnValidThread());
135
136 // TODO(vtl): Pass in the result from |MainMain()|.
137 on_app_complete_.Run(MOJO_RESULT_UNIMPLEMENTED);
138 } 135 }
139 136
140 // To be executed on the controller thread. Creates the |ChildController|, 137 // To be executed on the controller thread. Creates the |ChildController|,
141 // etc. 138 // etc.
142 static void Create(RunnerConnectionImpl* connection, 139 static void Create(RunnerConnectionImpl* connection,
143 const GotApplicationRequestCallback& callback, 140 const GotApplicationRequestCallback& callback,
144 ScopedMessagePipeHandle runner_handle, 141 ScopedMessagePipeHandle runner_handle,
145 const Blocker::Unblocker& unblocker, 142 const Blocker::Unblocker& unblocker,
146 bool exit_on_error) { 143 bool exit_on_error) {
147 DCHECK(connection); 144 DCHECK(connection);
(...skipping 12 matching lines...) Expand all
160 binding_.Bind(std::move(handle)); 157 binding_.Bind(std::move(handle));
161 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); 158 binding_.set_connection_error_handler([this]() { OnConnectionError(); });
162 } 159 }
163 160
164 void OnConnectionError() { 161 void OnConnectionError() {
165 // A connection error means the connection to the shell is lost. This is not 162 // A connection error means the connection to the shell is lost. This is not
166 // recoverable. 163 // recoverable.
167 DLOG(ERROR) << "Connection error to the shell."; 164 DLOG(ERROR) << "Connection error to the shell.";
168 if (exit_on_error_) { 165 if (exit_on_error_) {
169 _exit(1); 166 _exit(1);
170 } else if (on_app_complete_.is_null()) { 167 } else {
171 // If we failed before we could even get a ShellClient request from the 168 // If we failed before we could even get a ShellClient request from the
172 // shell, signal failure to the RunnerConnection, as it's still blocking 169 // shell, signal failure to the RunnerConnection, as it's still blocking
173 // on a response. 170 // on a response.
174 unblocker_.Unblock( 171 unblocker_.Unblock(
175 base::Bind(&ChildControllerImpl::ReturnApplicationRequestOnMainThread, 172 base::Bind(&ChildControllerImpl::ReturnApplicationRequestOnMainThread,
176 callback_, nullptr)); 173 callback_, nullptr));
177 } 174 }
178 } 175 }
179 176
180 // |mojom::ChildController| methods: 177 // |mojom::ShellClientFactory| methods:
181 void StartApp(InterfaceRequest<mojom::ShellClient> request, 178 void CreateShellClient(mojom::ShellClientRequest request,
182 const StartAppCallback& on_app_complete) override { 179 const String& name) override {
183 DCHECK(thread_checker_.CalledOnValidThread()); 180 DCHECK(thread_checker_.CalledOnValidThread());
184
185 on_app_complete_ = on_app_complete;
186 unblocker_.Unblock( 181 unblocker_.Unblock(
187 base::Bind(&ChildControllerImpl::ReturnApplicationRequestOnMainThread, 182 base::Bind(&ChildControllerImpl::ReturnApplicationRequestOnMainThread,
188 callback_, base::Passed(&request))); 183 callback_, base::Passed(&request)));
189 } 184 }
190 185
191 void ExitNow(int32_t exit_code) override {
192 DVLOG(2) << "ChildControllerImpl::ExitNow(" << exit_code << ")";
193 _exit(exit_code);
194 }
195
196 private: 186 private:
197 ChildControllerImpl(RunnerConnectionImpl* connection, 187 ChildControllerImpl(RunnerConnectionImpl* connection,
198 const GotApplicationRequestCallback& callback, 188 const GotApplicationRequestCallback& callback,
199 const Blocker::Unblocker& unblocker, 189 const Blocker::Unblocker& unblocker,
200 bool exit_on_error) 190 bool exit_on_error)
201 : connection_(connection), 191 : connection_(connection),
202 callback_(callback), 192 callback_(callback),
203 unblocker_(unblocker), 193 unblocker_(unblocker),
204 binding_(this), 194 binding_(this),
205 exit_on_error_(exit_on_error) {} 195 exit_on_error_(exit_on_error) {}
206 196
207 static void ReturnApplicationRequestOnMainThread( 197 static void ReturnApplicationRequestOnMainThread(
208 const GotApplicationRequestCallback& callback, 198 const GotApplicationRequestCallback& callback,
209 InterfaceRequest<mojom::ShellClient> request) { 199 InterfaceRequest<mojom::ShellClient> request) {
210 callback.Run(std::move(request)); 200 callback.Run(std::move(request));
211 } 201 }
212 202
213 base::ThreadChecker thread_checker_; 203 base::ThreadChecker thread_checker_;
214 RunnerConnectionImpl* const connection_; 204 RunnerConnectionImpl* const connection_;
215 GotApplicationRequestCallback callback_; 205 GotApplicationRequestCallback callback_;
216 Blocker::Unblocker unblocker_; 206 Blocker::Unblocker unblocker_;
217 StartAppCallback on_app_complete_;
218 207
219 Binding<ChildController> binding_; 208 Binding<mojom::ShellClientFactory> binding_;
220 209
221 bool exit_on_error_; 210 bool exit_on_error_;
222 211
223 DISALLOW_COPY_AND_ASSIGN(ChildControllerImpl); 212 DISALLOW_COPY_AND_ASSIGN(ChildControllerImpl);
224 }; 213 };
225 214
226 bool RunnerConnectionImpl::WaitForApplicationRequest( 215 bool RunnerConnectionImpl::WaitForApplicationRequest(
227 InterfaceRequest<mojom::ShellClient>* request, 216 InterfaceRequest<mojom::ShellClient>* request,
228 ScopedMessagePipeHandle handle, 217 ScopedMessagePipeHandle handle,
229 bool exit_on_error) { 218 bool exit_on_error) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 delete connection; 260 delete connection;
272 return nullptr; 261 return nullptr;
273 } 262 }
274 return connection; 263 return connection;
275 } 264 }
276 265
277 RunnerConnection::RunnerConnection() {} 266 RunnerConnection::RunnerConnection() {}
278 267
279 } // namespace shell 268 } // namespace shell
280 } // namespace mojo 269 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/runner/child/child_controller.mojom ('k') | mojo/shell/runner/host/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698