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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 #if !defined(NDEBUG) || !defined(ENABLE_PROFILING) | 84 #if !defined(NDEBUG) || !defined(ENABLE_PROFILING) |
85 LOG(ERROR) << "Profiling requires is_debug=false and " | 85 LOG(ERROR) << "Profiling requires is_debug=false and " |
86 << "enable_profiling=true. Continuing without profiling."; | 86 << "enable_profiling=true. Continuing without profiling."; |
87 // StartProfiling() and StopProfiling() are a no-op. | 87 // StartProfiling() and StopProfiling() are a no-op. |
88 #endif | 88 #endif |
89 base::debug::StartProfiling("mojo_shell.pprof"); | 89 base::debug::StartProfiling("mojo_shell.pprof"); |
90 } | 90 } |
91 | 91 |
92 // We want the shell::Context to outlive the MessageLoop so that pipes are all | 92 // We want the shell::Context to outlive the MessageLoop so that pipes are all |
93 // gracefully closed / error-out before we try to shut the Context down. | 93 // gracefully closed / error-out before we try to shut the Context down. |
94 shell::Context shell_context; | 94 shell::Context shell_context(&tracer); |
95 { | 95 { |
96 base::MessageLoop message_loop; | 96 base::MessageLoop message_loop; |
97 if (!shell_context.Init()) { | |
98 Usage(); | |
99 return 1; | |
100 } | |
101 | |
102 if (trace_startup) { | 97 if (trace_startup) { |
103 message_loop.PostDelayedTask( | 98 message_loop.PostDelayedTask( |
104 FROM_HERE, base::Bind(&shell::Tracer::StopAndFlushToFile, | 99 FROM_HERE, base::Bind(&shell::Tracer::StopAndFlushToFile, |
105 base::Unretained(&tracer), "mojo_shell.trace"), | 100 base::Unretained(&tracer), "mojo_shell.trace"), |
106 base::TimeDelta::FromSeconds(5)); | 101 base::TimeDelta::FromSeconds(5)); |
107 } | 102 } |
108 | 103 |
104 if (!shell_context.Init()) { | |
viettrungluu
2015/04/27 17:04:11
I don't know if the sketchy failure case is compat
jamesr
2015/04/27 23:46:57
I think it's OK - even here the message_loop goes
| |
105 Usage(); | |
106 return 1; | |
107 } | |
108 | |
109 // The mojo_shell --args-for command-line switch is handled specially | 109 // The mojo_shell --args-for command-line switch is handled specially |
110 // because it can appear more than once. The base::CommandLine class | 110 // because it can appear more than once. The base::CommandLine class |
111 // collapses multiple occurrences of the same switch. | 111 // collapses multiple occurrences of the same switch. |
112 for (int i = 1; i < argc; i++) | 112 for (int i = 1; i < argc; i++) |
113 ApplyApplicationArgs(&shell_context, argv[i]); | 113 ApplyApplicationArgs(&shell_context, argv[i]); |
114 | 114 |
115 message_loop.PostTask( | 115 message_loop.PostTask( |
116 FROM_HERE, base::Bind(&shell::RunCommandLineApps, &shell_context)); | 116 FROM_HERE, base::Bind(&shell::RunCommandLineApps, &shell_context)); |
117 message_loop.Run(); | 117 message_loop.Run(); |
118 | 118 |
119 // Must be called before |message_loop| is destroyed. | 119 // Must be called before |message_loop| is destroyed. |
120 shell_context.Shutdown(); | 120 shell_context.Shutdown(); |
121 } | 121 } |
122 | 122 |
123 if (command_line.HasSwitch(switches::kCPUProfile)) | 123 if (command_line.HasSwitch(switches::kCPUProfile)) |
124 base::debug::StopProfiling(); | 124 base::debug::StopProfiling(); |
125 if (trace_startup) | 125 if (trace_startup) |
126 tracer.StopAndFlushToFile("mojo_shell.trace"); | 126 tracer.StopAndFlushToFile("mojo_shell.trace"); |
127 return 0; | 127 return 0; |
128 } | 128 } |
OLD | NEW |