summaryrefslogtreecommitdiffstats
path: root/chromium/services/tracing/public/cpp/traced_process_impl.h
blob: 5d7a503a69ba3a26ed797ae58d19df0eb563cb25 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2019 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.

#ifndef SERVICES_TRACING_PUBLIC_CPP_TRACED_PROCESS_IMPL_H_
#define SERVICES_TRACING_PUBLIC_CPP_TRACED_PROCESS_IMPL_H_

#include <set>
#include <string>

#include "base/component_export.h"
#include "base/sequence_checker.h"
#include "base/synchronization/lock.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/tracing/public/mojom/tracing.mojom.h"

namespace tracing {

class BaseAgent;

// Each running process will bind this singleton
// to the mojom::TracedProcess interface, which will be
// connected to by the tracing service to enable tracing
// support.
class COMPONENT_EXPORT(TRACING_CPP) TracedProcessImpl
    : public mojom::TracedProcess {
 public:
  static TracedProcessImpl* GetInstance();

  void OnTracedProcessRequest(mojom::TracedProcessRequest request);

  // Set which taskrunner to bind any incoming requests on.
  void SetTaskRunner(scoped_refptr<base::SequencedTaskRunner> task_runner);

  void RegisterAgent(BaseAgent* agent);
  void UnregisterAgent(BaseAgent* agent);

  // Populate categories from all of the registered agents.
  void GetCategories(std::set<std::string>* category_set);

 private:
  friend class base::NoDestructor<TracedProcessImpl>;
  TracedProcessImpl();
  ~TracedProcessImpl() override;

  // tracing::mojom::TracedProcess:
  void ConnectToTracingService(
      mojom::ConnectToTracingRequestPtr request) override;

  // Lock protecting binding_.
  base::Lock lock_;
  std::set<BaseAgent*> agents_;
  tracing::mojom::AgentRegistryPtr agent_registry_;
  mojo::Binding<tracing::mojom::TracedProcess> binding_;
  scoped_refptr<base::SequencedTaskRunner> task_runner_;

  SEQUENCE_CHECKER(sequence_checker_);
  DISALLOW_COPY_AND_ASSIGN(TracedProcessImpl);
};

}  // namespace tracing

#endif  // SERVICES_TRACING_PUBLIC_CPP_TRACED_PROCESS_IMPL_H_