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 <stdio.h> | 5 #include <stdio.h> |
6 #include <string.h> | 6 #include <string.h> |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <iostream> | 9 #include <iostream> |
10 | 10 |
11 #include "base/base_switches.h" | 11 #include "base/base_switches.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
17 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
| 18 #include "mojo/shell/command_line_util.h" |
18 #include "mojo/shell/context.h" | 19 #include "mojo/shell/context.h" |
19 #include "mojo/shell/switches.h" | 20 #include "mojo/shell/switches.h" |
20 | 21 |
21 namespace mojo { | 22 namespace mojo { |
22 namespace shell { | 23 namespace shell { |
23 namespace { | 24 namespace { |
24 | 25 |
| 26 void Usage() { |
| 27 std::cerr << "Launch Mojo applications.\n"; |
| 28 std::cerr |
| 29 << "Usage: mojo_shell" |
| 30 << " [--" << switches::kContentHandlers << "=<handlers>]" |
| 31 << " [--" << switches::kDisableCache << "]" |
| 32 << " [--" << switches::kEnableMultiprocess << "]" |
| 33 << " [--" << switches::kOrigin << "=<url-lib-path>]" |
| 34 << " [--" << switches::kTraceStartup << "]" |
| 35 << " [--" << switches::kURLMappings << "=from1=to1,from2=to2]" |
| 36 << " [--" << switches::kPredictableAppFilenames << "]" |
| 37 << " [--" << switches::kWaitForDebugger << "]" |
| 38 << " [--" << switches::kTestApp << "]" |
| 39 << " [<mojo-app>] ...\n\n" |
| 40 << "A <mojo-app> is a Mojo URL or a Mojo URL and arguments within " |
| 41 << "quotes.\n" |
| 42 << "Example: mojo_shell \"mojo:js_standalone test.js\".\n" |
| 43 << "<url-lib-path> is searched for shared libraries named by mojo URLs.\n" |
| 44 << "The value of <handlers> is a comma separated list like:\n" |
| 45 << "text/html,mojo:html_viewer," |
| 46 << "application/javascript,mojo:js_content_handler\n"; |
| 47 } |
| 48 |
25 // Whether we're currently tracing. | 49 // Whether we're currently tracing. |
26 bool g_tracing = false; | 50 bool g_tracing = false; |
27 | 51 |
28 // Number of tracing blocks written. | 52 // Number of tracing blocks written. |
29 uint32_t g_blocks = 0; | 53 uint32_t g_blocks = 0; |
30 | 54 |
31 // Trace file, if open. | 55 // Trace file, if open. |
32 FILE* g_trace_file = nullptr; | 56 FILE* g_trace_file = nullptr; |
33 | 57 |
34 void WriteTraceDataCollected( | 58 void WriteTraceDataCollected( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 101 |
78 void StartWindowManager(mojo::shell::Context* context) { | 102 void StartWindowManager(mojo::shell::Context* context) { |
79 context->Run(GURL("mojo:window_manager")); | 103 context->Run(GURL("mojo:window_manager")); |
80 } | 104 } |
81 | 105 |
82 } // namespace | 106 } // namespace |
83 | 107 |
84 int LauncherProcessMain(int argc, char** argv) { | 108 int LauncherProcessMain(int argc, char** argv) { |
85 const base::CommandLine& command_line = | 109 const base::CommandLine& command_line = |
86 *base::CommandLine::ForCurrentProcess(); | 110 *base::CommandLine::ForCurrentProcess(); |
| 111 |
| 112 if (command_line.HasSwitch(switches::kHelp)) { |
| 113 Usage(); |
| 114 return 0; |
| 115 } |
| 116 |
87 if (command_line.HasSwitch(switches::kTraceStartup)) { | 117 if (command_line.HasSwitch(switches::kTraceStartup)) { |
88 g_tracing = true; | 118 g_tracing = true; |
89 base::trace_event::CategoryFilter category_filter( | 119 base::trace_event::CategoryFilter category_filter( |
90 command_line.GetSwitchValueASCII(switches::kTraceStartup)); | 120 command_line.GetSwitchValueASCII(switches::kTraceStartup)); |
91 base::trace_event::TraceLog::GetInstance()->SetEnabled( | 121 base::trace_event::TraceLog::GetInstance()->SetEnabled( |
92 category_filter, base::trace_event::TraceLog::RECORDING_MODE, | 122 category_filter, base::trace_event::TraceLog::RECORDING_MODE, |
93 base::trace_event::TraceOptions(base::trace_event::RECORD_UNTIL_FULL)); | 123 base::trace_event::TraceOptions(base::trace_event::RECORD_UNTIL_FULL)); |
94 } | 124 } |
95 | 125 |
96 // We want the shell::Context to outlive the MessageLoop so that pipes are | 126 // We want the shell::Context to outlive the MessageLoop so that pipes are |
97 // all gracefully closed / error-out before we try to shut the Context down. | 127 // all gracefully closed / error-out before we try to shut the Context down. |
98 mojo::shell::Context shell_context; | 128 mojo::shell::Context shell_context; |
99 { | 129 { |
100 base::MessageLoop message_loop; | 130 base::MessageLoop message_loop; |
101 if (!shell_context.Init()) { | 131 if (!shell_context.Init()) { |
| 132 Usage(); |
102 return 0; | 133 return 0; |
103 } | 134 } |
104 if (g_tracing) { | 135 if (g_tracing) { |
105 message_loop.PostDelayedTask(FROM_HERE, | 136 message_loop.PostDelayedTask(FROM_HERE, |
106 base::Bind(StopTracingAndFlushToDisk), | 137 base::Bind(StopTracingAndFlushToDisk), |
107 base::TimeDelta::FromSeconds(5)); | 138 base::TimeDelta::FromSeconds(5)); |
108 } | 139 } |
109 | 140 |
110 message_loop.PostTask(FROM_HERE, | 141 // // The mojo_shell --args-for command-line switch is handled specially |
111 base::Bind(&StartWindowManager, &shell_context)); | 142 // // because it can appear more than once. The base::CommandLine class |
| 143 // // collapses multiple occurrences of the same switch. |
| 144 // for (int i = 1; i < argc; i++) { |
| 145 // ApplyApplicationArgs(&shell_context, argv[i]); |
| 146 // } |
| 147 |
| 148 if (command_line.HasSwitch(switches::kTestApp)) { |
| 149 message_loop.PostTask( |
| 150 FROM_HERE, |
| 151 base::Bind(&mojo::shell::RunCommandLineApps, &shell_context)); |
| 152 } else { |
| 153 message_loop.PostTask( |
| 154 FROM_HERE, |
| 155 base::Bind(&StartWindowManager, &shell_context)); |
| 156 } |
112 message_loop.Run(); | 157 message_loop.Run(); |
113 | 158 |
114 // Must be called before |message_loop| is destroyed. | 159 // Must be called before |message_loop| is destroyed. |
115 shell_context.Shutdown(); | 160 shell_context.Shutdown(); |
116 } | 161 } |
117 | 162 |
118 if (g_tracing) | 163 if (g_tracing) |
119 StopTracingAndFlushToDisk(); | 164 StopTracingAndFlushToDisk(); |
120 return 0; | 165 return 0; |
121 } | 166 } |
122 | 167 |
123 } // namespace shell | 168 } // namespace shell |
124 } // namespace mojo | 169 } // namespace mojo |
OLD | NEW |