blob: 6c9bedb64fb1eb2ba9c8e5928efedcbc91beecc8 [file] [log] [blame]
Przemyslaw Pietrzkiewicz1d909942015-08-28 16:27:56 +02001// 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#ifndef APPS_BENCHMARK_TRACE_COORDINATOR_CLIENT_H_
6#define APPS_BENCHMARK_TRACE_COORDINATOR_CLIENT_H_
7
8#include <memory>
9#include <string>
10
11#include "base/memory/scoped_ptr.h"
12#include "mojo/data_pipe_utils/data_pipe_drainer.h"
Viet-Trung Luu0f4f3ba2015-10-10 01:08:40 -070013#include "mojo/services/tracing/interfaces/tracing.mojom.h"
Przemyslaw Pietrzkiewicz1d909942015-08-28 16:27:56 +020014
15// Connects to trace collector in tracing.mojo to get traces and returns the
16// results as a single string to the receiver.
17class TraceCollectorClient : public mojo::common::DataPipeDrainer::Client {
18 public:
19 class Receiver {
20 public:
21 // |trace_data| will be a JSON list of the collected trace events.
22 virtual void OnTraceCollected(std::string trace_data) = 0;
23
24 protected:
25 virtual ~Receiver() {}
26 };
27
28 TraceCollectorClient(Receiver* receiver,
29 tracing::TraceCollectorPtr collector);
30 ~TraceCollectorClient() override;
31
32 void Start(const std::string& categories);
33 void Stop();
34
35 private:
36 // mojo::common:DataPipeDrainer:
37 void OnDataAvailable(const void* data, size_t num_bytes) override;
38 void OnDataComplete() override;
39
40 Receiver* receiver_;
41 tracing::TraceCollectorPtr collector_;
42 scoped_ptr<mojo::common::DataPipeDrainer> drainer_;
43 std::string trace_data_;
44 bool currently_tracing_;
45
46 DISALLOW_COPY_AND_ASSIGN(TraceCollectorClient);
47};
48
49#endif // APPS_BENCHMARK_TRACE_COORDINATOR_CLIENT_H_