Index: services/resource_coordinator/coordination_unit/coordination_unit_graph_observer.h |
diff --git a/services/resource_coordinator/coordination_unit/coordination_unit_graph_observer.h b/services/resource_coordinator/coordination_unit/coordination_unit_graph_observer.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..334fdd537a581128f231da37e6c5fd4db6478274 |
--- /dev/null |
+++ b/services/resource_coordinator/coordination_unit/coordination_unit_graph_observer.h |
@@ -0,0 +1,61 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_COORDINATION_UNIT_GRAPH_OBSERVER_H_ |
+#define SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_COORDINATION_UNIT_GRAPH_OBSERVER_H_ |
+ |
+#include <memory> |
+#include <unordered_map> |
+ |
+#include "base/macros.h" |
+#include "services/resource_coordinator/coordination_unit/coordination_unit_impl.h" |
+#include "services/resource_coordinator/public/cpp/coordination_unit_id.h" |
+#include "services/resource_coordinator/public/cpp/coordination_unit_types.h" |
+#include "services/resource_coordinator/public/interfaces/coordination_unit.mojom.h" |
+ |
+namespace resource_coordinator { |
+ |
+// An observer API for the CoordinationUnitGraph maintained by GRC. |
+// |
+// Observers are instantiated when the resource_coordinator serivce |
+// is created and are destroyed when the resource_coordinator service |
+// is destroyed. Therefore observers are guaranteed to be alive before |
+// any coordination unit is created and will be alive after any |
+// coordination unit is destroyed. Additionally, any |
+// Coordination Unit reachable within a callback will always be |
+// initialized and valid. |
+// |
+// To create and install a new observer: |
+// (1) derive from this class |
+// (2) register in CoordinationUnitManager::RegisterObserver |
+// inside of CoordinationUnitManager::CoordinationUnitManager |
+// |
+class CoordinationUnitGraphObserver { |
+ public: |
+ CoordinationUnitGraphObserver(); |
+ // The CoordinationUnitGraphObserver will only call |
+ // CoordinationUnitGraphObserver::CoordinationUnitCreated when the |
+ // CoordinationUnit's CoordinationUnitID.type matches filter. |
+ explicit CoordinationUnitGraphObserver(CoordinationUnitType filter); |
+ virtual ~CoordinationUnitGraphObserver(); |
+ |
+ // Determines whether or not OnCoordinationUnitCreated should be |
+ // invoked on the newly created CoordinationUnit. |
+ bool ShouldObserve(CoordinationUnitImpl* coordination_unit); |
+ |
+ // Called whenever any new CoordinationUnit of interest is created |
+ // (i.e. ShouldObserve evaluates to true). |
+ virtual void OnCoordinationUnitCreated( |
+ CoordinationUnitImpl* coordination_unit) {} |
+ |
+ protected: |
+ CoordinationUnitType filter_; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(CoordinationUnitGraphObserver); |
+}; |
+ |
+} // namespace resource_coordinator |
+ |
+#endif // SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_COORDINATION_UNIT_GRAPH_OBSERVER_H_ |