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

Unified Diff: services/resource_coordinator/coordination_unit/coordination_unit_impl.cc

Issue 2942403002: [GRC] Coordination Unit Graph Observer (Closed)
Patch Set: Fix unittest and OnCoordinationUnitWillBeDestroyed Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: services/resource_coordinator/coordination_unit/coordination_unit_impl.cc
diff --git a/services/resource_coordinator/coordination_unit/coordination_unit_impl.cc b/services/resource_coordinator/coordination_unit/coordination_unit_impl.cc
index 7fd56636949211c79a1ae042f7971728dae02021..277e110a1f5c9e88290022b5c26fa42ddc81c43a 100644
--- a/services/resource_coordinator/coordination_unit/coordination_unit_impl.cc
+++ b/services/resource_coordinator/coordination_unit/coordination_unit_impl.cc
@@ -162,10 +162,8 @@ bool CoordinationUnitImpl::AddChild(CoordinationUnitImpl* child) {
children_.count(child) ? false : children_.insert(child).second;
if (success) {
- for (auto* observer :
- on_child_added_event_observer_registry_.GetObserversForFilter(
- child->id().type)) {
- observer->OnChildAddedEvent(this, child);
+ for (auto& observer : observers_) {
+ observer.OnChildAdded(this, child);
}
}
@@ -196,10 +194,8 @@ bool CoordinationUnitImpl::RemoveChild(CoordinationUnitImpl* child) {
bool success = children_removed > 0;
if (success) {
- for (auto* observer :
- on_child_removed_event_observer_registry_.GetObserversForFilter(
- child->id().type)) {
- observer->OnChildRemovedEvent(this, child);
+ for (auto& observer : observers_) {
+ observer.OnChildRemoved(this, child);
}
}
@@ -210,10 +206,8 @@ void CoordinationUnitImpl::AddParent(CoordinationUnitImpl* parent) {
DCHECK_EQ(0u, parents_.count(parent));
parents_.insert(parent);
- for (auto* observer :
- on_parent_added_event_observer_registry_.GetObserversForFilter(
- parent->id().type)) {
- observer->OnParentAddedEvent(this, parent);
+ for (auto& observer : observers_) {
+ observer.OnParentAdded(this, parent);
}
RecalcCoordinationPolicy();
@@ -225,10 +219,8 @@ void CoordinationUnitImpl::RemoveParent(CoordinationUnitImpl* parent) {
// TODO(matthalp, oysteine) should this go before or
// after RecalcCoordinationPolicy?
- for (auto* observer :
- on_parent_removed_event_observer_registry_.GetObserversForFilter(
- parent->id().type)) {
- observer->OnParentRemovedEvent(this, parent);
+ for (auto& observer : observers_) {
+ observer.OnParentRemoved(this, parent);
}
RecalcCoordinationPolicy();
@@ -300,90 +292,25 @@ void CoordinationUnitImpl::SetProperty(mojom::PropertyType property,
property_store_[property] = value;
- for (auto* observer :
- on_property_changed_event_observer_registry_.GetObserversForFilter(
- property)) {
- observer->OnPropertyChangedEvent(this, property);
+ for (auto& observer : observers_) {
+ observer.OnPropertyChanged(this, property);
}
}
void CoordinationUnitImpl::WillBeDestroyed() {
- for (auto* observer : on_will_be_destroyed_event_observer_registry_
- .GetObserversWithoutAFilter()) {
- observer->OnWillBeDestroyedEvent(this);
+ for (auto& observer : observers_) {
+ observer.OnCoordinationUnitWillBeDestroyed(this);
}
}
-void CoordinationUnitImpl::ObserveOnChildAddedEvent(
- CoordinationUnitGraphObserver* observer,
- CoordinationUnitType child_filter) {
- on_child_added_event_observer_registry_.AddObserver(observer, child_filter);
-}
-
-void CoordinationUnitImpl::ObserveOnChildAddedEvent(
- CoordinationUnitGraphObserver* observer) {
- ObserveOnChildAddedEvent(
- observer,
- CoordinationUnitGraphObserverRegistry<CoordinationUnitType>::kNoFilter);
-}
-
-void CoordinationUnitImpl::ObserveOnParentAddedEvent(
- CoordinationUnitGraphObserver* observer,
- CoordinationUnitType parent_filter) {
- on_parent_added_event_observer_registry_.AddObserver(observer, parent_filter);
-}
-
-void CoordinationUnitImpl::ObserveOnParentAddedEvent(
- CoordinationUnitGraphObserver* observer) {
- ObserveOnParentAddedEvent(
- observer,
- CoordinationUnitGraphObserverRegistry<CoordinationUnitType>::kNoFilter);
-}
-
-void CoordinationUnitImpl::ObserveOnPropertyChangedEvent(
- CoordinationUnitGraphObserver* observer,
- mojom::PropertyType property_filter) {
- on_property_changed_event_observer_registry_.AddObserver(observer,
- property_filter);
-}
-
-void CoordinationUnitImpl::ObserveOnPropertyChangedEvent(
- CoordinationUnitGraphObserver* observer) {
- ObserveOnPropertyChangedEvent(
- observer,
- CoordinationUnitGraphObserverRegistry<mojom::PropertyType>::kNoFilter);
-}
-
-void CoordinationUnitImpl::ObserveOnChildRemovedEvent(
- CoordinationUnitGraphObserver* observer,
- CoordinationUnitType child_filter) {
- on_child_removed_event_observer_registry_.AddObserver(observer, child_filter);
-}
-
-void CoordinationUnitImpl::ObserveOnChildRemovedEvent(
- CoordinationUnitGraphObserver* observer) {
- ObserveOnChildRemovedEvent(
- observer,
- CoordinationUnitGraphObserverRegistry<CoordinationUnitType>::kNoFilter);
-}
-
-void CoordinationUnitImpl::ObserveOnParentRemovedEvent(
- CoordinationUnitGraphObserver* observer,
- CoordinationUnitType parent_filter) {
- on_parent_removed_event_observer_registry_.AddObserver(observer,
- parent_filter);
-}
-
-void CoordinationUnitImpl::ObserveOnParentRemovedEvent(
+void CoordinationUnitImpl::AddObserver(
CoordinationUnitGraphObserver* observer) {
- ObserveOnParentRemovedEvent(
- observer,
- CoordinationUnitGraphObserverRegistry<CoordinationUnitType>::kNoFilter);
+ observers_.AddObserver(observer);
}
-void CoordinationUnitImpl::ObserveOnWillBeDestroyedEvent(
+void CoordinationUnitImpl::RemoveObserver(
CoordinationUnitGraphObserver* observer) {
- on_will_be_destroyed_event_observer_registry_.AddObserver(observer);
+ observers_.RemoveObserver(observer);
}
} // namespace resource_coordinator

Powered by Google App Engine
This is Rietveld 408576698