| 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 #ifndef COMPONENTS_KEYED_SERVICE_CORE_DEPENDENCY_MANAGER_H_ | 5 #ifndef COMPONENTS_KEYED_SERVICE_CORE_DEPENDENCY_MANAGER_H_ |
| 6 #define COMPONENTS_KEYED_SERVICE_CORE_DEPENDENCY_MANAGER_H_ | 6 #define COMPONENTS_KEYED_SERVICE_CORE_DEPENDENCY_MANAGER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "components/keyed_service/core/dependency_graph.h" | 10 #include "components/keyed_service/core/dependency_graph.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 void AddComponent(KeyedServiceBaseFactory* component); | 38 void AddComponent(KeyedServiceBaseFactory* component); |
| 39 void RemoveComponent(KeyedServiceBaseFactory* component); | 39 void RemoveComponent(KeyedServiceBaseFactory* component); |
| 40 | 40 |
| 41 // Adds a dependency between two factories. | 41 // Adds a dependency between two factories. |
| 42 void AddEdge(KeyedServiceBaseFactory* depended, | 42 void AddEdge(KeyedServiceBaseFactory* depended, |
| 43 KeyedServiceBaseFactory* dependee); | 43 KeyedServiceBaseFactory* dependee); |
| 44 | 44 |
| 45 // Registers preferences for all services via |registry| associated with | 45 // Registers preferences for all services via |registry| associated with |
| 46 // |context| (the association is managed by the embedder). The |context| | 46 // |context| (the association is managed by the embedder). The |context| |
| 47 // is used as a key to prevent multiple registration during tests. | 47 // is used as a key to prevent multiple registration during tests. |
| 48 void RegisterPrefsForServices(const base::SupportsUserData* context, | 48 void RegisterPrefsForServices(base::SupportsUserData* context, |
| 49 user_prefs::PrefRegistrySyncable* registry); | 49 user_prefs::PrefRegistrySyncable* registry); |
| 50 | 50 |
| 51 // Called upon creation of |context| to create services that want to be | 51 // Called upon creation of |context| to create services that want to be |
| 52 // started at the creation of a context and register service-related | 52 // started at the creation of a context and register service-related |
| 53 // preferences. | 53 // preferences. |
| 54 // | 54 // |
| 55 // To have a KeyedService started when a context is created the method | 55 // To have a KeyedService started when a context is created the method |
| 56 // KeyedServiceBaseFactory::ServiceIsCreatedWithContext() must be overridden | 56 // KeyedServiceBaseFactory::ServiceIsCreatedWithContext() must be overridden |
| 57 // to return true. | 57 // to return true. |
| 58 // | 58 // |
| 59 // If |is_testing_context| then the service will not be started unless the | 59 // If |is_testing_context| then the service will not be started unless the |
| 60 // method KeyedServiceBaseFactory::ServiceIsNULLWhileTesting() return false. | 60 // method KeyedServiceBaseFactory::ServiceIsNULLWhileTesting() return false. |
| 61 void CreateContextServices(base::SupportsUserData* context, | 61 void CreateContextServices(base::SupportsUserData* context, |
| 62 bool is_testing_context); | 62 bool is_testing_context); |
| 63 | 63 |
| 64 // Called upon destruction of |context| to destroy all services associated | 64 // Called upon destruction of |context| to destroy all services associated |
| 65 // with it. | 65 // with it. |
| 66 void DestroyContextServices(base::SupportsUserData* context); | 66 void DestroyContextServices(base::SupportsUserData* context); |
| 67 | 67 |
| 68 #ifndef NDEBUG | 68 #ifndef NDEBUG |
| 69 // Debugging assertion called as part of GetServiceForContext() in debug | 69 // Debugging assertion called as part of GetServiceForContext() in debug |
| 70 // mode. This will NOTREACHED() whenever the |context| is considered stale. | 70 // mode. This will NOTREACHED() whenever the |context| is considered stale. |
| 71 void AssertContextWasntDestroyed(const base::SupportsUserData* context); | 71 void AssertContextWasntDestroyed(base::SupportsUserData* context); |
| 72 | 72 |
| 73 // Marks |context| as live (i.e., not stale). This method can be called as a | 73 // Marks |context| as live (i.e., not stale). This method can be called as a |
| 74 // safeguard against |AssertContextWasntDestroyed()| checks going off due to | 74 // safeguard against |AssertContextWasntDestroyed()| checks going off due to |
| 75 // |context| aliasing am instance from a prior test (i.e., 0xWhatever might | 75 // |context| aliasing am instance from a prior test (i.e., 0xWhatever might |
| 76 // be created, be destroyed, and then a new object might be created at | 76 // be created, be destroyed, and then a new object might be created at |
| 77 // 0xWhatever). | 77 // 0xWhatever). |
| 78 void MarkContextLiveForTesting(const base::SupportsUserData* context); | 78 void MarkContextLiveForTesting(base::SupportsUserData* context); |
| 79 | 79 |
| 80 // Dumps service dependency graph as a Graphviz dot file |dot_file| with a | 80 // Dumps service dependency graph as a Graphviz dot file |dot_file| with a |
| 81 // title |top_level_name|. Helper for |DumpContextDependencies|. | 81 // title |top_level_name|. Helper for |DumpContextDependencies|. |
| 82 void DumpDependenciesAsGraphviz(const std::string& top_level_name, | 82 void DumpDependenciesAsGraphviz(const std::string& top_level_name, |
| 83 const base::FilePath& dot_file) const; | 83 const base::FilePath& dot_file) const; |
| 84 #endif // NDEBUG | 84 #endif // NDEBUG |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 friend class KeyedServiceBaseFactory; | 87 friend class KeyedServiceBaseFactory; |
| 88 | 88 |
| 89 #ifndef NDEBUG | 89 #ifndef NDEBUG |
| 90 // Hook for subclass to dump the dependency graph of service for |context|. | 90 // Hook for subclass to dump the dependency graph of service for |context|. |
| 91 virtual void DumpContextDependencies( | 91 virtual void DumpContextDependencies( |
| 92 const base::SupportsUserData* context) const = 0; | 92 base::SupportsUserData* context) const = 0; |
| 93 #endif // NDEBUG | 93 #endif // NDEBUG |
| 94 | 94 |
| 95 DependencyGraph dependency_graph_; | 95 DependencyGraph dependency_graph_; |
| 96 | 96 |
| 97 #ifndef NDEBUG | 97 #ifndef NDEBUG |
| 98 // A list of context objects that have gone through the Shutdown() phase. | 98 // A list of context objects that have gone through the Shutdown() phase. |
| 99 // These pointers are most likely invalid, but we keep track of their | 99 // These pointers are most likely invalid, but we keep track of their |
| 100 // locations in memory so we can nicely assert if we're asked to do anything | 100 // locations in memory so we can nicely assert if we're asked to do anything |
| 101 // with them. | 101 // with them. |
| 102 std::set<const base::SupportsUserData*> dead_context_pointers_; | 102 std::set<base::SupportsUserData*> dead_context_pointers_; |
| 103 #endif // NDEBUG | 103 #endif // NDEBUG |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 #endif // COMPONENTS_KEYED_SERVICE_CORE_DEPENDENCY_MANAGER_H_ | 106 #endif // COMPONENTS_KEYED_SERVICE_CORE_DEPENDENCY_MANAGER_H_ |
| OLD | NEW |