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 <unistd.h> | 5 #include <unistd.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 20 #include "base/posix/global_descriptors.h" |
20 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
21 #include "base/synchronization/waitable_event.h" | 22 #include "base/synchronization/waitable_event.h" |
22 #include "base/thread_task_runner_handle.h" | 23 #include "base/thread_task_runner_handle.h" |
23 #include "base/threading/thread.h" | 24 #include "base/threading/thread.h" |
24 #include "base/threading/thread_checker.h" | 25 #include "base/threading/thread_checker.h" |
25 #include "mojo/edk/base_edk/platform_handle_watcher_impl.h" | 26 #include "mojo/edk/base_edk/platform_handle_watcher_impl.h" |
26 #include "mojo/edk/base_edk/platform_task_runner_impl.h" | 27 #include "mojo/edk/base_edk/platform_task_runner_impl.h" |
27 #include "mojo/edk/embedder/embedder.h" | 28 #include "mojo/edk/embedder/embedder.h" |
28 #include "mojo/edk/embedder/multiprocess_embedder.h" | 29 #include "mojo/edk/embedder/multiprocess_embedder.h" |
29 #include "mojo/edk/embedder/platform_channel_pair.h" | 30 #include "mojo/edk/embedder/platform_channel_pair.h" |
30 #include "mojo/edk/embedder/simple_platform_support.h" | 31 #include "mojo/edk/embedder/simple_platform_support.h" |
31 #include "mojo/edk/embedder/slave_process_delegate.h" | 32 #include "mojo/edk/embedder/slave_process_delegate.h" |
| 33 #include "mojo/edk/platform/platform_handle.h" |
32 #include "mojo/edk/platform/platform_handle_watcher.h" | 34 #include "mojo/edk/platform/platform_handle_watcher.h" |
33 #include "mojo/edk/platform/scoped_platform_handle.h" | 35 #include "mojo/edk/platform/scoped_platform_handle.h" |
34 #include "mojo/edk/platform/task_runner.h" | 36 #include "mojo/edk/platform/task_runner.h" |
35 #include "mojo/edk/util/make_unique.h" | 37 #include "mojo/edk/util/make_unique.h" |
36 #include "mojo/edk/util/ref_ptr.h" | 38 #include "mojo/edk/util/ref_ptr.h" |
37 #include "mojo/message_pump/message_pump_mojo.h" | 39 #include "mojo/message_pump/message_pump_mojo.h" |
38 #include "mojo/public/cpp/bindings/binding.h" | 40 #include "mojo/public/cpp/bindings/binding.h" |
39 #include "mojo/public/cpp/system/core.h" | 41 #include "mojo/public/cpp/system/core.h" |
40 #include "shell/child_controller.mojom.h" | 42 #include "shell/child_controller.mojom.h" |
41 #include "shell/child_switches.h" | 43 #include "shell/child_switches.h" |
42 #include "shell/init.h" | 44 #include "shell/init.h" |
43 #include "shell/native_application_support.h" | 45 #include "shell/native_application_support.h" |
44 | 46 |
| 47 using mojo::platform::PlatformHandle; |
45 using mojo::platform::PlatformHandleWatcher; | 48 using mojo::platform::PlatformHandleWatcher; |
46 using mojo::platform::ScopedPlatformHandle; | 49 using mojo::platform::ScopedPlatformHandle; |
47 using mojo::platform::TaskRunner; | 50 using mojo::platform::TaskRunner; |
48 using mojo::util::MakeRefCounted; | 51 using mojo::util::MakeRefCounted; |
49 using mojo::util::MakeUnique; | 52 using mojo::util::MakeUnique; |
50 using mojo::util::RefPtr; | 53 using mojo::util::RefPtr; |
51 | 54 |
52 namespace shell { | 55 namespace shell { |
53 namespace { | 56 namespace { |
54 | 57 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 | 311 |
309 shell::InitializeLogging(); | 312 shell::InitializeLogging(); |
310 | 313 |
311 // Make sure that we're really meant to be invoked as the child process. | 314 // Make sure that we're really meant to be invoked as the child process. |
312 | 315 |
313 CHECK(command_line.HasSwitch(switches::kChildConnectionId)); | 316 CHECK(command_line.HasSwitch(switches::kChildConnectionId)); |
314 std::string child_connection_id = | 317 std::string child_connection_id = |
315 command_line.GetSwitchValueASCII(switches::kChildConnectionId); | 318 command_line.GetSwitchValueASCII(switches::kChildConnectionId); |
316 CHECK(!child_connection_id.empty()); | 319 CHECK(!child_connection_id.empty()); |
317 | 320 |
318 std::string platform_channel_info = | 321 ScopedPlatformHandle platform_handle( |
319 command_line.GetSwitchValueASCII(switches::kPlatformChannelHandleInfo); | 322 (PlatformHandle(base::GlobalDescriptors::kBaseDescriptor))); |
320 ScopedPlatformHandle platform_handle = | |
321 mojo::embedder::PlatformChannelPair::PassClientHandleFromParentProcess( | |
322 platform_channel_info); | |
323 CHECK(platform_handle.is_valid()); | |
324 | |
325 shell::AppContext app_context; | 323 shell::AppContext app_context; |
326 app_context.Init(platform_handle.Pass()); | 324 app_context.Init(platform_handle.Pass()); |
327 | 325 |
328 shell::Blocker blocker; | 326 shell::Blocker blocker; |
329 // TODO(vtl): With C++14 lambda captures, this can be made nicer. | 327 // TODO(vtl): With C++14 lambda captures, this can be made nicer. |
330 const shell::Blocker::Unblocker unblocker = blocker.GetUnblocker(); | 328 const shell::Blocker::Unblocker unblocker = blocker.GetUnblocker(); |
331 app_context.controller_runner()->PostTask( | 329 app_context.controller_runner()->PostTask( |
332 [&app_context, &child_connection_id, &unblocker]() { | 330 [&app_context, &child_connection_id, &unblocker]() { |
333 shell::ChildControllerImpl::Init(&app_context, child_connection_id, | 331 shell::ChildControllerImpl::Init(&app_context, child_connection_id, |
334 unblocker); | 332 unblocker); |
335 }); | 333 }); |
336 // This will block, then run whatever the controller wants. | 334 // This will block, then run whatever the controller wants. |
337 blocker.Block(); | 335 blocker.Block(); |
338 | 336 |
339 app_context.Shutdown(); | 337 app_context.Shutdown(); |
340 | 338 |
341 return 0; | 339 return 0; |
342 } | 340 } |
OLD | NEW |