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

Side by Side Diff: services/tracing/trace_data_sink.cc

Issue 962703003: Add using mojo::common::BlockingCopyFromString (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 4
5 #include "services/tracing/trace_data_sink.h" 5 #include "services/tracing/trace_data_sink.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "mojo/common/data_pipe_utils.h" 8 #include "mojo/common/data_pipe_utils.h"
9 9
10 using mojo::common::BlockingCopyFromString;
11
10 namespace tracing { 12 namespace tracing {
11 namespace { 13 namespace {
12 14
13 const char kStart[] = "{\"traceEvents\":["; 15 const char kStart[] = "{\"traceEvents\":[";
14 const char kEnd[] = "]}"; 16 const char kEnd[] = "]}";
15 17
16 } // namespace 18 } // namespace
17 19
18 TraceDataSink::TraceDataSink(mojo::ScopedDataPipeProducerHandle pipe) 20 TraceDataSink::TraceDataSink(mojo::ScopedDataPipeProducerHandle pipe)
19 : pipe_(pipe.Pass()), empty_(true) { 21 : pipe_(pipe.Pass()), empty_(true) {
20 mojo::common::BlockingCopyFromString(kStart, pipe_); 22 BlockingCopyFromString(kStart, pipe_);
21 } 23 }
22 24
23 TraceDataSink::~TraceDataSink() { 25 TraceDataSink::~TraceDataSink() {
24 if (pipe_.is_valid()) 26 if (pipe_.is_valid())
25 Flush(); 27 Flush();
26 DCHECK(!pipe_.is_valid()); 28 DCHECK(!pipe_.is_valid());
27 } 29 }
28 30
29 void TraceDataSink::AddChunk(const std::string& json) { 31 void TraceDataSink::AddChunk(const std::string& json) {
30 if (!empty_) 32 if (!empty_)
31 mojo::common::BlockingCopyFromString(",", pipe_); 33 BlockingCopyFromString(",", pipe_);
32 empty_ = false; 34 empty_ = false;
33 mojo::common::BlockingCopyFromString(json, pipe_); 35 BlockingCopyFromString(json, pipe_);
34 } 36 }
35 37
36 void TraceDataSink::Flush() { 38 void TraceDataSink::Flush() {
37 mojo::common::BlockingCopyFromString(kEnd, pipe_); 39 BlockingCopyFromString(kEnd, pipe_);
38 pipe_.reset(); 40 pipe_.reset();
39 } 41 }
40 42
41 } // namespace tracing 43 } // namespace tracing
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698