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"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h"
10 #include "mojo/shell/child_process.h"
11 #include "mojo/shell/context.h"
12 #include "mojo/shell/init.h"
13 #include "mojo/shell/run.h"
14 #include "mojo/shell/switches.h"
15 #include "ui/gl/gl_surface.h"
17 int main(int argc, char** argv) {
18 base::AtExitManager at_exit;
19 base::CommandLine::Init(argc, argv);
20 mojo::shell::InitializeLogging();
22 // TODO(vtl): Unify parent and child process cases to the extent possible.
23 if (scoped_ptr<mojo::shell::ChildProcess> child_process =
24 mojo::shell::ChildProcess::Create(
25 *base::CommandLine::ForCurrentProcess())) {
26 child_process->Main();
28 gfx::GLSurface::InitializeOneOff();
30 // We want the shell::Context to outlive the MessageLoop so that pipes are
31 // all gracefully closed / error-out before we try to shut the Context down.
32 mojo::shell::Context shell_context;
34 base::MessageLoop message_loop;
37 const base::CommandLine& command_line =
38 *base::CommandLine::ForCurrentProcess();
39 if (command_line.HasSwitch(switches::kOrigin)) {
40 shell_context.mojo_url_resolver()->SetBaseURL(
41 GURL(command_line.GetSwitchValueASCII(switches::kOrigin)));
44 std::vector<GURL> app_urls;
45 base::CommandLine::StringVector args = command_line.GetArgs();
46 for (base::CommandLine::StringVector::const_iterator it = args.begin();
49 app_urls.push_back(GURL(*it));
51 message_loop.PostTask(FROM_HERE,
52 base::Bind(mojo::shell::Run,