OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "apps/benchmark/trace_collector_client.h" |
| 6 |
| 7 TraceCollectorClient::TraceCollectorClient(Receiver* receiver, |
| 8 tracing::TraceCollectorPtr collector) |
| 9 : receiver_(receiver), |
| 10 collector_(collector.Pass()), |
| 11 currently_tracing_(false) {} |
| 12 |
| 13 TraceCollectorClient::~TraceCollectorClient() {} |
| 14 |
| 15 void TraceCollectorClient::Start(const std::string& categories) { |
| 16 DCHECK(!currently_tracing_); |
| 17 currently_tracing_ = true; |
| 18 mojo::DataPipe data_pipe; |
| 19 collector_->Start(data_pipe.producer_handle.Pass(), categories); |
| 20 drainer_.reset(new mojo::common::DataPipeDrainer( |
| 21 this, data_pipe.consumer_handle.Pass())); |
| 22 trace_data_.clear(); |
| 23 trace_data_ += "["; |
| 24 } |
| 25 |
| 26 void TraceCollectorClient::Stop() { |
| 27 DCHECK(currently_tracing_); |
| 28 currently_tracing_ = false; |
| 29 collector_->StopAndFlush(); |
| 30 } |
| 31 |
| 32 void TraceCollectorClient::OnDataAvailable(const void* data, size_t num_bytes) { |
| 33 const char* chars = static_cast<const char*>(data); |
| 34 trace_data_.append(chars, num_bytes); |
| 35 } |
| 36 |
| 37 void TraceCollectorClient::OnDataComplete() { |
| 38 drainer_.reset(); |
| 39 collector_.reset(); |
| 40 trace_data_ += "]"; |
| 41 receiver_->OnTraceCollected(trace_data_); |
| 42 } |
OLD | NEW |