Chromium Code Reviews| 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 b50d98fcc700eaf820347721d7b6c812bfaf453b..7fd56636949211c79a1ae042f7971728dae02021 100644 |
| --- a/services/resource_coordinator/coordination_unit/coordination_unit_impl.cc |
| +++ b/services/resource_coordinator/coordination_unit/coordination_unit_impl.cc |
| @@ -10,6 +10,7 @@ |
| #include "base/strings/string_number_conversions.h" |
| #include "mojo/public/cpp/bindings/strong_binding.h" |
| +#include "services/resource_coordinator/coordination_unit/coordination_unit_graph_observer.h" |
| #include "services/resource_coordinator/public/cpp/coordination_unit_id.h" |
| namespace resource_coordinator { |
| @@ -157,7 +158,18 @@ bool CoordinationUnitImpl::AddChild(CoordinationUnitImpl* child) { |
| // We don't recalculate the policy here as policies are only dependent |
| // on the current CU or its parents, not its children. In other words, |
| // policies only bubble down. |
| - return children_.count(child) ? false : children_.insert(child).second; |
| + bool success = |
| + 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); |
| + } |
| + } |
| + |
| + return success; |
| } |
| void CoordinationUnitImpl::RemoveChild(const CoordinationUnitID& child_id) { |
| @@ -181,13 +193,29 @@ void CoordinationUnitImpl::RemoveChild(const CoordinationUnitID& child_id) { |
| bool CoordinationUnitImpl::RemoveChild(CoordinationUnitImpl* child) { |
| size_t children_removed = children_.erase(child); |
| - return children_removed > 0; |
| + bool success = children_removed > 0; |
| + |
| + if (success) { |
| + for (auto* observer : |
| + on_child_removed_event_observer_registry_.GetObserversForFilter( |
| + child->id().type)) { |
| + observer->OnChildRemovedEvent(this, child); |
| + } |
| + } |
| + |
| + return success; |
| } |
| 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); |
| + } |
| + |
| RecalcCoordinationPolicy(); |
| } |
| @@ -195,6 +223,14 @@ void CoordinationUnitImpl::RemoveParent(CoordinationUnitImpl* parent) { |
| size_t parents_removed = parents_.erase(parent); |
| DCHECK_EQ(1u, parents_removed); |
| + // TODO(matthalp, oysteine) should this go before or |
| + // after RecalcCoordinationPolicy? |
|
Zhen Wang
2017/06/19 22:54:25
Is this undecided or you intend to ask Oystein for
oystein (OOO til 10th of July)
2017/06/20 18:39:23
Recalc should happen after, though TBH I think we'
matthalp
2017/06/20 19:02:52
RecalcCoordinationPolicy does not do anything righ
matthalp
2017/06/20 19:02:52
Sounds good.
|
| + for (auto* observer : |
| + on_parent_removed_event_observer_registry_.GetObserversForFilter( |
| + parent->id().type)) { |
| + observer->OnParentRemovedEvent(this, parent); |
| + } |
| + |
| RecalcCoordinationPolicy(); |
| } |
| @@ -238,7 +274,8 @@ double CoordinationUnitImpl::GetCPUUsageForTesting() { |
| return kCPUUsageUnmeasuredForTesting; |
| } |
| -base::Value CoordinationUnitImpl::GetProperty(mojom::PropertyType property) { |
| +base::Value CoordinationUnitImpl::GetProperty( |
| + mojom::PropertyType property) const { |
| auto value_it = property_store_.find(property); |
| return value_it != property_store_.end() ? value_it->second : base::Value(); |
| @@ -262,6 +299,91 @@ 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); |
| + } |
| +} |
| + |
| +void CoordinationUnitImpl::WillBeDestroyed() { |
| + for (auto* observer : on_will_be_destroyed_event_observer_registry_ |
| + .GetObserversWithoutAFilter()) { |
| + observer->OnWillBeDestroyedEvent(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( |
| + CoordinationUnitGraphObserver* observer) { |
| + ObserveOnParentRemovedEvent( |
| + observer, |
| + CoordinationUnitGraphObserverRegistry<CoordinationUnitType>::kNoFilter); |
| +} |
| + |
| +void CoordinationUnitImpl::ObserveOnWillBeDestroyedEvent( |
| + CoordinationUnitGraphObserver* observer) { |
| + on_will_be_destroyed_event_observer_registry_.AddObserver(observer); |
| } |
| } // namespace resource_coordinator |