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/path_service.h" | |
17 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
18 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
19 #include "components/tracing/trace_config_file.h" | 18 #include "components/tracing/trace_config_file.h" |
20 #include "components/tracing/tracing_switches.h" | 19 #include "components/tracing/tracing_switches.h" |
21 #include "mojo/runner/context.h" | 20 #include "mojo/runner/context.h" |
22 #include "mojo/runner/switches.h" | 21 #include "mojo/runner/switches.h" |
23 | 22 |
24 namespace mojo { | 23 namespace mojo { |
25 namespace runner { | 24 namespace runner { |
26 namespace { | 25 namespace { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 trace_config, base::trace_event::TraceLog::RECORDING_MODE); | 91 trace_config, base::trace_event::TraceLog::RECORDING_MODE); |
93 } else if (tracing::TraceConfigFile::GetInstance()->IsEnabled()) { | 92 } else if (tracing::TraceConfigFile::GetInstance()->IsEnabled()) { |
94 g_tracing = true; | 93 g_tracing = true; |
95 base::trace_event::TraceLog::GetInstance()->SetEnabled( | 94 base::trace_event::TraceLog::GetInstance()->SetEnabled( |
96 tracing::TraceConfigFile::GetInstance()->GetTraceConfig(), | 95 tracing::TraceConfigFile::GetInstance()->GetTraceConfig(), |
97 base::trace_event::TraceLog::RECORDING_MODE); | 96 base::trace_event::TraceLog::RECORDING_MODE); |
98 } | 97 } |
99 | 98 |
100 // We want the shell::Context to outlive the MessageLoop so that pipes are | 99 // We want the shell::Context to outlive the MessageLoop so that pipes are |
101 // all gracefully closed / error-out before we try to shut the Context down. | 100 // all gracefully closed / error-out before we try to shut the Context down. |
102 base::FilePath shell_dir; | 101 Context shell_context; |
103 PathService::Get(base::DIR_MODULE, &shell_dir); | |
104 Context shell_context(shell_dir); | |
105 { | 102 { |
106 base::MessageLoop message_loop; | 103 base::MessageLoop message_loop; |
107 if (!shell_context.Init()) { | 104 if (!shell_context.Init()) { |
108 return 0; | 105 return 0; |
109 } | 106 } |
110 if (g_tracing) { | 107 if (g_tracing) { |
111 message_loop.PostDelayedTask(FROM_HERE, | 108 message_loop.PostDelayedTask(FROM_HERE, |
112 base::Bind(StopTracingAndFlushToDisk), | 109 base::Bind(StopTracingAndFlushToDisk), |
113 base::TimeDelta::FromSeconds(5)); | 110 base::TimeDelta::FromSeconds(5)); |
114 } | 111 } |
115 | 112 |
116 message_loop.PostTask( | 113 message_loop.PostTask( |
117 FROM_HERE, | 114 FROM_HERE, |
118 base::Bind(&Context::RunCommandLineApplication, | 115 base::Bind(&Context::RunCommandLineApplication, |
119 base::Unretained(&shell_context), base::Closure())); | 116 base::Unretained(&shell_context), base::Closure())); |
120 message_loop.Run(); | 117 message_loop.Run(); |
121 | 118 |
122 // Must be called before |message_loop| is destroyed. | 119 // Must be called before |message_loop| is destroyed. |
123 shell_context.Shutdown(); | 120 shell_context.Shutdown(); |
124 } | 121 } |
125 | 122 |
126 if (g_tracing) | 123 if (g_tracing) |
127 StopTracingAndFlushToDisk(); | 124 StopTracingAndFlushToDisk(); |
128 return 0; | 125 return 0; |
129 } | 126 } |
130 | 127 |
131 } // namespace runner | 128 } // namespace runner |
132 } // namespace mojo | 129 } // namespace mojo |
OLD | NEW |