OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_PROFILES_PROFILE_DEPENDENCY_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_PROFILES_PROFILE_DEPENDENCY_MANAGER_H_ |
6 #define CHROME_BROWSER_PROFILES_PROFILE_DEPENDENCY_MANAGER_H_ | 6 #define CHROME_BROWSER_PROFILES_PROFILE_DEPENDENCY_MANAGER_H_ |
7 | 7 |
8 #include <map> | |
9 #include <vector> | |
10 | |
11 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
| 9 #include "chrome/browser/profiles/dependency_graph.h" |
12 | 10 |
13 #ifndef NDEBUG | 11 #ifndef NDEBUG |
14 #include <set> | 12 #include <set> |
15 #include <string> | |
16 #endif | 13 #endif |
17 | 14 |
18 class Profile; | 15 class Profile; |
19 class ProfileKeyedBaseFactory; | 16 class ProfileKeyedBaseFactory; |
20 | 17 |
21 // A singleton that listens for profile destruction notifications and | 18 // A singleton that listens for profile destruction notifications and |
22 // rebroadcasts them to each ProfileKeyedBaseFactory in a safe order based | 19 // rebroadcasts them to each ProfileKeyedBaseFactory in a safe order based |
23 // on the stated dependencies by each service. | 20 // on the stated dependencies by each service. |
24 class ProfileDependencyManager { | 21 class ProfileDependencyManager { |
25 public: | 22 public: |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 // Profile*. | 54 // Profile*. |
58 void AssertProfileWasntDestroyed(Profile* profile); | 55 void AssertProfileWasntDestroyed(Profile* profile); |
59 #endif | 56 #endif |
60 | 57 |
61 static ProfileDependencyManager* GetInstance(); | 58 static ProfileDependencyManager* GetInstance(); |
62 | 59 |
63 private: | 60 private: |
64 friend class ProfileDependencyManagerUnittests; | 61 friend class ProfileDependencyManagerUnittests; |
65 friend struct DefaultSingletonTraits<ProfileDependencyManager>; | 62 friend struct DefaultSingletonTraits<ProfileDependencyManager>; |
66 | 63 |
67 typedef std::multimap<ProfileKeyedBaseFactory*, | |
68 ProfileKeyedBaseFactory*> EdgeMap; | |
69 | |
70 ProfileDependencyManager(); | 64 ProfileDependencyManager(); |
71 virtual ~ProfileDependencyManager(); | 65 virtual ~ProfileDependencyManager(); |
72 | 66 |
73 // Ensures that all the factories have been created before building the | 67 // Ensures that all the factories have been created before building the |
74 // dependency graph. | 68 // dependency graph. |
75 void AssertFactoriesBuilt(); | 69 void AssertFactoriesBuilt(); |
76 | 70 |
77 // Using the dependency graph defined in |edges_|, fills |destruction_order_| | |
78 // so that Observe() can notify each ProfileKeyedBaseFactory in order. | |
79 void BuildDestructionOrder(Profile* profile); | |
80 | |
81 #ifndef NDEBUG | 71 #ifndef NDEBUG |
82 // Creates a dot file with our dependency information. | 72 void DumpProfileDependencies(Profile* profile); |
83 std::string DumpGraphvizDependency(); | |
84 #endif | 73 #endif |
85 | 74 |
86 std::vector<ProfileKeyedBaseFactory*> all_components_; | |
87 | |
88 EdgeMap edges_; | |
89 | |
90 std::vector<ProfileKeyedBaseFactory*> destruction_order_; | |
91 | |
92 // Whether AssertFactoriesBuilt has been done. | 75 // Whether AssertFactoriesBuilt has been done. |
93 bool built_factories_; | 76 bool built_factories_; |
94 | 77 |
| 78 DependencyGraph dependency_graph_; |
| 79 |
95 #ifndef NDEBUG | 80 #ifndef NDEBUG |
96 // A list of profile objects that have gone through the Shutdown() | 81 // A list of profile objects that have gone through the Shutdown() |
97 // phase. These pointers are most likely invalid, but we keep track of their | 82 // phase. These pointers are most likely invalid, but we keep track of their |
98 // locations in memory so we can nicely assert if we're asked to do anything | 83 // locations in memory so we can nicely assert if we're asked to do anything |
99 // with them. | 84 // with them. |
100 std::set<Profile*> dead_profile_pointers_; | 85 std::set<Profile*> dead_profile_pointers_; |
101 #endif | 86 #endif |
102 }; | 87 }; |
103 | 88 |
104 #endif // CHROME_BROWSER_PROFILES_PROFILE_DEPENDENCY_MANAGER_H_ | 89 #endif // CHROME_BROWSER_PROFILES_PROFILE_DEPENDENCY_MANAGER_H_ |
OLD | NEW |