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/gfx/switches.h" | 14 #include "ui/gfx/switches.h" |
15 #include "ui/gl/gl_surface.h" | 15 #include "ui/gl/gl_surface.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 void RunApps(mojo::shell::Context* context) { | 19 void RunApps(mojo::shell::Context* context, std::vector<GURL> app_urls) { |
20 const base::CommandLine& command_line = | 20 for (std::vector<GURL>::const_iterator it = app_urls.begin(); |
21 *base::CommandLine::ForCurrentProcess(); | 21 it != app_urls.end(); ++it) { |
22 base::CommandLine::StringVector args = command_line.GetArgs(); | 22 context->Run(*it); |
23 for (base::CommandLine::StringVector::const_iterator it = args.begin(); | |
24 it != args.end(); | |
25 ++it) { | |
26 context->Run(GURL(*it)); | |
27 } | 23 } |
28 } | 24 } |
29 | 25 |
30 } // namespace | 26 } // namespace |
31 | 27 |
32 int main(int argc, char** argv) { | 28 int main(int argc, char** argv) { |
33 base::AtExitManager at_exit; | 29 base::AtExitManager at_exit; |
34 base::CommandLine::Init(argc, argv); | 30 base::CommandLine::Init(argc, argv); |
35 #if defined(OS_LINUX) | 31 #if defined(OS_LINUX) |
36 // We use gfx::RenderText from multiple threads concurrently and the pango | 32 // We use gfx::RenderText from multiple threads concurrently and the pango |
37 // backend (currently the default on linux) is not close to threadsafe. Force | 33 // backend (currently the default on linux) is not close to threadsafe. Force |
38 // use of the harfbuzz backend for now. | 34 // use of the harfbuzz backend for now. |
39 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 35 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
40 switches::kEnableHarfBuzzRenderText); | 36 switches::kEnableHarfBuzzRenderText); |
41 #endif | 37 #endif |
42 mojo::shell::InitializeLogging(); | 38 mojo::shell::InitializeLogging(); |
43 | 39 |
44 // TODO(vtl): Unify parent and child process cases to the extent possible. | 40 // TODO(vtl): Unify parent and child process cases to the extent possible. |
45 if (scoped_ptr<mojo::shell::ChildProcess> child_process = | 41 if (scoped_ptr<mojo::shell::ChildProcess> child_process = |
46 mojo::shell::ChildProcess::Create( | 42 mojo::shell::ChildProcess::Create( |
47 *base::CommandLine::ForCurrentProcess())) { | 43 *base::CommandLine::ForCurrentProcess())) { |
48 child_process->Main(); | 44 child_process->Main(); |
49 } else { | 45 } else { |
50 #if defined(COMPONENT_BUILD) | |
51 gfx::GLSurface::InitializeOneOff(); | 46 gfx::GLSurface::InitializeOneOff(); |
52 #endif | 47 |
53 // We want the shell::Context to outlive the MessageLoop so that pipes are | 48 // We want the shell::Context to outlive the MessageLoop so that pipes are |
54 // all gracefully closed / error-out before we try to shut the Context down. | 49 // all gracefully closed / error-out before we try to shut the Context down. |
55 mojo::shell::Context shell_context; | 50 mojo::shell::Context shell_context; |
56 { | 51 { |
57 base::MessageLoop message_loop; | 52 base::MessageLoop message_loop; |
58 shell_context.Init(); | 53 shell_context.Init(); |
59 | 54 |
60 const base::CommandLine& command_line = | 55 const base::CommandLine& command_line = |
61 *base::CommandLine::ForCurrentProcess(); | 56 *base::CommandLine::ForCurrentProcess(); |
62 if (command_line.HasSwitch(switches::kOrigin)) { | 57 if (command_line.HasSwitch(switches::kOrigin)) { |
63 shell_context.mojo_url_resolver()->SetBaseURL( | 58 shell_context.mojo_url_resolver()->SetBaseURL( |
64 GURL(command_line.GetSwitchValueASCII(switches::kOrigin))); | 59 GURL(command_line.GetSwitchValueASCII(switches::kOrigin))); |
65 } | 60 } |
66 | 61 |
67 message_loop.PostTask(FROM_HERE, base::Bind(RunApps, &shell_context)); | 62 std::vector<GURL> app_urls; |
| 63 base::CommandLine::StringVector args = command_line.GetArgs(); |
| 64 for (base::CommandLine::StringVector::const_iterator it = args.begin(); |
| 65 it != args.end(); |
| 66 ++it) |
| 67 app_urls.push_back(GURL(*it)); |
| 68 |
| 69 message_loop.PostTask(FROM_HERE, |
| 70 base::Bind(RunApps, |
| 71 &shell_context, |
| 72 app_urls)); |
68 message_loop.Run(); | 73 message_loop.Run(); |
69 } | 74 } |
70 } | 75 } |
71 return 0; | 76 return 0; |
72 } | 77 } |
OLD | NEW |