1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/at_exit.h"
6 #include "base/command_line.h"
7 #include "base/logging.h"
8 #include "base/macros.h" // TODO(vtl): Remove.
9 #include "base/message_loop/message_loop.h"
10 #include "mojo/common/message_pump_mojo.h" // TODO(vtl): Remove.
11 #include "mojo/shell/child_process.h"
12 #include "mojo/shell/child_process_host.h" // TODO(vtl): Remove.
13 #include "mojo/shell/context.h"
14 #include "mojo/shell/init.h"
15 #include "mojo/shell/run.h"
16 #include "ui/gl/gl_surface.h"
21 class TestChildProcessHostDelegate
22 : public mojo::shell::ChildProcessHost::Delegate {
24 TestChildProcessHostDelegate() {}
25 virtual ~TestChildProcessHostDelegate() {}
26 virtual void WillStart() OVERRIDE {
27 VLOG(2) << "TestChildProcessHostDelegate::WillStart()";
29 virtual void DidStart(bool success) OVERRIDE {
30 VLOG(2) << "TestChildProcessHostDelegate::DidStart(" << success << ")";
31 base::MessageLoop::current()->QuitWhenIdle();
37 int main(int argc, char** argv) {
38 base::AtExitManager at_exit;
39 CommandLine::Init(argc, argv);
40 mojo::shell::InitializeLogging();
42 // TODO(vtl): Move this a proper test (and remove includes marked "remove").
43 if (CommandLine::ForCurrentProcess()->HasSwitch("run-test-child")) {
44 base::MessageLoop message_loop(
45 scoped_ptr<base::MessagePump>(new mojo::common::MessagePumpMojo()));
47 mojo::shell::Context context;
48 TestChildProcessHostDelegate child_process_host_delegate;
49 mojo::shell::ChildProcessHost child_process_host(
50 &context, &child_process_host_delegate,
51 mojo::shell::ChildProcess::TYPE_TEST);
52 child_process_host.Start();
54 int exit_code = child_process_host.Join();
55 VLOG(2) << "Joined child: exit_code = " << exit_code;
59 // TODO(vtl): Unify parent and child process cases to the extent possible.
60 if (scoped_ptr<mojo::shell::ChildProcess> child_process =
61 mojo::shell::ChildProcess::Create(
62 *CommandLine::ForCurrentProcess())) {
63 child_process->Main();
65 gfx::GLSurface::InitializeOneOff();
67 base::MessageLoop message_loop;
68 mojo::shell::Context context;
69 message_loop.PostTask(FROM_HERE, base::Bind(mojo::shell::Run, &context));