OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "base/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "mojo/shell/child_process.h" | 10 #include "mojo/shell/child_process.h" |
11 #include "mojo/shell/context.h" | 11 #include "mojo/shell/context.h" |
12 #include "mojo/shell/init.h" | 12 #include "mojo/shell/init.h" |
13 #include "mojo/shell/switches.h" | 13 #include "mojo/shell/switches.h" |
14 #include "ui/gl/gl_surface.h" | 14 #include "ui/gl/gl_surface.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 void RunApps(mojo::shell::Context* context, std::vector<GURL> app_urls) { | 18 void RunApps(mojo::shell::Context* context) { |
19 for (std::vector<GURL>::const_iterator it = app_urls.begin(); | 19 const base::CommandLine& command_line = |
20 it != app_urls.end(); ++it) { | 20 *base::CommandLine::ForCurrentProcess(); |
21 context->Run(*it); | 21 base::CommandLine::StringVector args = command_line.GetArgs(); |
| 22 for (base::CommandLine::StringVector::const_iterator it = args.begin(); |
| 23 it != args.end(); |
| 24 ++it) { |
| 25 context->Run(GURL(*it)); |
22 } | 26 } |
23 } | 27 } |
24 | 28 |
25 } // namespace | 29 } // namespace |
26 | 30 |
27 int main(int argc, char** argv) { | 31 int main(int argc, char** argv) { |
28 base::AtExitManager at_exit; | 32 base::AtExitManager at_exit; |
29 base::CommandLine::Init(argc, argv); | 33 base::CommandLine::Init(argc, argv); |
30 mojo::shell::InitializeLogging(); | 34 mojo::shell::InitializeLogging(); |
31 | 35 |
32 // TODO(vtl): Unify parent and child process cases to the extent possible. | 36 // TODO(vtl): Unify parent and child process cases to the extent possible. |
33 if (scoped_ptr<mojo::shell::ChildProcess> child_process = | 37 if (scoped_ptr<mojo::shell::ChildProcess> child_process = |
34 mojo::shell::ChildProcess::Create( | 38 mojo::shell::ChildProcess::Create( |
35 *base::CommandLine::ForCurrentProcess())) { | 39 *base::CommandLine::ForCurrentProcess())) { |
36 child_process->Main(); | 40 child_process->Main(); |
37 } else { | 41 } else { |
| 42 #if defined(COMPONENT_BUILD) |
38 gfx::GLSurface::InitializeOneOff(); | 43 gfx::GLSurface::InitializeOneOff(); |
39 | 44 #endif |
40 // We want the shell::Context to outlive the MessageLoop so that pipes are | 45 // We want the shell::Context to outlive the MessageLoop so that pipes are |
41 // all gracefully closed / error-out before we try to shut the Context down. | 46 // all gracefully closed / error-out before we try to shut the Context down. |
42 mojo::shell::Context shell_context; | 47 mojo::shell::Context shell_context; |
43 { | 48 { |
44 base::MessageLoop message_loop; | 49 base::MessageLoop message_loop; |
45 shell_context.Init(); | 50 shell_context.Init(); |
46 | 51 |
47 const base::CommandLine& command_line = | 52 const base::CommandLine& command_line = |
48 *base::CommandLine::ForCurrentProcess(); | 53 *base::CommandLine::ForCurrentProcess(); |
49 if (command_line.HasSwitch(switches::kOrigin)) { | 54 if (command_line.HasSwitch(switches::kOrigin)) { |
50 shell_context.mojo_url_resolver()->SetBaseURL( | 55 shell_context.mojo_url_resolver()->SetBaseURL( |
51 GURL(command_line.GetSwitchValueASCII(switches::kOrigin))); | 56 GURL(command_line.GetSwitchValueASCII(switches::kOrigin))); |
52 } | 57 } |
53 | 58 |
54 std::vector<GURL> app_urls; | 59 message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context)); |
55 base::CommandLine::StringVector args = command_line.GetArgs(); | |
56 for (base::CommandLine::StringVector::const_iterator it = args.begin(); | |
57 it != args.end(); | |
58 ++it) | |
59 app_urls.push_back(GURL(*it)); | |
60 | |
61 message_loop.PostTask(FROM_HERE, | |
62 base::Bind(RunApps, | |
63 &shell_context, | |
64 app_urls)); | |
65 message_loop.Run(); | 60 message_loop.Run(); |
66 } | 61 } |
67 } | 62 } |
68 return 0; | 63 return 0; |
69 } | 64 } |
OLD | NEW |