Index: services/resource_coordinator/tracing/agent_set_impl.h |
diff --git a/services/resource_coordinator/tracing/agent_set_impl.h b/services/resource_coordinator/tracing/agent_set_impl.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0f0ccd4aac5714c6313a00e1d55c9f804d431771 |
--- /dev/null |
+++ b/services/resource_coordinator/tracing/agent_set_impl.h |
@@ -0,0 +1,94 @@ |
+// Copyright 2017 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_RESOURCE_COORDINATOR_TRACING_AGENT_SET_IMPL_H_ |
+#define SERVICES_RESOURCE_COORDINATOR_TRACING_AGENT_SET_IMPL_H_ |
+ |
+#include "base/callback_forward.h" |
+#include "mojo/public/cpp/bindings/binding_set.h" |
+#include "services/resource_coordinator/public/interfaces/tracing/tracing.mojom.h" |
+#include "services/service_manager/public/cpp/bind_source_info.h" |
+ |
+namespace resource_coordinator { |
+namespace tracing { |
+ |
+class AgentSetImpl : public mojom::AgentSet { |
+ public: |
+ class Entry { |
+ public: |
+ Entry(size_t id, |
+ AgentSetImpl* agent_set, |
+ mojom::AgentPtr agent, |
+ const std::string& label, |
+ mojom::TraceDataType type, |
+ bool supports_explicit_clock_sync); |
+ ~Entry(); |
+ |
+ mojom::Agent* agent() const { return agent_.get(); } |
+ const std::string& label() const { return label_; } |
+ mojom::TraceDataType type() const { return type_; } |
+ bool supports_explicit_clock_sync() const { |
+ return supports_explicit_clock_sync_; |
+ } |
+ |
+ void AddDisconnectClosure(const std::string& closure_type, |
+ base::OnceClosure closure); |
+ bool RemoveDisconnectClosure(const std::string& closure_type); |
+ void OnConnectionError(); |
+ |
+ private: |
+ const size_t id_; |
+ AgentSetImpl* agent_set_; |
+ mojom::AgentPtr agent_; |
+ const std::string label_; |
+ const mojom::TraceDataType type_; |
+ const bool supports_explicit_clock_sync_; |
+ |
+ std::unordered_map<std::string, base::OnceClosure> closures_; |
+ DISALLOW_COPY_AND_ASSIGN(Entry); |
+ }; |
+ |
+ typedef base::RepeatingCallback<void(Entry*)> AgentProcessingCallback; |
+ |
+ // The getter of the unique instance. |
+ static AgentSetImpl* GetInstance(); |
+ |
+ AgentSetImpl(); |
+ |
+ void BindAgentSetRequest(const service_manager::BindSourceInfo& source_info, |
+ mojom::AgentSetRequest request); |
+ void SetAgentProcessingCallback(const AgentProcessingCallback& callback); |
+ void ResetAgentProcessingCallback(); |
+ |
+ template <typename FunctionType> |
+ void ForAllAgents(FunctionType function) { |
+ for (const auto& key_value : agents_) { |
+ function(key_value.second.get()); |
+ } |
+ } |
+ |
+ private: |
+ friend std::default_delete<AgentSetImpl>; |
+ |
+ ~AgentSetImpl() override; |
+ |
+ // mojom::AgentSet |
+ void RegisterAgent(mojom::AgentPtr agent, |
+ const std::string& label, |
+ mojom::TraceDataType type, |
+ bool supports_explicit_clock_sync) override; |
+ |
+ void UnregisterAgent(size_t agent_id); |
+ |
+ mojo::BindingSet<mojom::AgentSet> bindings_; |
+ size_t next_agent_id_ = 0; |
+ std::unordered_map<size_t, std::unique_ptr<Entry>> agents_; |
+ AgentProcessingCallback agent_processing_callback_; |
+ DISALLOW_COPY_AND_ASSIGN(AgentSetImpl); |
+}; |
+ |
+} // namespace tracing |
+} // namespace resource_coordinator |
+ |
+#endif // SERVICES_RESOURCE_COORDINATOR_TRACING_AGENT_SET_IMPL_H_ |