OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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 CHROME_BROWSER_PROFILES_DEPENDENCY_GRAPH_H_ |
| 6 #define CHROME_BROWSER_PROFILES_DEPENDENCY_GRAPH_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" |
| 14 |
| 15 class DependencyNode; |
| 16 |
| 17 // Dynamic graph of dependencies between nodes. |
| 18 class DependencyGraph { |
| 19 public: |
| 20 DependencyGraph(); |
| 21 ~DependencyGraph(); |
| 22 |
| 23 // Adds/Removes a node from our list of live nodes. Removing will |
| 24 // also remove live dependency links. |
| 25 void AddNode(DependencyNode* node); |
| 26 void RemoveNode(DependencyNode* node); |
| 27 |
| 28 // Adds a dependency between two nodes. |
| 29 void AddEdge(DependencyNode* depended, DependencyNode* dependee); |
| 30 |
| 31 // Topologically sorts nodes to produce a safe construction order |
| 32 // (all nodes after their dependees). |
| 33 bool GetConstructionOrder( |
| 34 std::vector<DependencyNode*>* order) WARN_UNUSED_RESULT; |
| 35 |
| 36 // Topologically sorts nodes to produce a safe destruction order |
| 37 // (all nodes before their dependees). |
| 38 bool GetDestructionOrder( |
| 39 std::vector<DependencyNode*>* order) WARN_UNUSED_RESULT; |
| 40 |
| 41 // Returns representation of the dependency graph in graphviz format. |
| 42 std::string DumpAsGraphviz( |
| 43 const std::string& toplevel_name, |
| 44 const base::Callback<std::string(DependencyNode*)>& |
| 45 node_name_callback) const; |
| 46 |
| 47 private: |
| 48 typedef std::multimap<DependencyNode*, DependencyNode*> EdgeMap; |
| 49 |
| 50 // Populates |construction_order_| with computed construction order. |
| 51 // Returns true on success. |
| 52 bool BuildConstructionOrder() WARN_UNUSED_RESULT; |
| 53 |
| 54 // Keeps track of all live nodes (see AddNode, RemoveNode). |
| 55 std::vector<DependencyNode*> all_nodes_; |
| 56 |
| 57 // Keeps track of edges of the dependency graph. |
| 58 EdgeMap edges_; |
| 59 |
| 60 // Cached construction order (needs rebuild with BuildConstructionOrder |
| 61 // when empty). |
| 62 std::vector<DependencyNode*> construction_order_; |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(DependencyGraph); |
| 65 }; |
| 66 |
| 67 #endif // CHROME_BROWSER_PROFILES_DEPENDENCY_GRAPH_H_ |
OLD | NEW |