1 // Copyright 2019 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 SERVICES_TRACING_PUBLIC_CPP_TRACED_PROCESS_IMPL_H_ 6 #define SERVICES_TRACING_PUBLIC_CPP_TRACED_PROCESS_IMPL_H_ 7 8 #include <set> 9 #include <string> 10 11 #include "base/component_export.h" 12 #include "base/no_destructor.h" 13 #include "base/sequence_checker.h" 14 #include "mojo/public/cpp/bindings/remote.h" 15 #include "services/tracing/public/mojom/traced_process.mojom.h" 16 17 namespace tracing { 18 19 class BaseAgent; 20 21 // Each running process will bind this singleton 22 // to the mojom::TracedProcess interface, which will be 23 // connected to by the tracing service to enable tracing 24 // support. COMPONENT_EXPORT(TRACING_CPP)25class COMPONENT_EXPORT(TRACING_CPP) TracedProcessImpl 26 : public mojom::TracedProcess { 27 public: 28 static TracedProcessImpl* GetInstance(); 29 30 void ResetTracedProcessReceiver(); 31 void OnTracedProcessRequest( 32 mojo::PendingReceiver<mojom::TracedProcess> receiver); 33 34 // Set which taskrunner to bind any incoming requests on. 35 void SetTaskRunner(scoped_refptr<base::SequencedTaskRunner> task_runner); 36 37 void RegisterAgent(BaseAgent* agent); 38 void UnregisterAgent(BaseAgent* agent); 39 40 // Populate categories from all of the registered agents. 41 void GetCategories(std::set<std::string>* category_set); 42 43 private: 44 friend class base::NoDestructor<TracedProcessImpl>; 45 TracedProcessImpl(); 46 ~TracedProcessImpl() override; 47 48 // tracing::mojom::TracedProcess: 49 void ConnectToTracingService( 50 mojom::ConnectToTracingRequestPtr request, 51 ConnectToTracingServiceCallback callback) override; 52 53 std::set<BaseAgent*> agents_; 54 mojo::Receiver<tracing::mojom::TracedProcess> receiver_{this}; 55 scoped_refptr<base::SequencedTaskRunner> task_runner_; 56 57 SEQUENCE_CHECKER(sequence_checker_); 58 DISALLOW_COPY_AND_ASSIGN(TracedProcessImpl); 59 }; 60 61 } // namespace tracing 62 63 #endif // SERVICES_TRACING_PUBLIC_CPP_TRACED_PROCESS_IMPL_H_ 64