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 #ifndef SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_COORDINATION_UNIT_GRAPH_
OBSERVER_H_ | 5 #ifndef SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_COORDINATION_UNIT_GRAPH_
OBSERVER_H_ |
6 #define SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_COORDINATION_UNIT_GRAPH_
OBSERVER_H_ | 6 #define SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_COORDINATION_UNIT_GRAPH_
OBSERVER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <unordered_map> | 9 #include <unordered_map> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "services/resource_coordinator/coordination_unit/coordination_unit_impl
.h" | 12 #include "services/resource_coordinator/coordination_unit/coordination_unit_impl
.h" |
13 #include "services/resource_coordinator/public/cpp/coordination_unit_id.h" | 13 #include "services/resource_coordinator/public/cpp/coordination_unit_id.h" |
14 #include "services/resource_coordinator/public/cpp/coordination_unit_types.h" | 14 #include "services/resource_coordinator/public/cpp/coordination_unit_types.h" |
15 #include "services/resource_coordinator/public/interfaces/coordination_unit.mojo
m.h" | 15 #include "services/resource_coordinator/public/interfaces/coordination_unit.mojo
m.h" |
16 | 16 |
17 namespace resource_coordinator { | 17 namespace resource_coordinator { |
18 | 18 |
19 // An observer API for the CoordinationUnitGraph maintained by GRC. | 19 // An observer API for the coordination unit graph maintained by GRC. |
20 // | 20 // |
21 // Observers are instantiated when the resource_coordinator serivce | 21 // Observers are instantiated when the resource_coordinator service |
22 // is created and are destroyed when the resource_coordinator service | 22 // is created and are destroyed when the resource_coordinator service |
23 // is destroyed. Therefore observers are guaranteed to be alive before | 23 // is destroyed. Therefore observers are guaranteed to be alive before |
24 // any coordination unit is created and will be alive after any | 24 // any coordination unit is created and will be alive after any |
25 // coordination unit is destroyed. Additionally, any | 25 // coordination unit is destroyed. Additionally, any |
26 // Coordination Unit reachable within a callback will always be | 26 // Coordination Unit reachable within a callback will always be |
27 // initialized and valid. | 27 // initialized and valid. |
28 // | 28 // |
29 // To create and install a new observer: | 29 // To create and install a new observer: |
30 // (1) derive from this class | 30 // (1) derive from this class |
31 // (2) register in CoordinationUnitManager::RegisterObserver | 31 // (2) register in CoordinationUnitManager::RegisterObserver |
32 // inside of CoordinationUnitManager::CoordinationUnitManager | 32 // inside of CoordinationUnitManager::CoordinationUnitManager |
33 // | |
34 class CoordinationUnitGraphObserver { | 33 class CoordinationUnitGraphObserver { |
35 public: | 34 public: |
36 CoordinationUnitGraphObserver(); | 35 CoordinationUnitGraphObserver(); |
37 // The CoordinationUnitGraphObserver will only call | |
38 // CoordinationUnitGraphObserver::CoordinationUnitCreated when the | |
39 // CoordinationUnit's CoordinationUnitID.type matches filter. | |
40 explicit CoordinationUnitGraphObserver(CoordinationUnitType filter); | |
41 virtual ~CoordinationUnitGraphObserver(); | 36 virtual ~CoordinationUnitGraphObserver(); |
42 | 37 |
43 // Determines whether or not OnCoordinationUnitCreated should be | 38 // Determines whether or not the observer should be registered and |
44 // invoked on the newly created CoordinationUnit. | 39 // invoked for the |coordination_unit|. |
45 bool ShouldObserve(CoordinationUnitImpl* coordination_unit); | 40 virtual bool ShouldObserve(const CoordinationUnitImpl* coordination_unit) = 0; |
46 | 41 |
47 // Called whenever any new CoordinationUnit of interest is created | 42 // Called whenever a CoordinationUnit is created. |
48 // (i.e. ShouldObserve evaluates to true). | 43 virtual void OnCoordinationUnitCreated( |
49 virtual void OnCoordinationUnitCreatedEvent( | 44 const CoordinationUnitImpl* coordination_unit) {} |
50 CoordinationUnitImpl* coordination_unit) {} | |
51 | 45 |
52 // Called whenever a new parent-child relationship occurs where the | 46 // Called whenever a new parent-child relationship occurs where the |
53 // |coordination_unit| is the parent and the |child_coordination_unit| | 47 // |coordination_unit| is the parent of |child_coordination_unit| |
54 // type matches the CoordinationUnitType filter that the observer | 48 virtual void OnChildAdded( |
55 // was registered with (e.g. CoordinationUnit::ObserveAddChildEvent). | |
56 virtual void OnChildAddedEvent( | |
57 const CoordinationUnitImpl* coordination_unit, | 49 const CoordinationUnitImpl* coordination_unit, |
58 const CoordinationUnitImpl* child_coordination_unit) {} | 50 const CoordinationUnitImpl* child_coordination_unit) {} |
59 | 51 |
60 // Called whenever a new parent-child relationship occurs where the | 52 // Called whenever a new parent-child relationship occurs where the |
61 // |coordination_unit| is the child and the |parent_coordination_unit| | 53 // |coordination_unit| is the child of |parent_coordination_unit|. |
62 // type matches the CoordinationUnitType filter that the observer | 54 virtual void OnParentAdded( |
63 // was registered with (e.g. CoordinationUnit::ObserveAddParentEvent). | |
64 virtual void OnParentAddedEvent( | |
65 const CoordinationUnitImpl* coordination_unit, | 55 const CoordinationUnitImpl* coordination_unit, |
66 const CoordinationUnitImpl* parent_coordination_unit) {} | 56 const CoordinationUnitImpl* parent_coordination_unit) {} |
67 | 57 |
68 // Called whenever a |property| within the |coordination_unit|'s internal | 58 // Called whenever a |property| within the |coordination_unit|'s |
69 // property store changes and the |property| type matches the | 59 // internal property store has changed. |
70 // mojom::Property filter that the observer was registered with | 60 virtual void OnPropertyChanged(const CoordinationUnitImpl* coordination_unit, |
71 // (e.g. CoordinationUnit::ObservePropertyChangedEvent). | 61 mojom::PropertyType property) {} |
72 virtual void OnPropertyChangedEvent( | |
73 const CoordinationUnitImpl* coordination_unit, | |
74 mojom::PropertyType property) {} | |
75 | 62 |
76 // Called whenever parent-child relationship ends where the | 63 // Called whenever parent-child relationship ends where the |
77 // |coordination_unit| was the parent and the |child_coordination_unit| | 64 // |coordination_unit| was the parent and the |child_coordination_unit|. |
78 // type matches the CoordinationUnitType filter that the observer | 65 virtual void OnChildRemoved( |
79 // was registered with (e.g. CoordinationUnit::ObserveAddChildEvent). | |
80 virtual void OnChildRemovedEvent( | |
81 const CoordinationUnitImpl* coordination_unit, | 66 const CoordinationUnitImpl* coordination_unit, |
82 const CoordinationUnitImpl* child_coordination_unit) {} | 67 const CoordinationUnitImpl* child_coordination_unit) {} |
83 | 68 |
84 // Called whenever parent-child relationship ends where the | 69 // Called whenever parent-child relationship ends where the |
85 // |coordination_unit| was the child and the |child_coordination_unit| | 70 // |coordination_unit| was the child and the |child_coordination_unit|. |
86 // type matches the CoordinationUnitType filter that the observer | 71 virtual void OnParentRemoved( |
87 // was registered with (e.g. CoordinationUnit::ObserveRemoveParentEvent). | |
88 virtual void OnParentRemovedEvent( | |
89 const CoordinationUnitImpl* coordination_unit, | 72 const CoordinationUnitImpl* coordination_unit, |
90 const CoordinationUnitImpl* parent_coordination_unit) {} | 73 const CoordinationUnitImpl* parent_coordination_unit) {} |
91 | 74 |
92 // Called when the |coordination_unit| is about to be destroyed. | 75 // Called when the |coordination_unit| is about to be destroyed. |
93 virtual void OnWillBeDestroyedEvent( | 76 virtual void OnCoordinationUnitWillBeDestroyed( |
94 const CoordinationUnitImpl* coordination_unit) {} | 77 const CoordinationUnitImpl* coordination_unit) {} |
95 | 78 |
96 protected: | |
97 CoordinationUnitType filter_; | |
98 | |
99 private: | 79 private: |
100 DISALLOW_COPY_AND_ASSIGN(CoordinationUnitGraphObserver); | 80 DISALLOW_COPY_AND_ASSIGN(CoordinationUnitGraphObserver); |
101 }; | 81 }; |
102 | 82 |
103 } // namespace resource_coordinator | 83 } // namespace resource_coordinator |
104 | 84 |
105 #endif // SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_COORDINATION_UNIT_GRA
PH_OBSERVER_H_ | 85 #endif // SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_COORDINATION_UNIT_GRA
PH_OBSERVER_H_ |
OLD | NEW |