| 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 23 matching lines...) Expand all Loading... |
| 34 } | 34 } |
| 35 | 35 |
| 36 void DependencyManager::RegisterPrefsForServices( | 36 void DependencyManager::RegisterPrefsForServices( |
| 37 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 (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); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 void DependencyManager::CreateContextServices(base::SupportsUserData* context, | 51 void DependencyManager::CreateContextServices(base::SupportsUserData* context, |
| 52 bool is_testing_context) { | 52 bool is_testing_context) { |
| 53 #ifndef NDEBUG | 53 #ifndef NDEBUG |
| 54 MarkContextLiveForTesting(context); | 54 MarkContextLiveForTesting(context); |
| 55 #endif | 55 #endif |
| 56 | 56 |
| 57 std::vector<DependencyNode*> construction_order; | 57 std::vector<DependencyNode*> construction_order; |
| 58 if (!dependency_graph_.GetConstructionOrder(&construction_order)) { | 58 if (!dependency_graph_.GetConstructionOrder(&construction_order)) { |
| 59 NOTREACHED(); | 59 NOTREACHED(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 #ifndef NDEBUG | 62 #ifndef NDEBUG |
| 63 DumpContextDependencies(context); | 63 DumpContextDependencies(context); |
| 64 #endif | 64 #endif |
| 65 | 65 |
| 66 for (const auto& dependency_node : construction_order) { | 66 for (auto* dependency_node : construction_order) { |
| 67 KeyedServiceBaseFactory* factory = | 67 KeyedServiceBaseFactory* factory = |
| 68 static_cast<KeyedServiceBaseFactory*>(dependency_node); | 68 static_cast<KeyedServiceBaseFactory*>(dependency_node); |
| 69 if (is_testing_context && factory->ServiceIsNULLWhileTesting() && | 69 if (is_testing_context && factory->ServiceIsNULLWhileTesting() && |
| 70 !factory->HasTestingFactory(context)) { | 70 !factory->HasTestingFactory(context)) { |
| 71 factory->SetEmptyTestingFactory(context); | 71 factory->SetEmptyTestingFactory(context); |
| 72 } else if (factory->ServiceIsCreatedWithContext()) { | 72 } else if (factory->ServiceIsCreatedWithContext()) { |
| 73 factory->CreateServiceNow(context); | 73 factory->CreateServiceNow(context); |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 void DependencyManager::DestroyContextServices( | 78 void DependencyManager::DestroyContextServices( |
| 79 base::SupportsUserData* context) { | 79 base::SupportsUserData* context) { |
| 80 std::vector<DependencyNode*> destruction_order; | 80 std::vector<DependencyNode*> destruction_order; |
| 81 if (!dependency_graph_.GetDestructionOrder(&destruction_order)) { | 81 if (!dependency_graph_.GetDestructionOrder(&destruction_order)) { |
| 82 NOTREACHED(); | 82 NOTREACHED(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 #ifndef NDEBUG | 85 #ifndef NDEBUG |
| 86 DumpContextDependencies(context); | 86 DumpContextDependencies(context); |
| 87 #endif | 87 #endif |
| 88 | 88 |
| 89 for (const auto& dependency_node : destruction_order) { | 89 for (auto* dependency_node : destruction_order) { |
| 90 KeyedServiceBaseFactory* factory = | 90 KeyedServiceBaseFactory* factory = |
| 91 static_cast<KeyedServiceBaseFactory*>(dependency_node); | 91 static_cast<KeyedServiceBaseFactory*>(dependency_node); |
| 92 factory->ContextShutdown(context); | 92 factory->ContextShutdown(context); |
| 93 } | 93 } |
| 94 | 94 |
| 95 #ifndef NDEBUG | 95 #ifndef NDEBUG |
| 96 // The context is now dead to the rest of the program. | 96 // The context is now dead to the rest of the program. |
| 97 dead_context_pointers_.insert(context); | 97 dead_context_pointers_.insert(context); |
| 98 #endif | 98 #endif |
| 99 | 99 |
| 100 for (const auto& dependency_node : destruction_order) { | 100 for (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 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()) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 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 |