1 // Copyright 2019 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 COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_GRAPH_SYSTEM_NODE_H_
6 #define COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_GRAPH_SYSTEM_NODE_H_
7 
8 #include "base/macros.h"
9 #include "components/performance_manager/public/graph/node.h"
10 
11 namespace performance_manager {
12 
13 class SystemNodeObserver;
14 
15 // The SystemNode represents system-wide state. There is at most one system node
16 // in a graph.
17 class SystemNode : public Node {
18  public:
19   using Observer = SystemNodeObserver;
20   class ObserverDefaultImpl;
21 
22   SystemNode();
23   ~SystemNode() override;
24 
25  private:
26   DISALLOW_COPY_AND_ASSIGN(SystemNode);
27 };
28 
29 // Pure virtual observer interface. Derive from this if you want to be forced to
30 // implement the entire interface.
31 class SystemNodeObserver {
32  public:
33   SystemNodeObserver();
34   virtual ~SystemNodeObserver();
35 
36   // Node lifetime notifications.
37 
38   // Called when the |system_node| is added to the graph.
39   virtual void OnSystemNodeAdded(const SystemNode* system_node) = 0;
40 
41   // Called before the |system_node| is removed from the graph.
42   virtual void OnBeforeSystemNodeRemoved(const SystemNode* system_node) = 0;
43 
44   // Called when a new set of process memory metrics is available.
45   virtual void OnProcessMemoryMetricsAvailable(
46       const SystemNode* system_node) = 0;
47 
48  private:
49   DISALLOW_COPY_AND_ASSIGN(SystemNodeObserver);
50 };
51 
52 // Default implementation of observer that provides dummy versions of each
53 // function. Derive from this if you only need to implement a few of the
54 // functions.
55 class SystemNode::ObserverDefaultImpl : public SystemNodeObserver {
56  public:
57   ObserverDefaultImpl();
58   ~ObserverDefaultImpl() override;
59 
60   // SystemNodeObserver implementation:
OnSystemNodeAdded(const SystemNode * system_node)61   void OnSystemNodeAdded(const SystemNode* system_node) override {}
OnBeforeSystemNodeRemoved(const SystemNode * system_node)62   void OnBeforeSystemNodeRemoved(const SystemNode* system_node) override {}
OnProcessMemoryMetricsAvailable(const SystemNode * system_node)63   void OnProcessMemoryMetricsAvailable(const SystemNode* system_node) override {
64   }
65 
66  private:
67   DISALLOW_COPY_AND_ASSIGN(ObserverDefaultImpl);
68 };
69 
70 }  // namespace performance_manager
71 
72 #endif  // COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_GRAPH_SYSTEM_NODE_H_
73