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

Side by Side Diff: services/resource_coordinator/tracing/agent_registry.h

Issue 2891973003: tracing: the agent registry implementation (Closed)
Patch Set: review Created 3 years, 7 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
OLDNEW
(Empty)
1 // Copyright 2017 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_RESOURCE_COORDINATOR_TRACING_AGENT_REGISTRY_H_
6 #define SERVICES_RESOURCE_COORDINATOR_TRACING_AGENT_REGISTRY_H_
7
8 #include <map>
9 #include <memory>
10 #include <string>
11
12 #include "base/callback_forward.h"
13 #include "base/macros.h"
14 #include "base/threading/thread_checker.h"
15 #include "mojo/public/cpp/bindings/binding_set.h"
16 #include "services/resource_coordinator/public/interfaces/tracing/tracing.mojom. h"
17 #include "services/service_manager/public/cpp/bind_source_info.h"
18
19 namespace tracing {
20
21 class AgentRegistry : public mojom::AgentRegistry {
22 public:
23 class AgentEntry {
24 public:
25 AgentEntry(size_t id,
26 AgentRegistry* agent_registry,
27 mojom::AgentPtr agent,
28 const std::string& label,
29 mojom::TraceDataType type,
30 bool supports_explicit_clock_sync);
31 ~AgentEntry();
32
33 // Currently, at most one callback when the tracing agent is disconnected is
34 // enough. We can generalize this later if several parts of the service need
35 // to get notified when an agent disconnects.
36 void SetDisconnectClosure(base::OnceClosure closure);
37 bool RemoveDisconnectClosure();
38
39 mojom::Agent* agent() const { return agent_.get(); }
40 const std::string& label() const { return label_; }
41 mojom::TraceDataType type() const { return type_; }
42 bool supports_explicit_clock_sync() const {
43 return supports_explicit_clock_sync_;
44 }
45
46 private:
47 void OnConnectionError();
48
49 const size_t id_;
50 AgentRegistry* agent_registry_;
51 mojom::AgentPtr agent_;
52 const std::string label_;
53 const mojom::TraceDataType type_;
54 const bool supports_explicit_clock_sync_;
55 base::OnceClosure closure_;
56
57 DISALLOW_COPY_AND_ASSIGN(AgentEntry);
58 };
59
60 // A function to be run for every agent that registers itself.
61 using AgentInitializationCallback =
62 base::RepeatingCallback<void(AgentEntry*)>;
63
64 static AgentRegistry* GetInstance();
65
66 AgentRegistry();
67
68 void BindAgentRegistryRequest(
69 const service_manager::BindSourceInfo& source_info,
70 mojom::AgentRegistryRequest request);
71 void SetAgentInitializationCallback(
72 const AgentInitializationCallback& callback);
73 void RemoveAgentInitializationCallback();
74
75 template <typename FunctionType>
76 void ForAllAgents(FunctionType function) {
77 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
78 for (const auto& key_value : agents_) {
79 function(key_value.second.get());
80 }
81 }
82
83 private:
84 friend std::default_delete<AgentRegistry>;
85 friend class AgentRegistryTest; // For testing.
86
87 ~AgentRegistry() override;
88
89 // mojom::AgentRegistry
90 void RegisterAgent(mojom::AgentPtr agent,
91 const std::string& label,
92 mojom::TraceDataType type,
93 bool supports_explicit_clock_sync) override;
94
95 void UnregisterAgent(size_t agent_id);
96
97 mojo::BindingSet<mojom::AgentRegistry> bindings_;
98 size_t next_agent_id_ = 0;
99 std::map<size_t, std::unique_ptr<AgentEntry>> agents_;
100 AgentInitializationCallback agent_initialization_callback_;
101
102 THREAD_CHECKER(thread_checker_);
103
104 DISALLOW_COPY_AND_ASSIGN(AgentRegistry);
105 };
106
107 } // namespace tracing
108
109 #endif // SERVICES_RESOURCE_COORDINATOR_TRACING_AGENT_REGISTRY_H_
OLDNEW
« no previous file with comments | « services/resource_coordinator/tracing/BUILD.gn ('k') | services/resource_coordinator/tracing/agent_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698