Chromium Code Reviews| 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 DependencyGraph { | |
| 16 public: | |
| 17 typedef base::Callback<std::string(void*)> GetNodeNameCallback; | |
| 18 | |
| 19 explicit DependencyGraph(const GetNodeNameCallback& callback); | |
| 20 ~DependencyGraph(); | |
| 21 | |
| 22 // Adds/Removes a node from our list of live nodes. Removing will | |
| 23 // also remove live dependency links. | |
| 24 void AddNode(void* node); | |
| 25 void RemoveNode(void* node); | |
| 26 | |
| 27 // Adds a dependency between two nodes. | |
| 28 void AddEdge(void* depended, void* dependee); | |
|
Elliot Glaysher
2013/04/05 23:44:15
I'd prefer it if you got rid of these void pointer
Paweł Hajdan Jr.
2013/04/08 20:26:43
Glad to see a concern for safety and correctness.
Elliot Glaysher
2013/04/11 20:09:28
So what's the motivation for doing that? Creating
| |
| 29 | |
| 30 // Topologically sorts nodes to produce a safe construction order | |
| 31 // (all nodes after their dependees). | |
| 32 bool GetConstructionOrder(std::vector<void*>* order) WARN_UNUSED_RESULT; | |
| 33 | |
| 34 // Topologically sorts nodes to produce a safe destruction order | |
| 35 // (all nodes before their dependees). | |
| 36 bool GetDestructionOrder(std::vector<void*>* order) WARN_UNUSED_RESULT; | |
| 37 | |
| 38 // Returns representation of the dependency graph in graphviz format. | |
| 39 std::string DumpAsGraphviz(const std::string& toplevel_name); | |
| 40 | |
| 41 private: | |
| 42 typedef std::multimap<void*, void*> EdgeMap; | |
| 43 | |
| 44 bool BuildConstructionOrder() WARN_UNUSED_RESULT; | |
| 45 | |
| 46 std::vector<void*> all_nodes_; | |
| 47 | |
| 48 EdgeMap edges_; | |
| 49 | |
| 50 std::vector<void*> construction_order_; | |
| 51 | |
| 52 GetNodeNameCallback get_node_name_callback_; | |
| 53 | |
| 54 DISALLOW_COPY_AND_ASSIGN(DependencyGraph); | |
| 55 }; | |
| 56 | |
| 57 #endif // CHROME_BROWSER_PROFILES_DEPENDENCY_GRAPH_H_ | |
| OLD | NEW |