| OLD | NEW | 
|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include <utility> | 4 #include <utility> | 
| 5 | 5 | 
| 6 #include "base/bind.h" | 6 #include "base/bind.h" | 
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" | 
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" | 
| 9 #include "base/macros.h" | 9 #include "base/macros.h" | 
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" | 
| 11 #include "base/strings/pattern.h" | 11 #include "base/strings/pattern.h" | 
| 12 #include "content/browser/tracing/tracing_controller_impl.h" | 12 #include "content/browser/tracing/tracing_controller_impl.h" | 
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" | 
| 14 #include "third_party/zlib/zlib.h" | 14 #include "third_party/zlib/zlib.h" | 
| 15 | 15 | 
| 16 namespace content { | 16 namespace content { | 
| 17 | 17 | 
| 18 namespace { | 18 namespace { | 
| 19 | 19 | 
| 20 const char kChromeTraceLabel[] = "traceEvents"; | 20 const char kChromeTraceLabelStr[] = "traceEvents"; | 
| 21 const char kMetadataTraceLabel[] = "metadata"; | 21 const char kMetadataTraceLabel[] = "metadata"; | 
| 22 | 22 | 
| 23 class StringTraceDataEndpoint : public TraceDataEndpoint { | 23 class StringTraceDataEndpoint : public TraceDataEndpoint { | 
| 24  public: | 24  public: | 
| 25   typedef base::Callback<void(std::unique_ptr<const base::DictionaryValue>, | 25   typedef base::Callback<void(std::unique_ptr<const base::DictionaryValue>, | 
| 26                               base::RefCountedString*)> | 26                               base::RefCountedString*)> | 
| 27       CompletionCallback; | 27       CompletionCallback; | 
| 28 | 28 | 
| 29   explicit StringTraceDataEndpoint(CompletionCallback callback) | 29   explicit StringTraceDataEndpoint(CompletionCallback callback) | 
| 30       : completion_callback_(callback) {} | 30       : completion_callback_(callback) {} | 
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 143 class JSONTraceDataSink : public TraceDataSinkImplBase { | 143 class JSONTraceDataSink : public TraceDataSinkImplBase { | 
| 144  public: | 144  public: | 
| 145   explicit JSONTraceDataSink(scoped_refptr<TraceDataEndpoint> endpoint) | 145   explicit JSONTraceDataSink(scoped_refptr<TraceDataEndpoint> endpoint) | 
| 146       : endpoint_(endpoint), had_received_first_chunk_(false) {} | 146       : endpoint_(endpoint), had_received_first_chunk_(false) {} | 
| 147 | 147 | 
| 148   void AddTraceChunk(const std::string& chunk) override { | 148   void AddTraceChunk(const std::string& chunk) override { | 
| 149     std::string trace_string; | 149     std::string trace_string; | 
| 150     if (had_received_first_chunk_) | 150     if (had_received_first_chunk_) | 
| 151       trace_string = ","; | 151       trace_string = ","; | 
| 152     else | 152     else | 
| 153       trace_string = "{\"" + std::string(kChromeTraceLabel) + "\":["; | 153       trace_string = "{\"" + std::string(kChromeTraceLabelStr) + "\":["; | 
| 154     trace_string += chunk; | 154     trace_string += chunk; | 
| 155     had_received_first_chunk_ = true; | 155     had_received_first_chunk_ = true; | 
| 156 | 156 | 
| 157     endpoint_->ReceiveTraceChunk(base::MakeUnique<std::string>(trace_string)); | 157     endpoint_->ReceiveTraceChunk(base::MakeUnique<std::string>(trace_string)); | 
| 158   } | 158   } | 
| 159 | 159 | 
| 160   void Close() override { | 160   void Close() override { | 
| 161     endpoint_->ReceiveTraceChunk(base::MakeUnique<std::string>("]")); | 161     endpoint_->ReceiveTraceChunk(base::MakeUnique<std::string>("]")); | 
| 162 | 162 | 
| 163     for (auto const &it : GetAgentTrace()) | 163     for (auto const &it : GetAgentTrace()) | 
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 337   return new StringTraceDataEndpoint(callback); | 337   return new StringTraceDataEndpoint(callback); | 
| 338 } | 338 } | 
| 339 | 339 | 
| 340 scoped_refptr<TracingController::TraceDataSink> | 340 scoped_refptr<TracingController::TraceDataSink> | 
| 341 TracingControllerImpl::CreateJSONSink( | 341 TracingControllerImpl::CreateJSONSink( | 
| 342     scoped_refptr<TraceDataEndpoint> endpoint) { | 342     scoped_refptr<TraceDataEndpoint> endpoint) { | 
| 343   return new JSONTraceDataSink(endpoint); | 343   return new JSONTraceDataSink(endpoint); | 
| 344 } | 344 } | 
| 345 | 345 | 
| 346 }  // namespace content | 346 }  // namespace content | 
| OLD | NEW | 
|---|