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