OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mojo/services/tracing/trace_data_sink.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "mojo/common/data_pipe_utils.h" |
| 9 |
| 10 using mojo::common::BlockingCopyFromString; |
| 11 |
| 12 namespace tracing { |
| 13 namespace { |
| 14 |
| 15 const char kStart[] = "{\"traceEvents\":["; |
| 16 const char kEnd[] = "]}"; |
| 17 |
| 18 } // namespace |
| 19 |
| 20 TraceDataSink::TraceDataSink(mojo::ScopedDataPipeProducerHandle pipe) |
| 21 : pipe_(pipe.Pass()), empty_(true) { |
| 22 BlockingCopyFromString(kStart, pipe_); |
| 23 } |
| 24 |
| 25 TraceDataSink::~TraceDataSink() { |
| 26 if (pipe_.is_valid()) |
| 27 Flush(); |
| 28 DCHECK(!pipe_.is_valid()); |
| 29 } |
| 30 |
| 31 void TraceDataSink::AddChunk(const std::string& json) { |
| 32 if (!empty_) |
| 33 BlockingCopyFromString(",", pipe_); |
| 34 empty_ = false; |
| 35 BlockingCopyFromString(json, pipe_); |
| 36 } |
| 37 |
| 38 void TraceDataSink::Flush() { |
| 39 BlockingCopyFromString(kEnd, pipe_); |
| 40 pipe_.reset(); |
| 41 } |
| 42 |
| 43 } // namespace tracing |
OLD | NEW |