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/runner/context.h" | 18 #include "mojo/runner/context.h" |
19 #include "mojo/runner/switches.h" | 19 #include "mojo/runner/switches.h" |
20 | 20 |
21 namespace mojo { | 21 namespace mojo { |
22 namespace shell { | 22 namespace runner { |
23 namespace { | 23 namespace { |
24 | 24 |
25 // Whether we're currently tracing. | 25 // Whether we're currently tracing. |
26 bool g_tracing = false; | 26 bool g_tracing = false; |
27 | 27 |
28 // Number of tracing blocks written. | 28 // Number of tracing blocks written. |
29 uint32_t g_blocks = 0; | 29 uint32_t g_blocks = 0; |
30 | 30 |
31 // Trace file, if open. | 31 // Trace file, if open. |
32 FILE* g_trace_file = nullptr; | 32 FILE* g_trace_file = nullptr; |
(...skipping 35 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::shell::Context* context) { | 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 | 79 // If a mojo app isn't specified (i.e. for an apptest), run the mojo shell's |
80 // window manager. | 80 // window manager. |
81 GURL app_url(GURL("mojo:window_manager")); | 81 GURL app_url(GURL("mojo:window_manager")); |
82 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 82 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
83 base::CommandLine::StringVector args = command_line->GetArgs(); | 83 base::CommandLine::StringVector args = command_line->GetArgs(); |
84 for (size_t i = 0; i < args.size(); ++i) { | 84 for (size_t i = 0; i < args.size(); ++i) { |
85 GURL possible_app(args[i]); | 85 GURL possible_app(args[i]); |
86 if (possible_app.SchemeIs("mojo")) { | 86 if (possible_app.SchemeIs("mojo")) { |
87 app_url = possible_app; | 87 app_url = possible_app; |
88 break; | 88 break; |
(...skipping 12 matching lines...) Expand all Loading... |
101 g_tracing = true; | 101 g_tracing = true; |
102 base::trace_event::CategoryFilter category_filter( | 102 base::trace_event::CategoryFilter category_filter( |
103 command_line.GetSwitchValueASCII(switches::kTraceStartup)); | 103 command_line.GetSwitchValueASCII(switches::kTraceStartup)); |
104 base::trace_event::TraceLog::GetInstance()->SetEnabled( | 104 base::trace_event::TraceLog::GetInstance()->SetEnabled( |
105 category_filter, base::trace_event::TraceLog::RECORDING_MODE, | 105 category_filter, base::trace_event::TraceLog::RECORDING_MODE, |
106 base::trace_event::TraceOptions(base::trace_event::RECORD_UNTIL_FULL)); | 106 base::trace_event::TraceOptions(base::trace_event::RECORD_UNTIL_FULL)); |
107 } | 107 } |
108 | 108 |
109 // We want the shell::Context to outlive the MessageLoop so that pipes are | 109 // 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. | 110 // all gracefully closed / error-out before we try to shut the Context down. |
111 mojo::shell::Context shell_context; | 111 Context shell_context; |
112 { | 112 { |
113 base::MessageLoop message_loop; | 113 base::MessageLoop message_loop; |
114 if (!shell_context.Init()) { | 114 if (!shell_context.Init()) { |
115 return 0; | 115 return 0; |
116 } | 116 } |
117 if (g_tracing) { | 117 if (g_tracing) { |
118 message_loop.PostDelayedTask(FROM_HERE, | 118 message_loop.PostDelayedTask(FROM_HERE, |
119 base::Bind(StopTracingAndFlushToDisk), | 119 base::Bind(StopTracingAndFlushToDisk), |
120 base::TimeDelta::FromSeconds(5)); | 120 base::TimeDelta::FromSeconds(5)); |
121 } | 121 } |
122 | 122 |
123 message_loop.PostTask(FROM_HERE, base::Bind(&StartApp, &shell_context)); | 123 message_loop.PostTask(FROM_HERE, base::Bind(&StartApp, &shell_context)); |
124 message_loop.Run(); | 124 message_loop.Run(); |
125 | 125 |
126 // Must be called before |message_loop| is destroyed. | 126 // Must be called before |message_loop| is destroyed. |
127 shell_context.Shutdown(); | 127 shell_context.Shutdown(); |
128 } | 128 } |
129 | 129 |
130 if (g_tracing) | 130 if (g_tracing) |
131 StopTracingAndFlushToDisk(); | 131 StopTracingAndFlushToDisk(); |
132 return 0; | 132 return 0; |
133 } | 133 } |
134 | 134 |
135 } // namespace shell | 135 } // namespace runner |
136 } // namespace mojo | 136 } // namespace mojo |
OLD | NEW |