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

Side by Side Diff: mojo/shell/runner/host/child_process.cc

Issue 1676913002: [mojo] Delete third_party/mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: let's try that again Created 4 years, 10 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/host/BUILD.gn ('k') | mojo/shell/runner/host/child_process_host.h » ('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 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.h" 5 #include "mojo/shell/runner/host/child_process.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 10 matching lines...) Expand all
21 #include "base/memory/ref_counted.h" 21 #include "base/memory/ref_counted.h"
22 #include "base/memory/scoped_ptr.h" 22 #include "base/memory/scoped_ptr.h"
23 #include "base/message_loop/message_loop.h" 23 #include "base/message_loop/message_loop.h"
24 #include "base/single_thread_task_runner.h" 24 #include "base/single_thread_task_runner.h"
25 #include "base/synchronization/waitable_event.h" 25 #include "base/synchronization/waitable_event.h"
26 #include "base/thread_task_runner_handle.h" 26 #include "base/thread_task_runner_handle.h"
27 #include "base/threading/thread.h" 27 #include "base/threading/thread.h"
28 #include "base/threading/thread_checker.h" 28 #include "base/threading/thread_checker.h"
29 #include "mojo/edk/embedder/embedder.h" 29 #include "mojo/edk/embedder/embedder.h"
30 #include "mojo/edk/embedder/platform_channel_pair.h" 30 #include "mojo/edk/embedder/platform_channel_pair.h"
31 #include "mojo/edk/embedder/process_delegate.h"
32 #include "mojo/edk/embedder/scoped_platform_handle.h"
31 #include "mojo/message_pump/message_pump_mojo.h" 33 #include "mojo/message_pump/message_pump_mojo.h"
32 #include "mojo/public/cpp/bindings/binding.h" 34 #include "mojo/public/cpp/bindings/binding.h"
33 #include "mojo/public/cpp/system/core.h" 35 #include "mojo/public/cpp/system/core.h"
34 #include "mojo/shell/runner/child/child_controller.mojom.h" 36 #include "mojo/shell/runner/child/child_controller.mojom.h"
35 #include "mojo/shell/runner/common/switches.h" 37 #include "mojo/shell/runner/common/switches.h"
36 #include "mojo/shell/runner/host/native_application_support.h" 38 #include "mojo/shell/runner/host/native_application_support.h"
37 #include "mojo/shell/runner/init.h" 39 #include "mojo/shell/runner/init.h"
38 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h"
39 #include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h"
40 #include "third_party/mojo/src/mojo/edk/embedder/process_delegate.h"
41 #include "third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h"
42 40
43 #if defined(OS_LINUX) && !defined(OS_ANDROID) 41 #if defined(OS_LINUX) && !defined(OS_ANDROID)
44 #include "base/rand_util.h" 42 #include "base/rand_util.h"
45 #include "base/sys_info.h" 43 #include "base/sys_info.h"
46 #include "mojo/shell/runner/host/linux_sandbox.h" 44 #include "mojo/shell/runner/host/linux_sandbox.h"
47 #endif 45 #endif
48 46
49 namespace mojo { 47 namespace mojo {
50 namespace shell { 48 namespace shell {
51 49
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 base::Closure run_after_; 91 base::Closure run_after_;
94 92
95 DISALLOW_COPY_AND_ASSIGN(Blocker); 93 DISALLOW_COPY_AND_ASSIGN(Blocker);
96 }; 94 };
97 95
98 // AppContext ------------------------------------------------------------------ 96 // AppContext ------------------------------------------------------------------
99 97
100 class ChildControllerImpl; 98 class ChildControllerImpl;
101 99
102 // Should be created and initialized on the main thread. 100 // Should be created and initialized on the main thread.
103 // TODO(use_chrome_edk) 101 class AppContext : public edk::ProcessDelegate {
104 // class AppContext : public edk::ProcessDelegate {
105 class AppContext : public embedder::ProcessDelegate {
106 public: 102 public:
107 AppContext() 103 AppContext()
108 : io_thread_("io_thread"), controller_thread_("controller_thread") {} 104 : io_thread_("io_thread"), controller_thread_("controller_thread") {}
109 ~AppContext() override {} 105 ~AppContext() override {}
110 106
111 void Init() { 107 void Init() {
112 embedder::PreInitializeChildProcess();
113 // Initialize Mojo before starting any threads. 108 // Initialize Mojo before starting any threads.
114 embedder::Init(); 109 edk::Init();
115 110
116 // Create and start our I/O thread. 111 // Create and start our I/O thread.
117 base::Thread::Options io_thread_options(base::MessageLoop::TYPE_IO, 0); 112 base::Thread::Options io_thread_options(base::MessageLoop::TYPE_IO, 0);
118 CHECK(io_thread_.StartWithOptions(io_thread_options)); 113 CHECK(io_thread_.StartWithOptions(io_thread_options));
119 io_runner_ = io_thread_.task_runner().get(); 114 io_runner_ = io_thread_.task_runner().get();
120 CHECK(io_runner_.get()); 115 CHECK(io_runner_.get());
121 116
122 // TODO(vtl): This should be SLAVE, not NONE. 117 // TODO(vtl): This should be SLAVE, not NONE.
123 // This must be created before controller_thread_ since MessagePumpMojo will 118 // This must be created before controller_thread_ since MessagePumpMojo will
124 // create a message pipe which requires this code to be run first. 119 // create a message pipe which requires this code to be run first.
125 embedder::InitIPCSupport(embedder::ProcessType::NONE, this, io_runner_, 120 edk::InitIPCSupport(this, io_runner_);
126 embedder::ScopedPlatformHandle());
127 } 121 }
128 122
129 void StartControllerThread() { 123 void StartControllerThread() {
130 // Create and start our controller thread. 124 // Create and start our controller thread.
131 base::Thread::Options controller_thread_options; 125 base::Thread::Options controller_thread_options;
132 controller_thread_options.message_loop_type = 126 controller_thread_options.message_loop_type =
133 base::MessageLoop::TYPE_CUSTOM; 127 base::MessageLoop::TYPE_CUSTOM;
134 controller_thread_options.message_pump_factory = 128 controller_thread_options.message_pump_factory =
135 base::Bind(&common::MessagePumpMojo::Create); 129 base::Bind(&common::MessagePumpMojo::Create);
136 CHECK(controller_thread_.StartWithOptions(controller_thread_options)); 130 CHECK(controller_thread_.StartWithOptions(controller_thread_options));
(...skipping 21 matching lines...) Expand all
158 void set_controller(scoped_ptr<ChildControllerImpl> controller) { 152 void set_controller(scoped_ptr<ChildControllerImpl> controller) {
159 controller_ = std::move(controller); 153 controller_ = std::move(controller);
160 } 154 }
161 155
162 private: 156 private:
163 void ShutdownOnControllerThread() { 157 void ShutdownOnControllerThread() {
164 // First, destroy the controller. 158 // First, destroy the controller.
165 controller_.reset(); 159 controller_.reset();
166 160
167 // Next shutdown IPC. We'll unblock the main thread in OnShutdownComplete(). 161 // Next shutdown IPC. We'll unblock the main thread in OnShutdownComplete().
168 embedder::ShutdownIPCSupport(); 162 edk::ShutdownIPCSupport();
169 } 163 }
170 164
171 // ProcessDelegate implementation. 165 // ProcessDelegate implementation.
172 void OnShutdownComplete() override { 166 void OnShutdownComplete() override {
173 shutdown_unblocker_.Unblock(base::Closure()); 167 shutdown_unblocker_.Unblock(base::Closure());
174 } 168 }
175 169
176 base::Thread io_thread_; 170 base::Thread io_thread_;
177 scoped_refptr<base::SingleThreadTaskRunner> io_runner_; 171 scoped_refptr<base::SingleThreadTaskRunner> io_runner_;
178 172
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 // Initialize stack dumping just before initializing sandbox to make 324 // Initialize stack dumping just before initializing sandbox to make
331 // sure symbol names in all loaded libraries will be cached. 325 // sure symbol names in all loaded libraries will be cached.
332 base::debug::EnableInProcessStackDumping(); 326 base::debug::EnableInProcessStackDumping();
333 #endif 327 #endif
334 #if defined(OS_LINUX) && !defined(OS_ANDROID) 328 #if defined(OS_LINUX) && !defined(OS_ANDROID)
335 if (command_line.HasSwitch(switches::kEnableSandbox)) 329 if (command_line.HasSwitch(switches::kEnableSandbox))
336 sandbox = InitializeSandbox(); 330 sandbox = InitializeSandbox();
337 #endif 331 #endif
338 332
339 edk::ScopedPlatformHandle platform_channel = 333 edk::ScopedPlatformHandle platform_channel =
340 edk::PlatformChannelPair::PassClientHandleFromParentProcess( 334 edk::PlatformChannelPair::PassClientHandleFromParentProcess(command_line);
341 command_line);
342 CHECK(platform_channel.is_valid()); 335 CHECK(platform_channel.is_valid());
343 336
344 DCHECK(!base::MessageLoop::current()); 337 DCHECK(!base::MessageLoop::current());
345 338
346 Blocker blocker; 339 Blocker blocker;
347 AppContext app_context; 340 AppContext app_context;
348 app_context.Init(); 341 app_context.Init();
349 app_context.StartControllerThread(); 342 app_context.StartControllerThread();
350 343
351 ScopedMessagePipeHandle host_pipe = InitializeHostMessagePipe( 344 ScopedMessagePipeHandle host_pipe = InitializeHostMessagePipe(
352 std::move(platform_channel), app_context.io_runner()); 345 std::move(platform_channel), app_context.io_runner());
353 app_context.controller_runner()->PostTask( 346 app_context.controller_runner()->PostTask(
354 FROM_HERE, 347 FROM_HERE,
355 base::Bind(&ChildControllerImpl::Init, &app_context, app_library, 348 base::Bind(&ChildControllerImpl::Init, &app_context, app_library,
356 base::Passed(&host_pipe), blocker.GetUnblocker())); 349 base::Passed(&host_pipe), blocker.GetUnblocker()));
357 350
358 // This will block, then run whatever the controller wants. 351 // This will block, then run whatever the controller wants.
359 blocker.Block(); 352 blocker.Block();
360 353
361 app_context.Shutdown(); 354 app_context.Shutdown();
362 355
363 return 0; 356 return 0;
364 } 357 }
365 358
366 } // namespace shell 359 } // namespace shell
367 } // namespace mojo 360 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/runner/host/BUILD.gn ('k') | mojo/shell/runner/host/child_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698