Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1082)

Unified Diff: mojo/services/tracing/trace_data_sink.cc

Issue 1049993002: Get mojo_shell building inside chromium checkout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix presubmit Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/services/tracing/trace_data_sink.h ('k') | mojo/services/tracing/tracing.mojom » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/services/tracing/trace_data_sink.cc
diff --git a/mojo/services/tracing/trace_data_sink.cc b/mojo/services/tracing/trace_data_sink.cc
new file mode 100644
index 0000000000000000000000000000000000000000..151a9d3c9fa26c798d0d82ee5a75efaeebeb5e48
--- /dev/null
+++ b/mojo/services/tracing/trace_data_sink.cc
@@ -0,0 +1,43 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/services/tracing/trace_data_sink.h"
+
+#include "base/logging.h"
+#include "mojo/common/data_pipe_utils.h"
+
+using mojo::common::BlockingCopyFromString;
+
+namespace tracing {
+namespace {
+
+const char kStart[] = "{\"traceEvents\":[";
+const char kEnd[] = "]}";
+
+} // namespace
+
+TraceDataSink::TraceDataSink(mojo::ScopedDataPipeProducerHandle pipe)
+ : pipe_(pipe.Pass()), empty_(true) {
+ BlockingCopyFromString(kStart, pipe_);
+}
+
+TraceDataSink::~TraceDataSink() {
+ if (pipe_.is_valid())
+ Flush();
+ DCHECK(!pipe_.is_valid());
+}
+
+void TraceDataSink::AddChunk(const std::string& json) {
+ if (!empty_)
+ BlockingCopyFromString(",", pipe_);
+ empty_ = false;
+ BlockingCopyFromString(json, pipe_);
+}
+
+void TraceDataSink::Flush() {
+ BlockingCopyFromString(kEnd, pipe_);
+ pipe_.reset();
+}
+
+} // namespace tracing
« no previous file with comments | « mojo/services/tracing/trace_data_sink.h ('k') | mojo/services/tracing/tracing.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698