| 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 #include "mojo/shell/runner/host/child_process_base.h" | 5 #include "mojo/shell/runner/host/child_process_base.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "base/thread_task_runner_handle.h" | 25 #include "base/thread_task_runner_handle.h" |
| 26 #include "base/threading/thread.h" | 26 #include "base/threading/thread.h" |
| 27 #include "base/threading/thread_checker.h" | 27 #include "base/threading/thread_checker.h" |
| 28 #include "mojo/edk/embedder/embedder.h" | 28 #include "mojo/edk/embedder/embedder.h" |
| 29 #include "mojo/edk/embedder/platform_channel_pair.h" | 29 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 30 #include "mojo/edk/embedder/process_delegate.h" | 30 #include "mojo/edk/embedder/process_delegate.h" |
| 31 #include "mojo/edk/embedder/scoped_platform_handle.h" | 31 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 32 #include "mojo/message_pump/message_pump_mojo.h" | 32 #include "mojo/message_pump/message_pump_mojo.h" |
| 33 #include "mojo/public/cpp/bindings/binding.h" | 33 #include "mojo/public/cpp/bindings/binding.h" |
| 34 #include "mojo/public/cpp/system/core.h" | 34 #include "mojo/public/cpp/system/core.h" |
| 35 #include "mojo/shell/runner/child/child_controller.mojom.h" | 35 #include "mojo/shell/public/interfaces/shell_client_factory.mojom.h" |
| 36 #include "mojo/shell/runner/common/switches.h" | 36 #include "mojo/shell/runner/common/switches.h" |
| 37 #include "mojo/shell/runner/init.h" | 37 #include "mojo/shell/runner/init.h" |
| 38 | 38 |
| 39 namespace mojo { | 39 namespace mojo { |
| 40 namespace shell { | 40 namespace shell { |
| 41 | 41 |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 // Blocker --------------------------------------------------------------------- | 44 // Blocker --------------------------------------------------------------------- |
| 45 | 45 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 scoped_ptr<ChildControllerImpl> controller_; | 169 scoped_ptr<ChildControllerImpl> controller_; |
| 170 | 170 |
| 171 // Used to unblock the main thread on shutdown. | 171 // Used to unblock the main thread on shutdown. |
| 172 Blocker::Unblocker shutdown_unblocker_; | 172 Blocker::Unblocker shutdown_unblocker_; |
| 173 | 173 |
| 174 DISALLOW_COPY_AND_ASSIGN(AppContext); | 174 DISALLOW_COPY_AND_ASSIGN(AppContext); |
| 175 }; | 175 }; |
| 176 | 176 |
| 177 // ChildControllerImpl ------------------------------------------------------ | 177 // ChildControllerImpl ------------------------------------------------------ |
| 178 | 178 |
| 179 class ChildControllerImpl : public mojom::ChildController { | 179 class ChildControllerImpl : public mojom::ShellClientFactory { |
| 180 public: | 180 public: |
| 181 ~ChildControllerImpl() override { | 181 ~ChildControllerImpl() override { |
| 182 DCHECK(thread_checker_.CalledOnValidThread()); | 182 DCHECK(thread_checker_.CalledOnValidThread()); |
| 183 | |
| 184 // TODO(vtl): Pass in the result from |MainMain()|. | |
| 185 on_app_complete_.Run(MOJO_RESULT_UNIMPLEMENTED); | |
| 186 } | 183 } |
| 187 | 184 |
| 188 // To be executed on the controller thread. Creates the |ChildController|, | 185 // To be executed on the controller thread. Creates the |ChildController|, |
| 189 // etc. | 186 // etc. |
| 190 static void Init(AppContext* app_context, | 187 static void Init(AppContext* app_context, |
| 191 const RunCallback& run_callback, | 188 const RunCallback& run_callback, |
| 192 ScopedMessagePipeHandle host_message_pipe, | 189 ScopedMessagePipeHandle host_message_pipe, |
| 193 const Blocker::Unblocker& unblocker) { | 190 const Blocker::Unblocker& unblocker) { |
| 194 DCHECK(app_context); | 191 DCHECK(app_context); |
| 195 DCHECK(host_message_pipe.is_valid()); | 192 DCHECK(host_message_pipe.is_valid()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 209 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); | 206 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); |
| 210 } | 207 } |
| 211 | 208 |
| 212 void OnConnectionError() { | 209 void OnConnectionError() { |
| 213 // A connection error means the connection to the shell is lost. This is not | 210 // A connection error means the connection to the shell is lost. This is not |
| 214 // recoverable. | 211 // recoverable. |
| 215 LOG(ERROR) << "Connection error to the shell."; | 212 LOG(ERROR) << "Connection error to the shell."; |
| 216 _exit(1); | 213 _exit(1); |
| 217 } | 214 } |
| 218 | 215 |
| 219 // |ChildController| methods: | 216 // |mojom::ShellClientFactory| methods: |
| 220 void StartApp(InterfaceRequest<mojom::ShellClient> request, | 217 void CreateShellClient(mojom::ShellClientRequest request, |
| 221 const StartAppCallback& on_app_complete) override { | 218 const String& name) override { |
| 222 DCHECK(thread_checker_.CalledOnValidThread()); | 219 DCHECK(thread_checker_.CalledOnValidThread()); |
| 223 | |
| 224 on_app_complete_ = on_app_complete; | |
| 225 unblocker_.Unblock(base::Bind(run_callback_, base::Passed(&request))); | 220 unblocker_.Unblock(base::Bind(run_callback_, base::Passed(&request))); |
| 226 } | 221 } |
| 227 | 222 |
| 228 void ExitNow(int32_t exit_code) override { | |
| 229 DVLOG(2) << "ChildControllerImpl::ExitNow(" << exit_code << ")"; | |
| 230 _exit(exit_code); | |
| 231 } | |
| 232 | |
| 233 private: | 223 private: |
| 234 ChildControllerImpl(AppContext* app_context, | 224 ChildControllerImpl(AppContext* app_context, |
| 235 const RunCallback& run_callback, | 225 const RunCallback& run_callback, |
| 236 const Blocker::Unblocker& unblocker) | 226 const Blocker::Unblocker& unblocker) |
| 237 : run_callback_(run_callback), unblocker_(unblocker), binding_(this) {} | 227 : run_callback_(run_callback), unblocker_(unblocker), binding_(this) {} |
| 238 | 228 |
| 239 base::ThreadChecker thread_checker_; | 229 base::ThreadChecker thread_checker_; |
| 240 RunCallback run_callback_; | 230 RunCallback run_callback_; |
| 241 Blocker::Unblocker unblocker_; | 231 Blocker::Unblocker unblocker_; |
| 242 StartAppCallback on_app_complete_; | |
| 243 | 232 |
| 244 Binding<ChildController> binding_; | 233 Binding<mojom::ShellClientFactory> binding_; |
| 245 | 234 |
| 246 DISALLOW_COPY_AND_ASSIGN(ChildControllerImpl); | 235 DISALLOW_COPY_AND_ASSIGN(ChildControllerImpl); |
| 247 }; | 236 }; |
| 248 | 237 |
| 249 ScopedMessagePipeHandle InitializeHostMessagePipe( | 238 ScopedMessagePipeHandle InitializeHostMessagePipe( |
| 250 edk::ScopedPlatformHandle platform_channel, | 239 edk::ScopedPlatformHandle platform_channel, |
| 251 scoped_refptr<base::TaskRunner> io_task_runner) { | 240 scoped_refptr<base::TaskRunner> io_task_runner) { |
| 252 edk::SetParentPipeHandle(std::move(platform_channel)); | 241 edk::SetParentPipeHandle(std::move(platform_channel)); |
| 253 std::string primordial_pipe_token = | 242 std::string primordial_pipe_token = |
| 254 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 243 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 279 base::Passed(&host_pipe), blocker.GetUnblocker())); | 268 base::Passed(&host_pipe), blocker.GetUnblocker())); |
| 280 | 269 |
| 281 // This will block, then run whatever the controller wants. | 270 // This will block, then run whatever the controller wants. |
| 282 blocker.Block(); | 271 blocker.Block(); |
| 283 | 272 |
| 284 app_context.Shutdown(); | 273 app_context.Shutdown(); |
| 285 } | 274 } |
| 286 | 275 |
| 287 } // namespace shell | 276 } // namespace shell |
| 288 } // namespace mojo | 277 } // namespace mojo |
| OLD | NEW |