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

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

Issue 2833873003: WIP: The tracing service prototype
Patch Set: sync 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_SET_IMPL_H_
6 #define SERVICES_RESOURCE_COORDINATOR_TRACING_AGENT_SET_IMPL_H_
7
8 #include "base/callback_forward.h"
9 #include "mojo/public/cpp/bindings/binding_set.h"
10 #include "services/resource_coordinator/public/interfaces/tracing/tracing.mojom. h"
11 #include "services/service_manager/public/cpp/bind_source_info.h"
12
13 namespace resource_coordinator {
14 namespace tracing {
15
16 class AgentSetImpl : public mojom::AgentSet {
17 public:
18 class Entry {
19 public:
20 Entry(size_t id,
21 AgentSetImpl* agent_set,
22 mojom::AgentPtr agent,
23 const std::string& label,
24 mojom::TraceDataType type,
25 bool supports_explicit_clock_sync);
26 ~Entry();
27
28 mojom::Agent* agent() const { return agent_.get(); }
29 const std::string& label() const { return label_; }
30 mojom::TraceDataType type() const { return type_; }
31 bool supports_explicit_clock_sync() const {
32 return supports_explicit_clock_sync_;
33 }
34
35 void AddDisconnectClosure(const std::string& closure_type,
36 base::OnceClosure closure);
37 bool RemoveDisconnectClosure(const std::string& closure_type);
38 void OnConnectionError();
39
40 private:
41 const size_t id_;
42 AgentSetImpl* agent_set_;
43 mojom::AgentPtr agent_;
44 const std::string label_;
45 const mojom::TraceDataType type_;
46 const bool supports_explicit_clock_sync_;
47
48 std::unordered_map<std::string, base::OnceClosure> closures_;
49 DISALLOW_COPY_AND_ASSIGN(Entry);
50 };
51
52 typedef base::RepeatingCallback<void(Entry*)> AgentProcessingCallback;
53
54 // The getter of the unique instance.
55 static AgentSetImpl* GetInstance();
56
57 AgentSetImpl();
58
59 void BindAgentSetRequest(const service_manager::BindSourceInfo& source_info,
60 mojom::AgentSetRequest request);
61 void SetAgentProcessingCallback(const AgentProcessingCallback& callback);
62 void ResetAgentProcessingCallback();
63
64 template <typename FunctionType>
65 void ForAllAgents(FunctionType function) {
66 for (const auto& key_value : agents_) {
67 function(key_value.second.get());
68 }
69 }
70
71 private:
72 friend std::default_delete<AgentSetImpl>;
73
74 ~AgentSetImpl() override;
75
76 // mojom::AgentSet
77 void RegisterAgent(mojom::AgentPtr agent,
78 const std::string& label,
79 mojom::TraceDataType type,
80 bool supports_explicit_clock_sync) override;
81
82 void UnregisterAgent(size_t agent_id);
83
84 mojo::BindingSet<mojom::AgentSet> bindings_;
85 size_t next_agent_id_ = 0;
86 std::unordered_map<size_t, std::unique_ptr<Entry>> agents_;
87 AgentProcessingCallback agent_processing_callback_;
88 DISALLOW_COPY_AND_ASSIGN(AgentSetImpl);
89 };
90
91 } // namespace tracing
92 } // namespace resource_coordinator
93
94 #endif // SERVICES_RESOURCE_COORDINATOR_TRACING_AGENT_SET_IMPL_H_
OLDNEW
« no previous file with comments | « services/resource_coordinator/tracing/BUILD.gn ('k') | services/resource_coordinator/tracing/agent_set_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698