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 "shell/child_main.h" | |
6 | |
7 #include <unistd.h> | 5 #include <unistd.h> |
8 | 6 |
7 #include "base/at_exit.h" | |
9 #include "base/bind.h" | 8 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
11 #include "base/command_line.h" | 10 #include "base/command_line.h" |
12 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
13 #include "base/location.h" | 12 #include "base/location.h" |
14 #include "base/logging.h" | 13 #include "base/logging.h" |
15 #include "base/macros.h" | 14 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
18 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
19 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
20 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
21 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
22 #include "base/threading/thread_checker.h" | 21 #include "base/threading/thread_checker.h" |
23 #include "mojo/common/message_pump_mojo.h" | 22 #include "mojo/common/message_pump_mojo.h" |
24 #include "mojo/edk/embedder/embedder.h" | 23 #include "mojo/edk/embedder/embedder.h" |
25 #include "mojo/edk/embedder/platform_channel_pair.h" | 24 #include "mojo/edk/embedder/platform_channel_pair.h" |
26 #include "mojo/edk/embedder/process_delegate.h" | 25 #include "mojo/edk/embedder/process_delegate.h" |
27 #include "mojo/edk/embedder/scoped_platform_handle.h" | 26 #include "mojo/edk/embedder/scoped_platform_handle.h" |
28 #include "mojo/edk/embedder/simple_platform_support.h" | 27 #include "mojo/edk/embedder/simple_platform_support.h" |
29 #include "mojo/public/cpp/system/core.h" | 28 #include "mojo/public/cpp/system/core.h" |
30 #include "shell/child_controller.mojom.h" | 29 #include "shell/child_controller.mojom.h" |
30 #include "shell/init.h" | |
31 #include "shell/native_application_support.h" | 31 #include "shell/native_application_support.h" |
32 #include "shell/switches.h" | |
32 | 33 |
33 namespace mojo { | 34 namespace mojo { |
34 namespace shell { | 35 namespace shell { |
35 | 36 |
36 namespace { | 37 namespace { |
37 | 38 |
38 // Blocker --------------------------------------------------------------------- | 39 // Blocker --------------------------------------------------------------------- |
39 | 40 |
40 // Blocks a thread until another thread unblocks it, at which point it unblocks | 41 // Blocks a thread until another thread unblocks it, at which point it unblocks |
41 // and runs a closure provided by that thread. | 42 // and runs a closure provided by that thread. |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 StartAppCallback on_app_complete_; | 270 StartAppCallback on_app_complete_; |
270 | 271 |
271 embedder::ChannelInfo* channel_info_; | 272 embedder::ChannelInfo* channel_info_; |
272 Binding<ChildController> binding_; | 273 Binding<ChildController> binding_; |
273 | 274 |
274 DISALLOW_COPY_AND_ASSIGN(ChildControllerImpl); | 275 DISALLOW_COPY_AND_ASSIGN(ChildControllerImpl); |
275 }; | 276 }; |
276 | 277 |
277 } // namespace | 278 } // namespace |
278 | 279 |
279 // ChildMain ------------------------------------------------------------------- | 280 } // namespace shell |
281 } // namespace mojo | |
280 | 282 |
281 int ChildMain() { | 283 int main(int argc, char** argv) { |
282 DVLOG(2) << "ChildMain()"; | 284 base::AtExitManager at_exit; |
285 base::CommandLine::Init(argc, argv); | |
283 | 286 |
284 DCHECK(!base::MessageLoop::current()); | 287 mojo::shell::InitializeLogging(); |
285 | 288 |
286 embedder::ScopedPlatformHandle platform_channel = | 289 // Make sure that we're really meant to be invoked as the child process. |
287 embedder::PlatformChannelPair::PassClientHandleFromParentProcess( | 290 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
291 switches::kChildProcess)); | |
DaveMoore
2015/04/07 22:27:30
this seems unnecessary. Why bother with having a s
| |
292 | |
293 mojo::embedder::ScopedPlatformHandle platform_channel = | |
294 mojo::embedder::PlatformChannelPair::PassClientHandleFromParentProcess( | |
288 *base::CommandLine::ForCurrentProcess()); | 295 *base::CommandLine::ForCurrentProcess()); |
289 CHECK(platform_channel.is_valid()); | 296 CHECK(platform_channel.is_valid()); |
290 | 297 |
291 AppContext app_context; | 298 mojo::shell::AppContext app_context; |
292 app_context.Init(); | 299 app_context.Init(); |
293 | 300 |
294 Blocker blocker; | 301 mojo::shell::Blocker blocker; |
295 app_context.controller_runner()->PostTask( | 302 app_context.controller_runner()->PostTask( |
296 FROM_HERE, | 303 FROM_HERE, |
297 base::Bind(&ChildControllerImpl::Init, base::Unretained(&app_context), | 304 base::Bind(&mojo::shell::ChildControllerImpl::Init, |
305 base::Unretained(&app_context), | |
298 base::Passed(&platform_channel), blocker.GetUnblocker())); | 306 base::Passed(&platform_channel), blocker.GetUnblocker())); |
299 // This will block, then run whatever the controller wants. | 307 // This will block, then run whatever the controller wants. |
300 blocker.Block(); | 308 blocker.Block(); |
301 | 309 |
302 app_context.Shutdown(); | 310 app_context.Shutdown(); |
303 | 311 |
304 return 0; | 312 return 0; |
305 } | 313 } |
306 | |
307 } // namespace shell | |
308 } // namespace mojo | |
OLD | NEW |