Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "base/callback_forward.h" | |
| 9 #include "base/threading/thread_checker.h" | |
| 10 #include "mojo/public/cpp/bindings/binding_set.h" | |
| 11 #include "services/resource_coordinator/public/interfaces/tracing/tracing.mojom. h" | |
| 12 #include "services/service_manager/public/cpp/bind_source_info.h" | |
| 13 | |
| 14 namespace tracing { | |
| 15 | |
| 16 class AgentRegistry : public mojom::AgentRegistry { | |
|
oystein (OOO til 10th of July)
2017/05/25 17:16:08
s/AgentRegistry/AgentRegistryImpl/ as in the other
chiniforooshan
2017/05/26 15:46:31
As Ken mentioned in the other CL, looks like Agent
| |
| 17 public: | |
| 18 class Entry { | |
|
oystein (OOO til 10th of July)
2017/05/25 17:16:08
Any more verbose names that can be used for this?
chiniforooshan
2017/05/26 15:46:32
Done.
| |
| 19 public: | |
| 20 Entry(size_t id, | |
| 21 AgentRegistry* agent_registry, | |
| 22 mojom::AgentPtr agent, | |
| 23 const std::string& label, | |
| 24 mojom::TraceDataType type, | |
| 25 bool supports_explicit_clock_sync); | |
| 26 ~Entry(); | |
| 27 | |
| 28 // Currently, at most one callback when the tracing agent is disconnected is | |
| 29 // enough. We can generalize this later if several parts of the service need | |
| 30 // to get notified when an agent disconnects. | |
| 31 void SetDisconnectClosure(base::OnceClosure closure); | |
| 32 bool RemoveDisconnectClosure(); | |
| 33 | |
| 34 mojom::Agent* agent() const { return agent_.get(); } | |
| 35 const std::string& label() const { return label_; } | |
| 36 mojom::TraceDataType type() const { return type_; } | |
| 37 bool supports_explicit_clock_sync() const { | |
| 38 return supports_explicit_clock_sync_; | |
| 39 } | |
| 40 | |
| 41 private: | |
| 42 void OnConnectionError(); | |
| 43 | |
| 44 const size_t id_; | |
| 45 AgentRegistry* agent_registry_; | |
| 46 mojom::AgentPtr agent_; | |
| 47 const std::string label_; | |
| 48 const mojom::TraceDataType type_; | |
| 49 const bool supports_explicit_clock_sync_; | |
| 50 base::OnceClosure closure_; | |
| 51 | |
| 52 DISALLOW_COPY_AND_ASSIGN(Entry); | |
| 53 }; | |
| 54 | |
| 55 // A function to be run for every agent that registers itself. | |
| 56 typedef base::RepeatingCallback<void(Entry*)> AgentInitializationCallback; | |
|
Primiano Tucci (use gerrit)
2017/05/25 13:24:28
using AgentInitializationCallback = base....
chiniforooshan
2017/05/26 15:46:32
Done (I promise to remember this next time :p).
| |
| 57 | |
| 58 // The getter of the unique instance. | |
|
Primiano Tucci (use gerrit)
2017/05/25 13:24:28
I guess this is a quite common pattern in chrome s
chiniforooshan
2017/05/26 15:46:32
Done.
| |
| 59 static AgentRegistry* GetInstance(); | |
| 60 | |
| 61 AgentRegistry(); | |
| 62 | |
| 63 void BindAgentRegistryRequest( | |
| 64 const service_manager::BindSourceInfo& source_info, | |
| 65 mojom::AgentRegistryRequest request); | |
| 66 void SetAgentInitializationCallback( | |
| 67 const AgentInitializationCallback& callback); | |
| 68 void RemoveAgentInitializationCallback(); | |
| 69 | |
| 70 template <typename FunctionType> | |
| 71 void ForAllAgents(FunctionType function) { | |
| 72 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); | |
|
Primiano Tucci (use gerrit)
2017/05/25 13:24:28
is this really needed? It feels that without this
chiniforooshan
2017/05/26 15:46:31
This is the public method that gives access to the
| |
| 73 for (const auto& key_value : agents_) { | |
| 74 function(key_value.second.get()); | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 private: | |
| 79 friend std::default_delete<AgentRegistry>; | |
| 80 friend class AgentRegistryTest; // For testing. | |
| 81 | |
| 82 ~AgentRegistry() override; | |
| 83 | |
| 84 // mojom::AgentRegistry | |
|
Primiano Tucci (use gerrit)
2017/05/25 13:24:28
similar comment to the other CL. not sure if there
chiniforooshan
2017/05/26 15:46:32
My preference is to keep this private so that only
| |
| 85 void RegisterAgent(mojom::AgentPtr agent, | |
| 86 const std::string& label, | |
| 87 mojom::TraceDataType type, | |
| 88 bool supports_explicit_clock_sync) override; | |
| 89 | |
| 90 void UnregisterAgent(size_t agent_id); | |
| 91 | |
| 92 mojo::BindingSet<mojom::AgentRegistry> bindings_; | |
| 93 size_t next_agent_id_ = 0; | |
| 94 std::unordered_map<size_t, std::unique_ptr<Entry>> agents_; | |
|
Primiano Tucci (use gerrit)
2017/05/25 13:24:28
see brett's PSA on chromium-dev about unordered_ma
chiniforooshan
2017/05/26 15:46:32
Done.
| |
| 95 AgentInitializationCallback agent_initialization_callback_; | |
| 96 | |
| 97 THREAD_CHECKER(thread_checker_); | |
| 98 | |
| 99 DISALLOW_COPY_AND_ASSIGN(AgentRegistry); | |
|
oystein (OOO til 10th of July)
2017/05/25 17:16:08
nit: "base/macros.h"
chiniforooshan
2017/05/26 15:46:32
Done.
| |
| 100 }; | |
| 101 | |
| 102 } // namespace tracing | |
| 103 | |
| 104 #endif // SERVICES_RESOURCE_COORDINATOR_TRACING_AGENT_REGISTRY_H_ | |
| OLD | NEW |