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

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

Issue 1350023003: Add a Mojo EDK for Chrome that uses one OS pipe per message pipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: convert remaining MP tests and simplify RawChannel destruction Created 5 years, 3 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
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/runner/child_process.h" 5 #include "mojo/runner/child_process.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/logging.h" 13 #include "base/logging.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/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
18 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
19 #include "base/synchronization/waitable_event.h" 19 #include "base/synchronization/waitable_event.h"
20 #include "base/thread_task_runner_handle.h" 20 #include "base/thread_task_runner_handle.h"
21 #include "base/threading/thread.h" 21 #include "base/threading/thread.h"
22 #include "base/threading/thread_checker.h" 22 #include "base/threading/thread_checker.h"
23 #include "mojo/edk/embedder/embedder.h"
24 #include "mojo/edk/embedder/platform_channel_pair.h"
25 #include "mojo/edk/embedder/process_delegate.h"
26 #include "mojo/edk/embedder/scoped_platform_handle.h"
27 #include "mojo/edk/embedder/simple_platform_support.h"
28 #include "mojo/message_pump/message_pump_mojo.h" 23 #include "mojo/message_pump/message_pump_mojo.h"
29 #include "mojo/public/cpp/bindings/binding.h" 24 #include "mojo/public/cpp/bindings/binding.h"
30 #include "mojo/public/cpp/system/core.h" 25 #include "mojo/public/cpp/system/core.h"
31 #include "mojo/runner/child_process.mojom.h" 26 #include "mojo/runner/child_process.mojom.h"
32 #include "mojo/runner/native_application_support.h" 27 #include "mojo/runner/native_application_support.h"
33 #include "mojo/runner/switches.h" 28 #include "mojo/runner/switches.h"
34 29
30 #if defined(USE_CHROME_EDK)
31 #include "mojo/edk/embedder/embedder.h"
32 #include "mojo/edk/embedder/platform_channel_pair.h"
33 #include "mojo/edk/embedder/process_delegate.h"
34 #include "mojo/edk/embedder/scoped_platform_handle.h"
35 #include "mojo/edk/embedder/simple_platform_support.h"
36 #else
37 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h"
38 #include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h"
39 #include "third_party/mojo/src/mojo/edk/embedder/process_delegate.h"
40 #include "third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h"
41 #include "third_party/mojo/src/mojo/edk/embedder/simple_platform_support.h"
42 #endif
43
35 #if defined(OS_LINUX) && !defined(OS_ANDROID) 44 #if defined(OS_LINUX) && !defined(OS_ANDROID)
36 #include "base/rand_util.h" 45 #include "base/rand_util.h"
37 #include "base/sys_info.h" 46 #include "base/sys_info.h"
38 #include "mojo/runner/linux_sandbox.h" 47 #include "mojo/runner/linux_sandbox.h"
39 #endif 48 #endif
40 49
41 namespace mojo { 50 namespace mojo {
42 namespace runner { 51 namespace runner {
43 52
44 namespace { 53 namespace {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 embedder::ScopedPlatformHandle platform_channel, 201 embedder::ScopedPlatformHandle platform_channel,
193 const Blocker::Unblocker& unblocker) { 202 const Blocker::Unblocker& unblocker) {
194 DCHECK(app_context); 203 DCHECK(app_context);
195 DCHECK(platform_channel.is_valid()); 204 DCHECK(platform_channel.is_valid());
196 205
197 DCHECK(!app_context->controller()); 206 DCHECK(!app_context->controller());
198 207
199 scoped_ptr<ChildControllerImpl> impl( 208 scoped_ptr<ChildControllerImpl> impl(
200 new ChildControllerImpl(app_context, app_library, unblocker)); 209 new ChildControllerImpl(app_context, app_library, unblocker));
201 210
211 #if defined(USE_CHROME_EDK)
212 ScopedMessagePipeHandle host_message_pipe(
213 embedder::CreateMessagePipe(platform_channel.Pass()));
214 #else
202 ScopedMessagePipeHandle host_message_pipe(embedder::CreateChannel( 215 ScopedMessagePipeHandle host_message_pipe(embedder::CreateChannel(
203 platform_channel.Pass(), 216 platform_channel.Pass(),
204 base::Bind(&ChildControllerImpl::DidCreateChannel, 217 base::Bind(&ChildControllerImpl::DidCreateChannel,
205 base::Unretained(impl.get())), 218 base::Unretained(impl.get())),
206 base::ThreadTaskRunnerHandle::Get())); 219 base::ThreadTaskRunnerHandle::Get()));
220 #endif
207 221
208 impl->Bind(host_message_pipe.Pass()); 222 impl->Bind(host_message_pipe.Pass());
209 223
210 app_context->set_controller(impl.Pass()); 224 app_context->set_controller(impl.Pass());
211 } 225 }
212 226
213 void Bind(ScopedMessagePipeHandle handle) { binding_.Bind(handle.Pass()); } 227 void Bind(ScopedMessagePipeHandle handle) { binding_.Bind(handle.Pass()); }
214 228
215 void OnConnectionError() { 229 void OnConnectionError() {
216 // A connection error means the connection to the shell is lost. This is not 230 // A connection error means the connection to the shell is lost. This is not
(...skipping 18 matching lines...) Expand all
235 _exit(exit_code); 249 _exit(exit_code);
236 } 250 }
237 251
238 private: 252 private:
239 ChildControllerImpl(AppContext* app_context, 253 ChildControllerImpl(AppContext* app_context,
240 base::NativeLibrary app_library, 254 base::NativeLibrary app_library,
241 const Blocker::Unblocker& unblocker) 255 const Blocker::Unblocker& unblocker)
242 : app_context_(app_context), 256 : app_context_(app_context),
243 app_library_(app_library), 257 app_library_(app_library),
244 unblocker_(unblocker), 258 unblocker_(unblocker),
259 #if !defined(USE_CHROME_EDK)
245 channel_info_(nullptr), 260 channel_info_(nullptr),
261 #endif
246 binding_(this) { 262 binding_(this) {
247 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); 263 binding_.set_connection_error_handler([this]() { OnConnectionError(); });
248 } 264 }
249 265
266 #if !defined(USE_CHROME_EDK)
250 // Callback for |embedder::CreateChannel()|. 267 // Callback for |embedder::CreateChannel()|.
251 void DidCreateChannel(embedder::ChannelInfo* channel_info) { 268 void DidCreateChannel(embedder::ChannelInfo* channel_info) {
252 DVLOG(2) << "ChildControllerImpl::DidCreateChannel()"; 269 DVLOG(2) << "ChildControllerImpl::DidCreateChannel()";
253 DCHECK(thread_checker_.CalledOnValidThread()); 270 DCHECK(thread_checker_.CalledOnValidThread());
254 channel_info_ = channel_info; 271 channel_info_ = channel_info;
255 } 272 }
273 #endif
256 274
257 static void StartAppOnMainThread( 275 static void StartAppOnMainThread(
258 base::NativeLibrary app_library, 276 base::NativeLibrary app_library,
259 InterfaceRequest<Application> application_request) { 277 InterfaceRequest<Application> application_request) {
260 if (!RunNativeApplication(app_library, application_request.Pass())) { 278 if (!RunNativeApplication(app_library, application_request.Pass())) {
261 LOG(ERROR) << "Failure to RunNativeApplication()"; 279 LOG(ERROR) << "Failure to RunNativeApplication()";
262 } 280 }
263 } 281 }
264 282
265 base::ThreadChecker thread_checker_; 283 base::ThreadChecker thread_checker_;
266 AppContext* const app_context_; 284 AppContext* const app_context_;
267 base::NativeLibrary app_library_; 285 base::NativeLibrary app_library_;
268 Blocker::Unblocker unblocker_; 286 Blocker::Unblocker unblocker_;
269 StartAppCallback on_app_complete_; 287 StartAppCallback on_app_complete_;
270 288
289 #if !defined(USE_CHROME_EDK)
271 embedder::ChannelInfo* channel_info_; 290 embedder::ChannelInfo* channel_info_;
291 #endif
272 Binding<ChildController> binding_; 292 Binding<ChildController> binding_;
273 293
274 DISALLOW_COPY_AND_ASSIGN(ChildControllerImpl); 294 DISALLOW_COPY_AND_ASSIGN(ChildControllerImpl);
275 }; 295 };
276 296
277 } // namespace 297 } // namespace
278 298
279 int ChildProcessMain() { 299 int ChildProcessMain() {
280 DVLOG(2) << "ChildProcessMain()"; 300 DVLOG(2) << "ChildProcessMain()";
281 const base::CommandLine& command_line = 301 const base::CommandLine& command_line =
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 // This will block, then run whatever the controller wants. 362 // This will block, then run whatever the controller wants.
343 blocker.Block(); 363 blocker.Block();
344 364
345 app_context.Shutdown(); 365 app_context.Shutdown();
346 366
347 return 0; 367 return 0;
348 } 368 }
349 369
350 } // namespace runner 370 } // namespace runner
351 } // namespace mojo 371 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698