summaryrefslogtreecommitdiff
path: root/chromium/services/tracing/data_sink.cc
blob: dcd71844bd594b06956a5809e93530c4dcdccd1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// 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 "services/tracing/data_sink.h"

#include <utility>

#include "base/logging.h"
#include "mojo/common/data_pipe_utils.h"

using mojo::common::BlockingCopyFromString;

namespace tracing {

DataSink::DataSink(mojo::ScopedDataPipeProducerHandle pipe)
    : pipe_(std::move(pipe)), empty_(true) {}

DataSink::~DataSink() {
  if (pipe_.is_valid())
    pipe_.reset();
  DCHECK(!pipe_.is_valid());
}

void DataSink::AddChunk(const std::string& json) {
  if (!empty_)
    BlockingCopyFromString(",", pipe_);
  empty_ = false;
  BlockingCopyFromString(json, pipe_);
}

}  // namespace tracing