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

Unified Diff: services/resource_coordinator/coordination_unit/coordination_unit_graph_observer.h

Issue 2926663003: [GRC] Coordination Unit Graph Observer (Closed)
Patch Set: Rebase 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_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..5a30d8ed74b9039f162b462640211c557c89d4fd
--- /dev/null
+++ b/services/resource_coordinator/coordination_unit/coordination_unit_graph_observer.h
@@ -0,0 +1,60 @@
+// 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/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 {
+
+class CoordinationUnitImpl;
+
+// 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 CoordinationUnitmanagerObserver will only call
Zhen Wang 2017/06/15 20:07:52 s/CoordinationUnitmanagerObserver/CoordinationUnit
matthalp 2017/06/16 00:01:26 Yes. Thank you for catching this.
+ // CoordinationUnitGraphObserver::CoordinationUnitCreated when the
+ // CoordinationUnit's CoordinationUnitID.type matches filter.
+ explicit CoordinationUnitGraphObserver(CoordinationUnitType filter);
+ virtual ~CoordinationUnitGraphObserver();
+
+ CoordinationUnitType filter() const { return filter_; }
Zhen Wang 2017/06/15 20:07:52 Instead of exposing filter type, how about using s
matthalp 2017/06/16 00:01:26 That is definitely cleaner -- done.
+
+ // Called whenever any new CoordinationUnit of any type is created. Note that
Zhen Wang 2017/06/15 20:07:52 This is only called when it matches the filter, ri
matthalp 2017/06/16 00:01:27 Done. Please let me know if the new comments are s
+ // this will be called after any specialized *CoordinationUnitCreated (e.g.
+ // FrameCoordinationUnitCreation, etc.) is called.
+ virtual void CoordinationUnitCreated(
+ CoordinationUnitImpl* coordination_unit) {}
+
+ private:
+ CoordinationUnitType filter_;
+
+ DISALLOW_COPY_AND_ASSIGN(CoordinationUnitGraphObserver);
+};
+
+} // namespace resource_coordinator
+
+#endif // SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_COORDINATION_UNIT_GRAPH_OBSERVER_H_

Powered by Google App Engine
This is Rietveld 408576698