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 <set> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "components/keyed_service/core/dependency_graph.h" | 11 #include "components/keyed_service/core/dependency_graph.h" |
11 #include "components/keyed_service/core/keyed_service_export.h" | 12 #include "components/keyed_service/core/keyed_service_export.h" |
12 | 13 |
13 #ifndef NDEBUG | |
14 #include <set> | |
15 #endif | |
16 | |
17 class KeyedServiceBaseFactory; | 14 class KeyedServiceBaseFactory; |
18 | 15 |
19 namespace base { | 16 namespace base { |
20 class FilePath; | 17 class FilePath; |
21 class SupportsUserData; | 18 class SupportsUserData; |
22 } | 19 } |
23 | 20 |
24 namespace user_prefs { | 21 namespace user_prefs { |
25 class PrefRegistrySyncable; | 22 class PrefRegistrySyncable; |
26 } | 23 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // | 55 // |
59 // If |is_testing_context| then the service will not be started unless the | 56 // If |is_testing_context| then the service will not be started unless the |
60 // method KeyedServiceBaseFactory::ServiceIsNULLWhileTesting() return false. | 57 // method KeyedServiceBaseFactory::ServiceIsNULLWhileTesting() return false. |
61 void CreateContextServices(base::SupportsUserData* context, | 58 void CreateContextServices(base::SupportsUserData* context, |
62 bool is_testing_context); | 59 bool is_testing_context); |
63 | 60 |
64 // Called upon destruction of |context| to destroy all services associated | 61 // Called upon destruction of |context| to destroy all services associated |
65 // with it. | 62 // with it. |
66 void DestroyContextServices(base::SupportsUserData* context); | 63 void DestroyContextServices(base::SupportsUserData* context); |
67 | 64 |
68 #ifndef NDEBUG | 65 // Runtime assertion called as a part of GetServiceForContext() to check if |
69 // Debugging assertion called as part of GetServiceForContext() in debug | 66 // |context| is considered stale. This will NOTREACHED() or |
70 // mode. This will NOTREACHED() whenever the |context| is considered stale. | 67 // base::debug::DumpWithoutCrashing() depending on the DCHECK_IS_ON() value. |
71 void AssertContextWasntDestroyed(base::SupportsUserData* context); | 68 void AssertContextWasntDestroyed(base::SupportsUserData* context) const; |
72 | 69 |
73 // Marks |context| as live (i.e., not stale). This method can be called as a | 70 // Marks |context| as live (i.e., not stale). This method can be called as a |
74 // safeguard against |AssertContextWasntDestroyed()| checks going off due to | 71 // safeguard against |AssertContextWasntDestroyed()| checks going off due to |
75 // |context| aliasing am instance from a prior test (i.e., 0xWhatever might | 72 // |context| aliasing an instance from a prior construction (i.e., 0xWhatever |
76 // be created, be destroyed, and then a new object might be created at | 73 // might be created, be destroyed, and then a new object might be created at |
77 // 0xWhatever). | 74 // 0xWhatever). |
78 void MarkContextLiveForTesting(base::SupportsUserData* context); | 75 void MarkContextLive(base::SupportsUserData* context); |
79 | 76 |
| 77 #ifndef NDEBUG |
80 // Dumps service dependency graph as a Graphviz dot file |dot_file| with a | 78 // Dumps service dependency graph as a Graphviz dot file |dot_file| with a |
81 // title |top_level_name|. Helper for |DumpContextDependencies|. | 79 // title |top_level_name|. Helper for |DumpContextDependencies|. |
82 void DumpDependenciesAsGraphviz(const std::string& top_level_name, | 80 void DumpDependenciesAsGraphviz(const std::string& top_level_name, |
83 const base::FilePath& dot_file) const; | 81 const base::FilePath& dot_file) const; |
84 #endif // NDEBUG | 82 #endif // NDEBUG |
85 | 83 |
86 private: | 84 private: |
87 friend class KeyedServiceBaseFactory; | 85 friend class KeyedServiceBaseFactory; |
88 | 86 |
89 #ifndef NDEBUG | 87 #ifndef NDEBUG |
90 // Hook for subclass to dump the dependency graph of service for |context|. | 88 // Hook for subclass to dump the dependency graph of service for |context|. |
91 virtual void DumpContextDependencies( | 89 virtual void DumpContextDependencies( |
92 base::SupportsUserData* context) const = 0; | 90 base::SupportsUserData* context) const = 0; |
93 #endif // NDEBUG | 91 #endif // NDEBUG |
94 | 92 |
95 DependencyGraph dependency_graph_; | 93 DependencyGraph dependency_graph_; |
96 | 94 |
97 #ifndef NDEBUG | |
98 // A list of context objects that have gone through the Shutdown() phase. | 95 // 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 | 96 // 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 | 97 // locations in memory so we can nicely assert if we're asked to do anything |
101 // with them. | 98 // with them. |
102 std::set<base::SupportsUserData*> dead_context_pointers_; | 99 std::set<base::SupportsUserData*> dead_context_pointers_; |
103 #endif // NDEBUG | |
104 }; | 100 }; |
105 | 101 |
106 #endif // COMPONENTS_KEYED_SERVICE_CORE_DEPENDENCY_MANAGER_H_ | 102 #endif // COMPONENTS_KEYED_SERVICE_CORE_DEPENDENCY_MANAGER_H_ |
OLD | NEW |