| 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 COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_DEPENDENCY_MANA
GER_H_ | 5 #ifndef COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_DEPENDENCY_MANA
GER_H_ |
| 6 #define COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_DEPENDENCY_MANA
GER_H_ | 6 #define COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_DEPENDENCY_MANA
GER_H_ |
| 7 | 7 |
| 8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
| 9 #include "components/browser_context_keyed_service/dependency_graph.h" | 9 #include "components/browser_context_keyed_service/dependency_graph.h" |
| 10 | 10 |
| 11 #ifndef NDEBUG | 11 #ifndef NDEBUG |
| 12 #include <set> | 12 #include <set> |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 class ProfileKeyedBaseFactory; | 15 class BrowserContextKeyedBaseFactory; |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 class BrowserContext; | 18 class BrowserContext; |
| 19 } | 19 } |
| 20 | 20 |
| 21 // A singleton that listens for profile destruction notifications and | 21 // A singleton that listens for context destruction notifications and |
| 22 // rebroadcasts them to each ProfileKeyedBaseFactory in a safe order based | 22 // rebroadcasts them to each BrowserContextKeyedBaseFactory in a safe order |
| 23 // on the stated dependencies by each service. | 23 // based on the stated dependencies by each service. |
| 24 class ProfileDependencyManager { | 24 class BrowserContextDependencyManager { |
| 25 public: | 25 public: |
| 26 // Adds/Removes a component from our list of live components. Removing will | 26 // Adds/Removes a component from our list of live components. Removing will |
| 27 // also remove live dependency links. | 27 // also remove live dependency links. |
| 28 void AddComponent(ProfileKeyedBaseFactory* component); | 28 void AddComponent(BrowserContextKeyedBaseFactory* component); |
| 29 void RemoveComponent(ProfileKeyedBaseFactory* component); | 29 void RemoveComponent(BrowserContextKeyedBaseFactory* component); |
| 30 | 30 |
| 31 // Adds a dependency between two factories. | 31 // Adds a dependency between two factories. |
| 32 void AddEdge(ProfileKeyedBaseFactory* depended, | 32 void AddEdge(BrowserContextKeyedBaseFactory* depended, |
| 33 ProfileKeyedBaseFactory* dependee); | 33 BrowserContextKeyedBaseFactory* dependee); |
| 34 | 34 |
| 35 // Called by each Profile to alert us of its creation. Several services want | 35 // Called by each BrowserContext to alert us of its creation. Several services |
| 36 // to be started when a profile is created. Testing configuration is also | 36 // want to be started when a context is created. Testing configuration is also |
| 37 // done at this time. (If you want your ProfileKeyedService to be started | 37 // done at this time. (If you want your BrowserContextKeyedService to be |
| 38 // with the Profile, override ProfileKeyedBaseFactory:: | 38 // started with the BrowserContext, override BrowserContextKeyedBaseFactory:: |
| 39 // ServiceIsCreatedWithProfile() to return true.) | 39 // ServiceIsCreatedWithBrowserContext() to return true.) |
| 40 void CreateProfileServices(content::BrowserContext* profile, | 40 void CreateBrowserContextServices(content::BrowserContext* context, |
| 41 bool is_testing_profile); | 41 bool is_testing_context); |
| 42 | 42 |
| 43 // Called by each Profile to alert us that we should destroy services | 43 // Called by each BrowserContext to alert us that we should destroy services |
| 44 // associated with it. | 44 // associated with it. |
| 45 // | 45 void DestroyBrowserContextServices(content::BrowserContext* context); |
| 46 // Why not use the existing PROFILE_DESTROYED notification? | |
| 47 // | |
| 48 // - Because we need to do everything here after the application has handled | |
| 49 // being notified about PROFILE_DESTROYED. | |
| 50 // - Because this class is a singleton and Singletons can't rely on | |
| 51 // NotificationService in unit tests because NotificationService is | |
| 52 // replaced in many tests. | |
| 53 void DestroyProfileServices(content::BrowserContext* profile); | |
| 54 | 46 |
| 55 #ifndef NDEBUG | 47 #ifndef NDEBUG |
| 56 // Debugging assertion called as part of GetServiceForProfile in debug | 48 // Debugging assertion called as part of GetServiceForBrowserContext in debug |
| 57 // mode. This will NOTREACHED() whenever the user is trying to access a stale | 49 // mode. This will NOTREACHED() whenever the user is trying to access a stale |
| 58 // Profile*. | 50 // BrowserContext*. |
| 59 void AssertProfileWasntDestroyed(content::BrowserContext* profile); | 51 void AssertBrowserContextWasntDestroyed(content::BrowserContext* context); |
| 60 #endif | 52 #endif |
| 61 | 53 |
| 62 static ProfileDependencyManager* GetInstance(); | 54 static BrowserContextDependencyManager* GetInstance(); |
| 63 | 55 |
| 64 private: | 56 private: |
| 65 friend class ProfileDependencyManagerUnittests; | 57 friend class BrowserContextDependencyManagerUnittests; |
| 66 friend struct DefaultSingletonTraits<ProfileDependencyManager>; | 58 friend struct DefaultSingletonTraits<BrowserContextDependencyManager>; |
| 67 | 59 |
| 68 ProfileDependencyManager(); | 60 BrowserContextDependencyManager(); |
| 69 virtual ~ProfileDependencyManager(); | 61 virtual ~BrowserContextDependencyManager(); |
| 70 | 62 |
| 71 #ifndef NDEBUG | 63 #ifndef NDEBUG |
| 72 void DumpProfileDependencies(content::BrowserContext* profile); | 64 void DumpBrowserContextDependencies(content::BrowserContext* context); |
| 73 #endif | 65 #endif |
| 74 | 66 |
| 75 DependencyGraph dependency_graph_; | 67 DependencyGraph dependency_graph_; |
| 76 | 68 |
| 77 #ifndef NDEBUG | 69 #ifndef NDEBUG |
| 78 // A list of profile objects that have gone through the Shutdown() | 70 // A list of context objects that have gone through the Shutdown() |
| 79 // phase. These pointers are most likely invalid, but we keep track of their | 71 // phase. These pointers are most likely invalid, but we keep track of their |
| 80 // locations in memory so we can nicely assert if we're asked to do anything | 72 // locations in memory so we can nicely assert if we're asked to do anything |
| 81 // with them. | 73 // with them. |
| 82 std::set<content::BrowserContext*> dead_profile_pointers_; | 74 std::set<content::BrowserContext*> dead_context_pointers_; |
| 83 #endif | 75 #endif |
| 84 }; | 76 }; |
| 85 | 77 |
| 86 #endif // COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_DEPENDENCY_M
ANAGER_H_ | 78 #endif // COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_DEPENDENCY_M
ANAGER_H_ |
| OLD | NEW |