Index: services/resource_coordinator/coordination_unit/coordination_unit_impl.h |
diff --git a/services/resource_coordinator/coordination_unit/coordination_unit_impl.h b/services/resource_coordinator/coordination_unit/coordination_unit_impl.h |
index 492c34c973d6afb55e3b48731f36963b74304af1..af6e92fffb7c6d465f8299028b0f78b2c9665808 100644 |
--- a/services/resource_coordinator/coordination_unit/coordination_unit_impl.h |
+++ b/services/resource_coordinator/coordination_unit/coordination_unit_impl.h |
@@ -14,6 +14,7 @@ |
#include <vector> |
#include "base/callback.h" |
+#include "base/observer_list.h" |
#include "base/optional.h" |
#include "base/values.h" |
#include "mojo/public/cpp/bindings/binding_set.h" |
@@ -29,60 +30,6 @@ namespace resource_coordinator { |
class CoordinationUnitGraphObserver; |
-// Collection to manage CoordinationUnitEvent listeners. |
-template <typename Filter> |
-class CoordinationUnitGraphObserverRegistry { |
- public: |
- CoordinationUnitGraphObserverRegistry() = default; |
- ~CoordinationUnitGraphObserverRegistry() = default; |
- |
- // callbacks paired with this kNoFilter will always be invoked |
- static const Filter kNoFilter = static_cast<Filter>(0); |
- |
- void AddObserver(CoordinationUnitGraphObserver* observer, Filter filter) { |
- registry_[filter].push_back(observer); |
- } |
- |
- void AddObserver(CoordinationUnitGraphObserver* observer) { |
- AddObserver(observer, kNoFilter); |
- } |
- |
- // Get the observers who are are either registered to be invoked for |
- // a specific filter or were registered with the kNoFilter. |
- // TODO(matthalp) add iterator support to replace this call and |
- // avoid excessive copying that currently occurs |
- std::vector<CoordinationUnitGraphObserver*> GetObserversForFilter( |
- Filter filter) { |
- std::vector<CoordinationUnitGraphObserver*> observers; |
- |
- // Get listeners registered with a listener first. |
- AppendObservers(&observers, filter); |
- |
- // Get listeners registered without a filter after. |
- if (filter != kNoFilter) { |
- AppendObservers(&observers, kNoFilter); |
- } |
- |
- return observers; |
- } |
- |
- std::vector<CoordinationUnitGraphObserver*> GetObserversWithoutAFilter() { |
- return GetObserversForFilter(kNoFilter); |
- } |
- |
- private: |
- void AppendObservers(std::vector<CoordinationUnitGraphObserver*>* observers, |
- Filter filter) { |
- observers->insert(observers->end(), registry_[filter].begin(), |
- registry_[filter].end()); |
- } |
- |
- // TODO(matthalp) Consider using a std::unordered_map instead. |
- std::map<Filter, std::vector<CoordinationUnitGraphObserver*>> registry_; |
- |
- DISALLOW_COPY_AND_ASSIGN(CoordinationUnitGraphObserverRegistry); |
-}; |
- |
class CoordinationUnitImpl : public mojom::CoordinationUnit { |
public: |
CoordinationUnitImpl( |
@@ -119,26 +66,9 @@ class CoordinationUnitImpl : public mojom::CoordinationUnit { |
// Set property from internal key-value store |
void SetProperty(mojom::PropertyType property, base::Value value); |
- // Notify an instance it will be destroyed before its destructor is |
- // actually called. |
void WillBeDestroyed(); |
- |
- void ObserveOnChildAddedEvent(CoordinationUnitGraphObserver* observer, |
- CoordinationUnitType child_filter); |
- void ObserveOnChildAddedEvent(CoordinationUnitGraphObserver* observer); |
- void ObserveOnParentAddedEvent(CoordinationUnitGraphObserver* observer, |
- CoordinationUnitType parent_filter); |
- void ObserveOnParentAddedEvent(CoordinationUnitGraphObserver* observer); |
- void ObserveOnPropertyChangedEvent(CoordinationUnitGraphObserver* observer, |
- mojom::PropertyType property_filter); |
- void ObserveOnPropertyChangedEvent(CoordinationUnitGraphObserver* observer); |
- void ObserveOnChildRemovedEvent(CoordinationUnitGraphObserver* observer, |
- CoordinationUnitType child_filter); |
- void ObserveOnChildRemovedEvent(CoordinationUnitGraphObserver* observer); |
- void ObserveOnParentRemovedEvent(CoordinationUnitGraphObserver* observer, |
- CoordinationUnitType parent_filter); |
- void ObserveOnParentRemovedEvent(CoordinationUnitGraphObserver* observer); |
- void ObserveOnWillBeDestroyedEvent(CoordinationUnitGraphObserver* observer); |
+ void AddObserver(CoordinationUnitGraphObserver* observer); |
+ void RemoveObserver(CoordinationUnitGraphObserver* observer); |
protected: |
const CoordinationUnitID id_; |
@@ -173,22 +103,9 @@ class CoordinationUnitImpl : public mojom::CoordinationUnit { |
mojom::CoordinationPolicyCallbackPtr policy_callback_; |
mojom::CoordinationPolicyPtr current_policy_; |
- base::Optional<bool> state_flags_[kNumStateFlags]; |
+ base::ObserverList<CoordinationUnitGraphObserver> observers_; |
- CoordinationUnitGraphObserverRegistry<CoordinationUnitType> |
- on_child_added_event_observer_registry_; |
- CoordinationUnitGraphObserverRegistry<CoordinationUnitType> |
- on_parent_added_event_observer_registry_; |
- CoordinationUnitGraphObserverRegistry<CoordinationUnitType> |
- on_child_removed_event_observer_registry_; |
- CoordinationUnitGraphObserverRegistry<CoordinationUnitType> |
- on_parent_removed_event_observer_registry_; |
- CoordinationUnitGraphObserverRegistry<mojom::PropertyType> |
- on_property_changed_event_observer_registry_; |
- // There is nothing to filter WillBeDestroyedEventCallbacks on so the |
- // CoordinationUnitType is used as a filter placeholder |
- CoordinationUnitGraphObserverRegistry<CoordinationUnitType> |
- on_will_be_destroyed_event_observer_registry_; |
+ base::Optional<bool> state_flags_[kNumStateFlags]; |
DISALLOW_COPY_AND_ASSIGN(CoordinationUnitImpl); |
}; |