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 <algorithm> | 5 #include <algorithm> |
6 #include <iostream> | 6 #include <iostream> |
7 | 7 |
8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 << "text/html,mojo:html_viewer," | 44 << "text/html,mojo:html_viewer," |
45 << "application/javascript,mojo:js_content_handler\n"; | 45 << "application/javascript,mojo:js_content_handler\n"; |
46 } | 46 } |
47 | 47 |
48 } // namespace | 48 } // namespace |
49 | 49 |
50 int main(int argc, char** argv) { | 50 int main(int argc, char** argv) { |
51 base::AtExitManager at_exit; | 51 base::AtExitManager at_exit; |
52 base::CommandLine::Init(argc, argv); | 52 base::CommandLine::Init(argc, argv); |
53 | 53 |
54 const base::CommandLine& command_line = | |
55 *base::CommandLine::ForCurrentProcess(); | |
56 | |
57 const std::set<std::string> all_switches = switches::GetAllSwitches(); | |
58 const base::CommandLine::SwitchMap switches = command_line.GetSwitches(); | |
59 bool found_unknown_switch = false; | |
60 for (const auto& s : switches) { | |
61 if (all_switches.find(s.first) == all_switches.end()) { | |
62 std::cerr << "unknown switch: " << s.first << std::endl; | |
63 found_unknown_switch = true; | |
64 } | |
65 } | |
66 | |
67 if (found_unknown_switch || | |
68 (!command_line.HasSwitch(switches::kEnableExternalApplications) && | |
69 (command_line.HasSwitch(switches::kHelp) || | |
70 command_line.GetArgs().empty()))) { | |
71 Usage(); | |
72 return 0; | |
73 } | |
74 | |
75 #if defined(OS_LINUX) | |
76 // We use gfx::RenderText from multiple threads concurrently and the pango | |
77 // backend (currently the default on linux) is not close to threadsafe. Force | |
78 // use of the harfbuzz backend for now. | |
79 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
80 kEnableHarfBuzzRenderText); | |
81 #endif | |
82 mojo::shell::InitializeLogging(); | 54 mojo::shell::InitializeLogging(); |
83 | 55 |
84 // TODO(vtl): Unify parent and child process cases to the extent possible. | 56 // TODO(vtl): Unify parent and child process cases to the extent possible. |
85 if (scoped_ptr<mojo::shell::ChildProcess> child_process = | 57 if (scoped_ptr<mojo::shell::ChildProcess> child_process = |
86 mojo::shell::ChildProcess::Create( | 58 mojo::shell::ChildProcess::Create( |
87 *base::CommandLine::ForCurrentProcess())) { | 59 *base::CommandLine::ForCurrentProcess())) { |
88 child_process->Main(); | 60 child_process->Main(); |
89 } else { | 61 } else { |
| 62 // Only check the command line for the main process. |
| 63 const base::CommandLine& command_line = |
| 64 *base::CommandLine::ForCurrentProcess(); |
| 65 |
| 66 const std::set<std::string> all_switches = switches::GetAllSwitches(); |
| 67 const base::CommandLine::SwitchMap switches = command_line.GetSwitches(); |
| 68 bool found_unknown_switch = false; |
| 69 for (const auto& s : switches) { |
| 70 if (all_switches.find(s.first) == all_switches.end()) { |
| 71 std::cerr << "unknown switch: " << s.first << std::endl; |
| 72 found_unknown_switch = true; |
| 73 } |
| 74 } |
| 75 |
| 76 if (found_unknown_switch || |
| 77 (!command_line.HasSwitch(switches::kEnableExternalApplications) && |
| 78 (command_line.HasSwitch(switches::kHelp) || |
| 79 command_line.GetArgs().empty()))) { |
| 80 Usage(); |
| 81 return 0; |
| 82 } |
| 83 |
| 84 #if defined(OS_LINUX) |
| 85 // We use gfx::RenderText from multiple threads concurrently and the pango |
| 86 // backend (currently the default on linux) is not close to threadsafe. |
| 87 // Force use of the harfbuzz backend for now. |
| 88 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 89 kEnableHarfBuzzRenderText); |
| 90 #endif |
| 91 |
90 // We want the shell::Context to outlive the MessageLoop so that pipes are | 92 // We want the shell::Context to outlive the MessageLoop so that pipes are |
91 // all gracefully closed / error-out before we try to shut the Context down. | 93 // all gracefully closed / error-out before we try to shut the Context down. |
92 mojo::shell::Context shell_context; | 94 mojo::shell::Context shell_context; |
93 { | 95 { |
94 base::MessageLoop message_loop; | 96 base::MessageLoop message_loop; |
95 if (!shell_context.Init()) { | 97 if (!shell_context.Init()) { |
96 Usage(); | 98 Usage(); |
97 return 0; | 99 return 0; |
98 } | 100 } |
99 | 101 |
100 // The mojo_shell --args-for command-line switch is handled specially | 102 // The mojo_shell --args-for command-line switch is handled specially |
101 // because it can appear more than once. The base::CommandLine class | 103 // because it can appear more than once. The base::CommandLine class |
102 // collapses multiple occurrences of the same switch. | 104 // collapses multiple occurrences of the same switch. |
103 for (int i = 1; i < argc; i++) { | 105 for (int i = 1; i < argc; i++) { |
104 ApplyApplicationArgs(&shell_context, argv[i]); | 106 ApplyApplicationArgs(&shell_context, argv[i]); |
105 } | 107 } |
106 | 108 |
107 message_loop.PostTask( | 109 message_loop.PostTask( |
108 FROM_HERE, | 110 FROM_HERE, |
109 base::Bind(&mojo::shell::RunCommandLineApps, &shell_context)); | 111 base::Bind(&mojo::shell::RunCommandLineApps, &shell_context)); |
110 message_loop.Run(); | 112 message_loop.Run(); |
111 | 113 |
112 // Must be called before |message_loop| is destroyed. | 114 // Must be called before |message_loop| is destroyed. |
113 shell_context.Shutdown(); | 115 shell_context.Shutdown(); |
114 } | 116 } |
115 } | 117 } |
116 return 0; | 118 return 0; |
117 } | 119 } |
OLD | NEW |