OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "services/resource_coordinator/coordination_unit/coordination_unit_impl
.h" | 5 #include "services/resource_coordinator/coordination_unit/coordination_unit_impl
.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <unordered_map> | 8 #include <unordered_map> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 155 } |
156 | 156 |
157 bool CoordinationUnitImpl::AddChild(CoordinationUnitImpl* child) { | 157 bool CoordinationUnitImpl::AddChild(CoordinationUnitImpl* child) { |
158 // We don't recalculate the policy here as policies are only dependent | 158 // We don't recalculate the policy here as policies are only dependent |
159 // on the current CU or its parents, not its children. In other words, | 159 // on the current CU or its parents, not its children. In other words, |
160 // policies only bubble down. | 160 // policies only bubble down. |
161 bool success = | 161 bool success = |
162 children_.count(child) ? false : children_.insert(child).second; | 162 children_.count(child) ? false : children_.insert(child).second; |
163 | 163 |
164 if (success) { | 164 if (success) { |
165 for (auto* observer : | 165 for (auto& observer : observers_) { |
166 on_child_added_event_observer_registry_.GetObserversForFilter( | 166 observer.OnChildAdded(this, child); |
167 child->id().type)) { | |
168 observer->OnChildAddedEvent(this, child); | |
169 } | 167 } |
170 } | 168 } |
171 | 169 |
172 return success; | 170 return success; |
173 } | 171 } |
174 | 172 |
175 void CoordinationUnitImpl::RemoveChild(const CoordinationUnitID& child_id) { | 173 void CoordinationUnitImpl::RemoveChild(const CoordinationUnitID& child_id) { |
176 auto child_iter = g_cu_map().find(child_id); | 174 auto child_iter = g_cu_map().find(child_id); |
177 if (child_iter == g_cu_map().end()) { | 175 if (child_iter == g_cu_map().end()) { |
178 return; | 176 return; |
(...skipping 10 matching lines...) Expand all Loading... |
189 if (RemoveChild(child)) { | 187 if (RemoveChild(child)) { |
190 child->RemoveParent(this); | 188 child->RemoveParent(this); |
191 } | 189 } |
192 } | 190 } |
193 | 191 |
194 bool CoordinationUnitImpl::RemoveChild(CoordinationUnitImpl* child) { | 192 bool CoordinationUnitImpl::RemoveChild(CoordinationUnitImpl* child) { |
195 size_t children_removed = children_.erase(child); | 193 size_t children_removed = children_.erase(child); |
196 bool success = children_removed > 0; | 194 bool success = children_removed > 0; |
197 | 195 |
198 if (success) { | 196 if (success) { |
199 for (auto* observer : | 197 for (auto& observer : observers_) { |
200 on_child_removed_event_observer_registry_.GetObserversForFilter( | 198 observer.OnChildRemoved(this, child); |
201 child->id().type)) { | |
202 observer->OnChildRemovedEvent(this, child); | |
203 } | 199 } |
204 } | 200 } |
205 | 201 |
206 return success; | 202 return success; |
207 } | 203 } |
208 | 204 |
209 void CoordinationUnitImpl::AddParent(CoordinationUnitImpl* parent) { | 205 void CoordinationUnitImpl::AddParent(CoordinationUnitImpl* parent) { |
210 DCHECK_EQ(0u, parents_.count(parent)); | 206 DCHECK_EQ(0u, parents_.count(parent)); |
211 parents_.insert(parent); | 207 parents_.insert(parent); |
212 | 208 |
213 for (auto* observer : | 209 for (auto& observer : observers_) { |
214 on_parent_added_event_observer_registry_.GetObserversForFilter( | 210 observer.OnParentAdded(this, parent); |
215 parent->id().type)) { | |
216 observer->OnParentAddedEvent(this, parent); | |
217 } | 211 } |
218 | 212 |
219 RecalcCoordinationPolicy(); | 213 RecalcCoordinationPolicy(); |
220 } | 214 } |
221 | 215 |
222 void CoordinationUnitImpl::RemoveParent(CoordinationUnitImpl* parent) { | 216 void CoordinationUnitImpl::RemoveParent(CoordinationUnitImpl* parent) { |
223 size_t parents_removed = parents_.erase(parent); | 217 size_t parents_removed = parents_.erase(parent); |
224 DCHECK_EQ(1u, parents_removed); | 218 DCHECK_EQ(1u, parents_removed); |
225 | 219 |
226 // TODO(matthalp, oysteine) should this go before or | 220 // TODO(matthalp, oysteine) should this go before or |
227 // after RecalcCoordinationPolicy? | 221 // after RecalcCoordinationPolicy? |
228 for (auto* observer : | 222 for (auto& observer : observers_) { |
229 on_parent_removed_event_observer_registry_.GetObserversForFilter( | 223 observer.OnParentRemoved(this, parent); |
230 parent->id().type)) { | |
231 observer->OnParentRemovedEvent(this, parent); | |
232 } | 224 } |
233 | 225 |
234 RecalcCoordinationPolicy(); | 226 RecalcCoordinationPolicy(); |
235 } | 227 } |
236 | 228 |
237 bool CoordinationUnitImpl::HasParent(CoordinationUnitImpl* unit) { | 229 bool CoordinationUnitImpl::HasParent(CoordinationUnitImpl* unit) { |
238 for (CoordinationUnitImpl* parent : parents_) { | 230 for (CoordinationUnitImpl* parent : parents_) { |
239 if (parent == unit || parent->HasParent(unit)) { | 231 if (parent == unit || parent->HasParent(unit)) { |
240 return true; | 232 return true; |
241 } | 233 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 base::Value value) { | 285 base::Value value) { |
294 // setting a property with an empty value is effectively clearing the | 286 // setting a property with an empty value is effectively clearing the |
295 // value from storage | 287 // value from storage |
296 if (value.IsType(base::Value::Type::NONE)) { | 288 if (value.IsType(base::Value::Type::NONE)) { |
297 ClearProperty(property); | 289 ClearProperty(property); |
298 return; | 290 return; |
299 } | 291 } |
300 | 292 |
301 property_store_[property] = value; | 293 property_store_[property] = value; |
302 | 294 |
303 for (auto* observer : | 295 for (auto& observer : observers_) { |
304 on_property_changed_event_observer_registry_.GetObserversForFilter( | 296 observer.OnPropertyChanged(this, property); |
305 property)) { | |
306 observer->OnPropertyChangedEvent(this, property); | |
307 } | 297 } |
308 } | 298 } |
309 | 299 |
310 void CoordinationUnitImpl::WillBeDestroyed() { | 300 void CoordinationUnitImpl::WillBeDestroyed() { |
311 for (auto* observer : on_will_be_destroyed_event_observer_registry_ | 301 for (auto& observer : observers_) { |
312 .GetObserversWithoutAFilter()) { | 302 observer.OnCoordinationUnitWillBeDestroyed(this); |
313 observer->OnWillBeDestroyedEvent(this); | |
314 } | 303 } |
315 } | 304 } |
316 | 305 |
317 void CoordinationUnitImpl::ObserveOnChildAddedEvent( | 306 void CoordinationUnitImpl::AddObserver( |
318 CoordinationUnitGraphObserver* observer, | 307 CoordinationUnitGraphObserver* observer) { |
319 CoordinationUnitType child_filter) { | 308 observers_.AddObserver(observer); |
320 on_child_added_event_observer_registry_.AddObserver(observer, child_filter); | |
321 } | 309 } |
322 | 310 |
323 void CoordinationUnitImpl::ObserveOnChildAddedEvent( | 311 void CoordinationUnitImpl::RemoveObserver( |
324 CoordinationUnitGraphObserver* observer) { | 312 CoordinationUnitGraphObserver* observer) { |
325 ObserveOnChildAddedEvent( | 313 observers_.RemoveObserver(observer); |
326 observer, | |
327 CoordinationUnitGraphObserverRegistry<CoordinationUnitType>::kNoFilter); | |
328 } | |
329 | |
330 void CoordinationUnitImpl::ObserveOnParentAddedEvent( | |
331 CoordinationUnitGraphObserver* observer, | |
332 CoordinationUnitType parent_filter) { | |
333 on_parent_added_event_observer_registry_.AddObserver(observer, parent_filter); | |
334 } | |
335 | |
336 void CoordinationUnitImpl::ObserveOnParentAddedEvent( | |
337 CoordinationUnitGraphObserver* observer) { | |
338 ObserveOnParentAddedEvent( | |
339 observer, | |
340 CoordinationUnitGraphObserverRegistry<CoordinationUnitType>::kNoFilter); | |
341 } | |
342 | |
343 void CoordinationUnitImpl::ObserveOnPropertyChangedEvent( | |
344 CoordinationUnitGraphObserver* observer, | |
345 mojom::PropertyType property_filter) { | |
346 on_property_changed_event_observer_registry_.AddObserver(observer, | |
347 property_filter); | |
348 } | |
349 | |
350 void CoordinationUnitImpl::ObserveOnPropertyChangedEvent( | |
351 CoordinationUnitGraphObserver* observer) { | |
352 ObserveOnPropertyChangedEvent( | |
353 observer, | |
354 CoordinationUnitGraphObserverRegistry<mojom::PropertyType>::kNoFilter); | |
355 } | |
356 | |
357 void CoordinationUnitImpl::ObserveOnChildRemovedEvent( | |
358 CoordinationUnitGraphObserver* observer, | |
359 CoordinationUnitType child_filter) { | |
360 on_child_removed_event_observer_registry_.AddObserver(observer, child_filter); | |
361 } | |
362 | |
363 void CoordinationUnitImpl::ObserveOnChildRemovedEvent( | |
364 CoordinationUnitGraphObserver* observer) { | |
365 ObserveOnChildRemovedEvent( | |
366 observer, | |
367 CoordinationUnitGraphObserverRegistry<CoordinationUnitType>::kNoFilter); | |
368 } | |
369 | |
370 void CoordinationUnitImpl::ObserveOnParentRemovedEvent( | |
371 CoordinationUnitGraphObserver* observer, | |
372 CoordinationUnitType parent_filter) { | |
373 on_parent_removed_event_observer_registry_.AddObserver(observer, | |
374 parent_filter); | |
375 } | |
376 | |
377 void CoordinationUnitImpl::ObserveOnParentRemovedEvent( | |
378 CoordinationUnitGraphObserver* observer) { | |
379 ObserveOnParentRemovedEvent( | |
380 observer, | |
381 CoordinationUnitGraphObserverRegistry<CoordinationUnitType>::kNoFilter); | |
382 } | |
383 | |
384 void CoordinationUnitImpl::ObserveOnWillBeDestroyedEvent( | |
385 CoordinationUnitGraphObserver* observer) { | |
386 on_will_be_destroyed_event_observer_registry_.AddObserver(observer); | |
387 } | 314 } |
388 | 315 |
389 } // namespace resource_coordinator | 316 } // namespace resource_coordinator |
OLD | NEW |