Index: base/debug/trace_event.cc |
diff --git a/base/debug/trace_event.cc b/base/debug/trace_event.cc |
index 347644f982ef3a4f3cd260b55a8b452e5217db3e..3e03d4afae69a0a909658a40f1b0ea70bf97c015 100644 |
--- a/base/debug/trace_event.cc |
+++ b/base/debug/trace_event.cc |
@@ -9,6 +9,7 @@ |
#if defined(OS_WIN) |
#include "base/debug/trace_event_win.h" |
#endif |
+#include "base/bind.h" |
#include "base/format_macros.h" |
#include "base/memory/ref_counted_memory.h" |
#include "base/process_util.h" |
@@ -224,13 +225,11 @@ void TraceEvent::AppendEventsAsJSON(const std::vector<TraceEvent>& events, |
size_t start, |
size_t count, |
std::string* out) { |
- *out += "["; |
for (size_t i = 0; i < count && start + i < events.size(); ++i) { |
if (i > 0) |
*out += ","; |
events[i + start].AppendAsJSON(out); |
} |
- *out += "]"; |
} |
void TraceEvent::AppendAsJSON(std::string* out) const { |
@@ -262,6 +261,48 @@ void TraceEvent::AppendAsJSON(std::string* out) const { |
//////////////////////////////////////////////////////////////////////////////// |
// |
+// TraceResultBuffer |
+// |
+//////////////////////////////////////////////////////////////////////////////// |
+ |
+TraceResultBuffer::OutputCallback |
+ TraceResultBuffer::SimpleOutput::GetCallback() { |
+ return base::Bind(&SimpleOutput::Append, base::Unretained(this)); |
+} |
+ |
+void TraceResultBuffer::SimpleOutput::Append( |
+ const std::string& json_trace_output) { |
+ json_output += json_trace_output; |
+} |
+ |
+TraceResultBuffer::TraceResultBuffer() : append_comma_(false) { |
+} |
+ |
+TraceResultBuffer::~TraceResultBuffer() { |
+} |
+ |
+void TraceResultBuffer::SetOutputCallback(OutputCallback json_chunk_callback) { |
+ output_callback_ = json_chunk_callback; |
+} |
+ |
+void TraceResultBuffer::Start() { |
+ append_comma_ = false; |
+ output_callback_.Run("["); |
+} |
+ |
+void TraceResultBuffer::AddFragment(const std::string& trace_fragment) { |
+ if (append_comma_) |
+ output_callback_.Run(","); |
+ append_comma_ = true; |
+ output_callback_.Run(trace_fragment); |
+} |
+ |
+void TraceResultBuffer::Finish() { |
+ output_callback_.Run("]"); |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// |
// TraceLog |
// |
//////////////////////////////////////////////////////////////////////////////// |