Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: mojo/shell/desktop/launcher_process.cc

Issue 1057603003: Simplify mojo_shell since it's now only used for Mandoline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: default url Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
19 #include "mojo/shell/context.h" 18 #include "mojo/shell/context.h"
20 #include "mojo/shell/switches.h" 19 #include "mojo/shell/switches.h"
21 20
22 namespace mojo { 21 namespace mojo {
23 namespace shell { 22 namespace shell {
24 namespace { 23 namespace {
25 24
26 void Usage() {
27 std::cerr << "Launch Mojo applications.\n";
28 std::cerr
29 << "Usage: mojo_shell"
30 << " [--" << switches::kArgsFor << "=<mojo-app>]"
31 << " [--" << switches::kContentHandlers << "=<handlers>]"
32 << " [--" << switches::kDisableCache << "]"
33 << " [--" << switches::kEnableMultiprocess << "]"
34 << " [--" << switches::kOrigin << "=<url-lib-path>]"
35 << " [--" << switches::kTraceStartup << "]"
36 << " [--" << switches::kURLMappings << "=from1=to1,from2=to2]"
37 << " [--" << switches::kPredictableAppFilenames << "]"
38 << " [--" << switches::kWaitForDebugger << "]"
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
49 // Whether we're currently tracing. 25 // Whether we're currently tracing.
50 bool g_tracing = false; 26 bool g_tracing = false;
51 27
52 // Number of tracing blocks written. 28 // Number of tracing blocks written.
53 uint32_t g_blocks = 0; 29 uint32_t g_blocks = 0;
54 30
55 // Trace file, if open. 31 // Trace file, if open.
56 FILE* g_trace_file = nullptr; 32 FILE* g_trace_file = nullptr;
57 33
58 void WriteTraceDataCollected( 34 void WriteTraceDataCollected(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // TraceLog::Flush requires a message loop but we've already shut ours down. 68 // TraceLog::Flush requires a message loop but we've already shut ours down.
93 // Spin up a new thread to flush things out. 69 // Spin up a new thread to flush things out.
94 base::Thread flush_thread("mojo_shell_trace_event_flush"); 70 base::Thread flush_thread("mojo_shell_trace_event_flush");
95 flush_thread.Start(); 71 flush_thread.Start();
96 flush_thread.message_loop()->PostTask( 72 flush_thread.message_loop()->PostTask(
97 FROM_HERE, 73 FROM_HERE,
98 base::Bind(EndTraceAndFlush, base::Unretained(&flush_complete_event))); 74 base::Bind(EndTraceAndFlush, base::Unretained(&flush_complete_event)));
99 flush_complete_event.Wait(); 75 flush_complete_event.Wait();
100 } 76 }
101 77
78 void StartWindowManager(mojo::shell::Context* context) {
79 context->Run(GURL("mojo:window_manager"));
80 }
81
102 } // namespace 82 } // namespace
103 83
104 int LauncherProcessMain(int argc, char** argv) { 84 int LauncherProcessMain(int argc, char** argv) {
105 const base::CommandLine& command_line = 85 const base::CommandLine& command_line =
106 *base::CommandLine::ForCurrentProcess(); 86 *base::CommandLine::ForCurrentProcess();
107
108 const std::set<std::string> all_switches = switches::GetAllSwitches();
109 const base::CommandLine::SwitchMap switches = command_line.GetSwitches();
110 bool found_unknown_switch = false;
111 for (const auto& s : switches) {
112 if (all_switches.find(s.first) == all_switches.end()) {
113 std::cerr << "unknown switch: " << s.first << std::endl;
114 found_unknown_switch = true;
115 }
116 }
117
118 if (found_unknown_switch || command_line.HasSwitch(switches::kHelp) ||
119 command_line.GetArgs().empty()) {
120 Usage();
121 return 0;
122 }
123
124 if (command_line.HasSwitch(switches::kTraceStartup)) { 87 if (command_line.HasSwitch(switches::kTraceStartup)) {
125 g_tracing = true; 88 g_tracing = true;
126 base::trace_event::CategoryFilter category_filter( 89 base::trace_event::CategoryFilter category_filter(
127 command_line.GetSwitchValueASCII(switches::kTraceStartup)); 90 command_line.GetSwitchValueASCII(switches::kTraceStartup));
128 base::trace_event::TraceLog::GetInstance()->SetEnabled( 91 base::trace_event::TraceLog::GetInstance()->SetEnabled(
129 category_filter, base::trace_event::TraceLog::RECORDING_MODE, 92 category_filter, base::trace_event::TraceLog::RECORDING_MODE,
130 base::trace_event::TraceOptions(base::trace_event::RECORD_UNTIL_FULL)); 93 base::trace_event::TraceOptions(base::trace_event::RECORD_UNTIL_FULL));
131 } 94 }
132 95
133 // We want the shell::Context to outlive the MessageLoop so that pipes are 96 // We want the shell::Context to outlive the MessageLoop so that pipes are
134 // all gracefully closed / error-out before we try to shut the Context down. 97 // all gracefully closed / error-out before we try to shut the Context down.
135 mojo::shell::Context shell_context; 98 mojo::shell::Context shell_context;
136 { 99 {
137 base::MessageLoop message_loop; 100 base::MessageLoop message_loop;
138 if (!shell_context.Init()) { 101 if (!shell_context.Init()) {
139 Usage();
140 return 0; 102 return 0;
141 } 103 }
142 if (g_tracing) { 104 if (g_tracing) {
143 message_loop.PostDelayedTask(FROM_HERE, 105 message_loop.PostDelayedTask(FROM_HERE,
144 base::Bind(StopTracingAndFlushToDisk), 106 base::Bind(StopTracingAndFlushToDisk),
145 base::TimeDelta::FromSeconds(5)); 107 base::TimeDelta::FromSeconds(5));
146 } 108 }
147 109
148 // The mojo_shell --args-for command-line switch is handled specially 110 message_loop.PostTask(FROM_HERE,
149 // because it can appear more than once. The base::CommandLine class 111 base::Bind(&StartWindowManager, &shell_context));
150 // collapses multiple occurrences of the same switch.
151 for (int i = 1; i < argc; i++) {
152 ApplyApplicationArgs(&shell_context, argv[i]);
153 }
154
155 message_loop.PostTask(
156 FROM_HERE,
157 base::Bind(&mojo::shell::RunCommandLineApps, &shell_context));
158 message_loop.Run(); 112 message_loop.Run();
159 113
160 // Must be called before |message_loop| is destroyed. 114 // Must be called before |message_loop| is destroyed.
161 shell_context.Shutdown(); 115 shell_context.Shutdown();
162 } 116 }
163 117
164 if (g_tracing) 118 if (g_tracing)
165 StopTracingAndFlushToDisk(); 119 StopTracingAndFlushToDisk();
166 return 0; 120 return 0;
167 } 121 }
168 122
169 } // namespace shell 123 } // namespace shell
170 } // namespace mojo 124 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698