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 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // 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. |
69 // Spin up a new thread to flush things out. | 69 // Spin up a new thread to flush things out. |
70 base::Thread flush_thread("mojo_shell_trace_event_flush"); | 70 base::Thread flush_thread("mojo_shell_trace_event_flush"); |
71 flush_thread.Start(); | 71 flush_thread.Start(); |
72 flush_thread.message_loop()->PostTask( | 72 flush_thread.message_loop()->PostTask( |
73 FROM_HERE, | 73 FROM_HERE, |
74 base::Bind(EndTraceAndFlush, base::Unretained(&flush_complete_event))); | 74 base::Bind(EndTraceAndFlush, base::Unretained(&flush_complete_event))); |
75 flush_complete_event.Wait(); | 75 flush_complete_event.Wait(); |
76 } | 76 } |
77 | 77 |
78 void StartApp(mojo::runner::Context* context) { | |
79 // If a mojo app isn't specified (i.e. for an apptest), run the mojo shell's | |
80 // window manager. | |
81 GURL app_url(GURL("mojo:window_manager")); | |
82 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
83 base::CommandLine::StringVector args = command_line->GetArgs(); | |
84 for (size_t i = 0; i < args.size(); ++i) { | |
85 GURL possible_app(args[i]); | |
86 if (possible_app.SchemeIs("mojo")) { | |
87 app_url = possible_app; | |
88 break; | |
89 } | |
90 } | |
91 | |
92 context->Run(app_url); | |
93 } | |
94 | |
95 } // namespace | 78 } // namespace |
96 | 79 |
97 int LauncherProcessMain(int argc, char** argv) { | 80 int LauncherProcessMain(int argc, char** argv) { |
98 const base::CommandLine& command_line = | 81 const base::CommandLine& command_line = |
99 *base::CommandLine::ForCurrentProcess(); | 82 *base::CommandLine::ForCurrentProcess(); |
100 if (command_line.HasSwitch(switches::kTraceStartup)) { | 83 if (command_line.HasSwitch(switches::kTraceStartup)) { |
101 g_tracing = true; | 84 g_tracing = true; |
102 base::trace_event::CategoryFilter category_filter( | 85 base::trace_event::CategoryFilter category_filter( |
103 command_line.GetSwitchValueASCII(switches::kTraceStartup)); | 86 command_line.GetSwitchValueASCII(switches::kTraceStartup)); |
104 base::trace_event::TraceLog::GetInstance()->SetEnabled( | 87 base::trace_event::TraceLog::GetInstance()->SetEnabled( |
105 category_filter, base::trace_event::TraceLog::RECORDING_MODE, | 88 category_filter, base::trace_event::TraceLog::RECORDING_MODE, |
106 base::trace_event::TraceOptions(base::trace_event::RECORD_UNTIL_FULL)); | 89 base::trace_event::TraceOptions(base::trace_event::RECORD_UNTIL_FULL)); |
107 } | 90 } |
108 | 91 |
109 // 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 |
110 // 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. |
111 Context shell_context; | 94 Context shell_context; |
112 { | 95 { |
113 base::MessageLoop message_loop; | 96 base::MessageLoop message_loop; |
114 if (!shell_context.Init()) { | 97 if (!shell_context.Init()) { |
115 return 0; | 98 return 0; |
116 } | 99 } |
117 if (g_tracing) { | 100 if (g_tracing) { |
118 message_loop.PostDelayedTask(FROM_HERE, | 101 message_loop.PostDelayedTask(FROM_HERE, |
119 base::Bind(StopTracingAndFlushToDisk), | 102 base::Bind(StopTracingAndFlushToDisk), |
120 base::TimeDelta::FromSeconds(5)); | 103 base::TimeDelta::FromSeconds(5)); |
121 } | 104 } |
122 | 105 |
123 message_loop.PostTask(FROM_HERE, base::Bind(&StartApp, &shell_context)); | 106 message_loop.PostTask(FROM_HERE, |
| 107 base::Bind(&Context::RunCommandLineApplication, |
| 108 base::Unretained(&shell_context))); |
124 message_loop.Run(); | 109 message_loop.Run(); |
125 | 110 |
126 // Must be called before |message_loop| is destroyed. | 111 // Must be called before |message_loop| is destroyed. |
127 shell_context.Shutdown(); | 112 shell_context.Shutdown(); |
128 } | 113 } |
129 | 114 |
130 if (g_tracing) | 115 if (g_tracing) |
131 StopTracingAndFlushToDisk(); | 116 StopTracingAndFlushToDisk(); |
132 return 0; | 117 return 0; |
133 } | 118 } |
134 | 119 |
135 } // namespace runner | 120 } // namespace runner |
136 } // namespace mojo | 121 } // namespace mojo |
OLD | NEW |