OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <algorithm> | |
6 | |
5 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | |
6 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
7 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
9 #include "mojo/application/application_runner_chromium.h" | 12 #include "mojo/application/application_runner_chromium.h" |
10 #include "mojo/public/c/system/main.h" | 13 #include "mojo/public/c/system/main.h" |
11 #include "mojo/public/cpp/application/application_delegate.h" | 14 #include "mojo/public/cpp/application/application_delegate.h" |
12 #include "mojo/public/cpp/application/application_impl.h" | 15 #include "mojo/public/cpp/application/application_impl.h" |
13 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
14 #include "net/server/http_server.h" | 17 #include "net/server/http_server.h" |
15 #include "net/server/http_server_request_info.h" | 18 #include "net/server/http_server_request_info.h" |
16 #include "net/socket/tcp_server_socket.h" | 19 #include "net/socket/tcp_server_socket.h" |
17 #include "services/tracing/tracing.mojom.h" | 20 #include "services/tracing/tracing.mojom.h" |
18 #include "sky/tools/debugger/debugger.mojom.h" | 21 #include "sky/tools/debugger/debugger.mojom.h" |
22 #include "sky/tools/debugger/prompt/trace_collector.h" | |
19 | 23 |
20 namespace sky { | 24 namespace sky { |
21 namespace debugger { | 25 namespace debugger { |
26 namespace { | |
22 | 27 |
23 class Prompt : public mojo::ApplicationDelegate, public net::HttpServer::Delegat e { | 28 const size_t kMinSendBufferSize = 1024 * 1024; |
29 } | |
30 | |
31 class Prompt : public mojo::ApplicationDelegate, | |
32 public net::HttpServer::Delegate { | |
24 public: | 33 public: |
25 Prompt() | 34 Prompt() |
26 : is_tracing_(false), | 35 : is_tracing_(false), |
27 weak_ptr_factory_(this) { | 36 weak_ptr_factory_(this) { |
28 } | 37 } |
29 virtual ~Prompt() { | 38 virtual ~Prompt() { |
30 } | 39 } |
31 | 40 |
32 private: | 41 private: |
33 // Overridden from mojo::ApplicationDelegate: | 42 // Overridden from mojo::ApplicationDelegate: |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 int connection_id, const net::HttpServerRequestInfo& info) override { | 100 int connection_id, const net::HttpServerRequestInfo& info) override { |
92 web_server_->Send500(connection_id, "http only"); | 101 web_server_->Send500(connection_id, "http only"); |
93 } | 102 } |
94 | 103 |
95 void OnWebSocketMessage( | 104 void OnWebSocketMessage( |
96 int connection_id, const std::string& data) override { | 105 int connection_id, const std::string& data) override { |
97 web_server_->Send500(connection_id, "http only"); | 106 web_server_->Send500(connection_id, "http only"); |
98 } | 107 } |
99 | 108 |
100 void Respond(int connection_id, std::string response) { | 109 void Respond(int connection_id, std::string response) { |
110 web_server_->SetSendBufferSize( | |
eseidel
2015/01/16 00:07:25
You should expain why you're donig this in a comme
abarth-chromium
2015/01/16 00:31:53
Done.
| |
111 connection_id, std::max(kMinSendBufferSize, response.length())); | |
101 web_server_->Send200(connection_id, response, "text/plain"); | 112 web_server_->Send200(connection_id, response, "text/plain"); |
102 } | 113 } |
103 | 114 |
104 void Help(std::string path, int connection_id) { | 115 void Help(std::string path, int connection_id) { |
105 std::string help = base::StringPrintf("Sky Debugger running on port %d\n" | 116 std::string help = base::StringPrintf("Sky Debugger running on port %d\n" |
106 "Supported URLs:\n" | 117 "Supported URLs:\n" |
107 "/toggle_tracing -- Start/stop tracing\n" | 118 "/toggle_tracing -- Start/stop tracing\n" |
108 "/reload -- Reload the current page\n" | 119 "/reload -- Reload the current page\n" |
109 "/inspect -- Start inspector server for current page\n" | 120 "/inspect -- Start inspector server for current page\n" |
110 "/quit -- Quit\n" | 121 "/quit -- Quit\n" |
(...skipping 20 matching lines...) Expand all Loading... | |
131 Respond(connection_id, | 142 Respond(connection_id, |
132 "Open the following URL in Chrome:\n" | 143 "Open the following URL in Chrome:\n" |
133 "chrome-devtools://devtools/bundled/devtools.html?ws=localhost:9898\n"); | 144 "chrome-devtools://devtools/bundled/devtools.html?ws=localhost:9898\n"); |
134 } | 145 } |
135 | 146 |
136 void Quit(int connection_id) { | 147 void Quit(int connection_id) { |
137 debugger_->Shutdown(); | 148 debugger_->Shutdown(); |
138 } | 149 } |
139 | 150 |
140 void ToggleTracing(int connection_id) { | 151 void ToggleTracing(int connection_id) { |
141 std::string response; | 152 bool was_tracing = is_tracing_; |
142 if (is_tracing_) { | 153 is_tracing_ = !is_tracing_; |
143 response = "Stopping trace (writing to sky_viewer.trace)\n"; | 154 |
155 if (was_tracing) { | |
144 tracing_->StopAndFlush(); | 156 tracing_->StopAndFlush(); |
145 } else { | 157 trace_collector_->GetTrace(base::Bind( |
146 response = "Starting trace (type 'trace' to stop tracing)\n"; | 158 &Prompt::OnTraceAvailable, base::Unretained(this), connection_id)); |
147 tracing_->Start(mojo::String("sky_viewer"), mojo::String("*")); | 159 return; |
148 } | 160 } |
149 is_tracing_ = !is_tracing_; | 161 |
150 Respond(connection_id, response); | 162 mojo::DataPipe pipe; |
163 tracing_->Start(pipe.producer_handle.Pass(), mojo::String("*")); | |
164 trace_collector_.reset(new TraceCollector(pipe.consumer_handle.Pass())); | |
165 Respond(connection_id, "Starting trace (type 'trace' to stop tracing)\n"); | |
166 } | |
167 | |
168 void OnTraceAvailable(int connection_id, std::string trace) { | |
169 trace_collector_.reset(); | |
170 Respond(connection_id, trace); | |
151 } | 171 } |
152 | 172 |
153 bool is_tracing_; | 173 bool is_tracing_; |
154 DebuggerPtr debugger_; | 174 DebuggerPtr debugger_; |
155 tracing::TraceCoordinatorPtr tracing_; | 175 tracing::TraceCoordinatorPtr tracing_; |
156 std::string url_; | 176 std::string url_; |
157 base::WeakPtrFactory<Prompt> weak_ptr_factory_; | 177 base::WeakPtrFactory<Prompt> weak_ptr_factory_; |
158 scoped_ptr<net::HttpServer> web_server_; | 178 scoped_ptr<net::HttpServer> web_server_; |
159 uint32_t command_port_; | 179 uint32_t command_port_; |
160 | 180 |
181 scoped_ptr<TraceCollector> trace_collector_; | |
182 | |
161 DISALLOW_COPY_AND_ASSIGN(Prompt); | 183 DISALLOW_COPY_AND_ASSIGN(Prompt); |
162 }; | 184 }; |
163 | 185 |
164 } // namespace debugger | 186 } // namespace debugger |
165 } // namespace sky | 187 } // namespace sky |
166 | 188 |
167 MojoResult MojoMain(MojoHandle shell_handle) { | 189 MojoResult MojoMain(MojoHandle shell_handle) { |
168 mojo::ApplicationRunnerChromium runner(new sky::debugger::Prompt); | 190 mojo::ApplicationRunnerChromium runner(new sky::debugger::Prompt); |
169 runner.set_message_loop_type(base::MessageLoop::TYPE_IO); | 191 runner.set_message_loop_type(base::MessageLoop::TYPE_IO); |
170 return runner.Run(shell_handle); | 192 return runner.Run(shell_handle); |
171 } | 193 } |
OLD | NEW |