OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/keyed_service/core/dependency_manager.h" | 5 #include "components/keyed_service/core/dependency_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/supports_user_data.h" | 9 #include "base/supports_user_data.h" |
10 #include "components/keyed_service/core/keyed_service_base_factory.h" | 10 #include "components/keyed_service/core/keyed_service_base_factory.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 void DependencyManager::RemoveComponent(KeyedServiceBaseFactory* component) { | 27 void DependencyManager::RemoveComponent(KeyedServiceBaseFactory* component) { |
28 dependency_graph_.RemoveNode(component); | 28 dependency_graph_.RemoveNode(component); |
29 } | 29 } |
30 | 30 |
31 void DependencyManager::AddEdge(KeyedServiceBaseFactory* depended, | 31 void DependencyManager::AddEdge(KeyedServiceBaseFactory* depended, |
32 KeyedServiceBaseFactory* dependee) { | 32 KeyedServiceBaseFactory* dependee) { |
33 dependency_graph_.AddEdge(depended, dependee); | 33 dependency_graph_.AddEdge(depended, dependee); |
34 } | 34 } |
35 | 35 |
36 void DependencyManager::RegisterPrefsForServices( | 36 void DependencyManager::RegisterPrefsForServices( |
37 const base::SupportsUserData* context, | 37 base::SupportsUserData* context, |
38 user_prefs::PrefRegistrySyncable* pref_registry) { | 38 user_prefs::PrefRegistrySyncable* pref_registry) { |
39 std::vector<DependencyNode*> construction_order; | 39 std::vector<DependencyNode*> construction_order; |
40 if (!dependency_graph_.GetConstructionOrder(&construction_order)) { | 40 if (!dependency_graph_.GetConstructionOrder(&construction_order)) { |
41 NOTREACHED(); | 41 NOTREACHED(); |
42 } | 42 } |
43 | 43 |
44 for (const auto& dependency_node : construction_order) { | 44 for (const auto& dependency_node : construction_order) { |
45 KeyedServiceBaseFactory* factory = | 45 KeyedServiceBaseFactory* factory = |
46 static_cast<KeyedServiceBaseFactory*>(dependency_node); | 46 static_cast<KeyedServiceBaseFactory*>(dependency_node); |
47 factory->RegisterPrefsIfNecessaryForContext(context, pref_registry); | 47 factory->RegisterPrefsIfNecessaryForContext(context, pref_registry); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 99 |
100 for (const auto& dependency_node : destruction_order) { | 100 for (const auto& dependency_node : destruction_order) { |
101 KeyedServiceBaseFactory* factory = | 101 KeyedServiceBaseFactory* factory = |
102 static_cast<KeyedServiceBaseFactory*>(dependency_node); | 102 static_cast<KeyedServiceBaseFactory*>(dependency_node); |
103 factory->ContextDestroyed(context); | 103 factory->ContextDestroyed(context); |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 #ifndef NDEBUG | 107 #ifndef NDEBUG |
108 void DependencyManager::AssertContextWasntDestroyed( | 108 void DependencyManager::AssertContextWasntDestroyed( |
109 const base::SupportsUserData* context) { | 109 base::SupportsUserData* context) { |
110 if (dead_context_pointers_.find(context) != dead_context_pointers_.end()) { | 110 if (dead_context_pointers_.find(context) != dead_context_pointers_.end()) { |
111 NOTREACHED() << "Attempted to access a context that was ShutDown(). " | 111 NOTREACHED() << "Attempted to access a context that was ShutDown(). " |
112 << "This is most likely a heap smasher in progress. After " | 112 << "This is most likely a heap smasher in progress. After " |
113 << "KeyedService::Shutdown() completes, your service MUST " | 113 << "KeyedService::Shutdown() completes, your service MUST " |
114 << "NOT refer to depended services again."; | 114 << "NOT refer to depended services again."; |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 void DependencyManager::MarkContextLiveForTesting( | 118 void DependencyManager::MarkContextLiveForTesting( |
119 const base::SupportsUserData* context) { | 119 base::SupportsUserData* context) { |
120 dead_context_pointers_.erase(context); | 120 dead_context_pointers_.erase(context); |
121 } | 121 } |
122 | 122 |
123 namespace { | 123 namespace { |
124 | 124 |
125 std::string KeyedServiceBaseFactoryGetNodeName(DependencyNode* node) { | 125 std::string KeyedServiceBaseFactoryGetNodeName(DependencyNode* node) { |
126 return static_cast<KeyedServiceBaseFactory*>(node)->name(); | 126 return static_cast<KeyedServiceBaseFactory*>(node)->name(); |
127 } | 127 } |
128 | 128 |
129 } // namespace | 129 } // namespace |
130 | 130 |
131 void DependencyManager::DumpDependenciesAsGraphviz( | 131 void DependencyManager::DumpDependenciesAsGraphviz( |
132 const std::string& top_level_name, | 132 const std::string& top_level_name, |
133 const base::FilePath& dot_file) const { | 133 const base::FilePath& dot_file) const { |
134 DCHECK(!dot_file.empty()); | 134 DCHECK(!dot_file.empty()); |
135 std::string contents = dependency_graph_.DumpAsGraphviz( | 135 std::string contents = dependency_graph_.DumpAsGraphviz( |
136 top_level_name, base::Bind(&KeyedServiceBaseFactoryGetNodeName)); | 136 top_level_name, base::Bind(&KeyedServiceBaseFactoryGetNodeName)); |
137 base::WriteFile(dot_file, contents.c_str(), contents.size()); | 137 base::WriteFile(dot_file, contents.c_str(), contents.size()); |
138 } | 138 } |
139 #endif // NDEBUG | 139 #endif // NDEBUG |
OLD | NEW |