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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_COORDINATION_UNIT_GRAPH_ OBSERVER_H_
6 #define SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_COORDINATION_UNIT_GRAPH_ OBSERVER_H_
7
8 #include <memory>
9 #include <unordered_map>
10
11 #include "base/macros.h"
12 #include "services/resource_coordinator/coordination_unit/coordination_unit_impl .h"
13 #include "services/resource_coordinator/public/cpp/coordination_unit_id.h"
14 #include "services/resource_coordinator/public/cpp/coordination_unit_types.h"
15 #include "services/resource_coordinator/public/interfaces/coordination_unit.mojo m.h"
16
17 namespace resource_coordinator {
18
19 // An observer API for the CoordinationUnitGraph maintained by GRC.
20 //
21 // Observers are instantiated when the resource_coordinator serivce
22 // is created and are destroyed when the resource_coordinator service
23 // is destroyed. Therefore observers are guaranteed to be alive before
24 // any coordination unit is created and will be alive after any
25 // coordination unit is destroyed. Additionally, any
26 // Coordination Unit reachable within a callback will always be
27 // initialized and valid.
28 //
29 // To create and install a new observer:
30 // (1) derive from this class
31 // (2) register in CoordinationUnitManager::RegisterObserver
32 // inside of CoordinationUnitManager::CoordinationUnitManager
33 //
34 class CoordinationUnitGraphObserver {
35 public:
36 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();
42
43 // Determines whether or not OnCoordinationUnitCreated should be
44 // invoked on the newly created CoordinationUnit.
45 bool ShouldObserve(CoordinationUnitImpl* coordination_unit);
46
47 // Called whenever any new CoordinationUnit of interest is created
48 // (i.e. ShouldObserve evaluates to true).
49 virtual void OnCoordinationUnitCreated(
50 CoordinationUnitImpl* coordination_unit) {}
51
52 protected:
53 CoordinationUnitType filter_;
54
55 private:
56 DISALLOW_COPY_AND_ASSIGN(CoordinationUnitGraphObserver);
57 };
58
59 } // namespace resource_coordinator
60
61 #endif // SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_COORDINATION_UNIT_GRA PH_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698