Chromium Code Reviews| 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 "content/browser/devtools/protocol/tracing_handler.h" | 5 #include "content/browser/devtools/protocol/tracing_handler.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 if (TracingHandler* h = tracing_handler_.get()) | 85 if (TracingHandler* h = tracing_handler_.get()) |
| 86 h->OnTraceComplete(); | 86 h->OnTraceComplete(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 private: | 89 private: |
| 90 ~DevToolsTraceSinkProxy() override {} | 90 ~DevToolsTraceSinkProxy() override {} |
| 91 | 91 |
| 92 base::WeakPtr<TracingHandler> tracing_handler_; | 92 base::WeakPtr<TracingHandler> tracing_handler_; |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 class DevToolsStreamTraceSink : public TracingController::TraceDataSink { | 95 class DevToolsStreamEndpoint : public TraceDataEndpoint { |
| 96 public: | 96 public: |
| 97 explicit DevToolsStreamTraceSink( | 97 explicit DevToolsStreamEndpoint( |
| 98 base::WeakPtr<TracingHandler> handler, | 98 base::WeakPtr<TracingHandler> handler, |
| 99 const scoped_refptr<DevToolsIOContext::Stream>& stream) | 99 const scoped_refptr<DevToolsIOContext::Stream>& stream) |
| 100 : stream_(stream), | 100 : stream_(stream), tracing_handler_(handler) {} |
| 101 tracing_handler_(handler), | |
| 102 first_chunk_(true) {} | |
| 103 | 101 |
| 104 void AddTraceChunk(const std::string& chunk) override { | 102 void ReceiveTraceChunk(std::unique_ptr<std::string> chunk) override { |
| 105 // FIXME: change interface to pass chunks as refcounted strings. | 103 stream_->Append(std::move(chunk)); |
| 106 scoped_refptr<base::RefCountedString> ref_counted_chunk | |
| 107 = new base::RefCountedString(); | |
| 108 std::string prefix = first_chunk_ ? "[" : ","; | |
| 109 ref_counted_chunk->data() = prefix + chunk; | |
| 110 first_chunk_ = false; | |
| 111 stream_->Append(ref_counted_chunk); | |
| 112 } | 104 } |
| 113 | 105 |
| 114 void Close() override { | 106 void ReceiveTraceFinalContents( |
| 115 if (TracingHandler* h = tracing_handler_.get()) { | 107 std::unique_ptr<const base::DictionaryValue> metadata) override { |
|
dgozman
2016/07/19 01:53:14
Don't you want to send metadata as well?
| |
| 116 std::string suffix = "]"; | 108 if (TracingHandler* h = tracing_handler_.get()) |
| 117 stream_->Append(base::RefCountedString::TakeString(&suffix)); | |
| 118 h->OnTraceToStreamComplete(stream_->handle()); | 109 h->OnTraceToStreamComplete(stream_->handle()); |
| 119 } | |
| 120 } | 110 } |
| 121 | 111 |
| 122 private: | 112 private: |
| 123 ~DevToolsStreamTraceSink() override {} | 113 ~DevToolsStreamEndpoint() override {} |
| 124 | 114 |
| 125 scoped_refptr<DevToolsIOContext::Stream> stream_; | 115 scoped_refptr<DevToolsIOContext::Stream> stream_; |
| 126 base::WeakPtr<TracingHandler> tracing_handler_; | 116 base::WeakPtr<TracingHandler> tracing_handler_; |
| 127 bool first_chunk_; | |
| 128 }; | 117 }; |
| 129 | 118 |
| 130 } // namespace | 119 } // namespace |
| 131 | 120 |
| 132 TracingHandler::TracingHandler(TracingHandler::Target target, | 121 TracingHandler::TracingHandler(TracingHandler::Target target, |
| 133 int frame_tree_node_id, | 122 int frame_tree_node_id, |
| 134 DevToolsIOContext* io_context) | 123 DevToolsIOContext* io_context) |
| 135 : target_(target), | 124 : target_(target), |
| 136 io_context_(io_context), | 125 io_context_(io_context), |
| 137 frame_tree_node_id_(frame_tree_node_id), | 126 frame_tree_node_id_(frame_tree_node_id), |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 return target_ == Renderer ? Response::FallThrough() : Response::OK(); | 203 return target_ == Renderer ? Response::FallThrough() : Response::OK(); |
| 215 } | 204 } |
| 216 | 205 |
| 217 Response TracingHandler::End(DevToolsCommandId command_id) { | 206 Response TracingHandler::End(DevToolsCommandId command_id) { |
| 218 // Startup tracing triggered by --trace-config-file is a special case, where | 207 // Startup tracing triggered by --trace-config-file is a special case, where |
| 219 // tracing is started automatically upon browser startup and can be stopped | 208 // tracing is started automatically upon browser startup and can be stopped |
| 220 // via DevTools. | 209 // via DevTools. |
| 221 if (!did_initiate_recording_ && !IsStartupTracingActive()) | 210 if (!did_initiate_recording_ && !IsStartupTracingActive()) |
| 222 return Response::InternalError("Tracing is not started"); | 211 return Response::InternalError("Tracing is not started"); |
| 223 | 212 |
| 224 scoped_refptr<TracingController::TraceDataSink> proxy; | 213 scoped_refptr<TracingController::TraceDataSink> sink; |
| 225 if (return_as_stream_) { | 214 if (return_as_stream_) { |
| 226 proxy = new DevToolsStreamTraceSink( | 215 sink = TracingControllerImpl::CreateJSONSink(new DevToolsStreamEndpoint( |
| 227 weak_factory_.GetWeakPtr(), io_context_->CreateTempFileBackedStream()); | 216 weak_factory_.GetWeakPtr(), io_context_->CreateTempFileBackedStream())); |
| 228 } else { | 217 } else { |
| 229 proxy = new DevToolsTraceSinkProxy(weak_factory_.GetWeakPtr()); | 218 sink = new DevToolsTraceSinkProxy(weak_factory_.GetWeakPtr()); |
| 230 } | 219 } |
| 231 StopTracing(proxy); | 220 StopTracing(sink); |
| 232 // If inspected target is a render process Tracing.end will be handled by | 221 // If inspected target is a render process Tracing.end will be handled by |
| 233 // tracing agent in the renderer. | 222 // tracing agent in the renderer. |
| 234 return target_ == Renderer ? Response::FallThrough() : Response::OK(); | 223 return target_ == Renderer ? Response::FallThrough() : Response::OK(); |
| 235 } | 224 } |
| 236 | 225 |
| 237 Response TracingHandler::GetCategories(DevToolsCommandId command_id) { | 226 Response TracingHandler::GetCategories(DevToolsCommandId command_id) { |
| 238 TracingController::GetInstance()->GetCategories( | 227 TracingController::GetInstance()->GetCategories( |
| 239 base::Bind(&TracingHandler::OnCategoriesReceived, | 228 base::Bind(&TracingHandler::OnCategoriesReceived, |
| 240 weak_factory_.GetWeakPtr(), | 229 weak_factory_.GetWeakPtr(), |
| 241 command_id)); | 230 command_id)); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 std::string mode; | 337 std::string mode; |
| 349 if (tracing_dict->GetString(kRecordModeParam, &mode)) | 338 if (tracing_dict->GetString(kRecordModeParam, &mode)) |
| 350 tracing_dict->SetString(kRecordModeParam, ConvertFromCamelCase(mode, '-')); | 339 tracing_dict->SetString(kRecordModeParam, ConvertFromCamelCase(mode, '-')); |
| 351 | 340 |
| 352 return base::trace_event::TraceConfig(*tracing_dict); | 341 return base::trace_event::TraceConfig(*tracing_dict); |
| 353 } | 342 } |
| 354 | 343 |
| 355 } // namespace tracing | 344 } // namespace tracing |
| 356 } // namespace devtools | 345 } // namespace devtools |
| 357 } // namespace content | 346 } // namespace content |
| OLD | NEW |