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 typedef base::Callback<std::string(DependencyNode*)> GetNodeNameCallback; | |
21 | |
22 // Constructor. The name callback is used for debugging. | |
Jói
2013/04/14 23:13:20
Clarify the documentation: Is a non-is_null() call
Paweł Hajdan Jr.
2013/04/15 19:07:40
Done.
| |
23 explicit DependencyGraph(const GetNodeNameCallback& callback); | |
24 ~DependencyGraph(); | |
25 | |
26 // Adds/Removes a node from our list of live nodes. Removing will | |
27 // also remove live dependency links. | |
28 void AddNode(DependencyNode* node); | |
29 void RemoveNode(DependencyNode* node); | |
30 | |
31 // Adds a dependency between two nodes. | |
32 void AddEdge(DependencyNode* depended, DependencyNode* dependee); | |
33 | |
34 // Topologically sorts nodes to produce a safe construction order | |
35 // (all nodes after their dependees). | |
36 bool GetConstructionOrder( | |
37 std::vector<DependencyNode*>* order) WARN_UNUSED_RESULT; | |
38 | |
39 // Topologically sorts nodes to produce a safe destruction order | |
40 // (all nodes before their dependees). | |
41 bool GetDestructionOrder( | |
42 std::vector<DependencyNode*>* order) WARN_UNUSED_RESULT; | |
43 | |
44 // Returns representation of the dependency graph in graphviz format. | |
45 std::string DumpAsGraphviz(const std::string& toplevel_name); | |
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 // Callback to get name of a node (for debugging). | |
65 GetNodeNameCallback get_node_name_callback_; | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(DependencyGraph); | |
68 }; | |
69 | |
70 #endif // CHROME_BROWSER_PROFILES_DEPENDENCY_GRAPH_H_ | |
OLD | NEW |