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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_DEPENDENCY_MANAGER_H_
6 #define COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_DEPENDENCY_MANAGER_H_
8 #include "base/memory/singleton.h"
9 #include "components/browser_context_keyed_service/browser_context_keyed_service_export.h"
10 #include "components/browser_context_keyed_service/dependency_graph.h"
16 class BrowserContextKeyedBaseFactory
;
22 // A singleton that listens for context destruction notifications and
23 // rebroadcasts them to each BrowserContextKeyedBaseFactory in a safe order
24 // based on the stated dependencies by each service.
25 class BROWSER_CONTEXT_KEYED_SERVICE_EXPORT BrowserContextDependencyManager
{
27 // Adds/Removes a component from our list of live components. Removing will
28 // also remove live dependency links.
29 void AddComponent(BrowserContextKeyedBaseFactory
* component
);
30 void RemoveComponent(BrowserContextKeyedBaseFactory
* component
);
32 // Adds a dependency between two factories.
33 void AddEdge(BrowserContextKeyedBaseFactory
* depended
,
34 BrowserContextKeyedBaseFactory
* dependee
);
36 // Called by each BrowserContext to alert us of its creation. Several services
37 // want to be started when a context is created. Testing configuration is also
38 // done at this time. (If you want your BrowserContextKeyedService to be
39 // started with the BrowserContext, override BrowserContextKeyedBaseFactory::
40 // ServiceIsCreatedWithBrowserContext() to return true.)
41 void CreateBrowserContextServices(content::BrowserContext
* context
,
42 bool is_testing_context
);
44 // Called by each BrowserContext to alert us that we should destroy services
45 // associated with it.
46 void DestroyBrowserContextServices(content::BrowserContext
* context
);
49 // Debugging assertion called as part of GetServiceForBrowserContext in debug
50 // mode. This will NOTREACHED() whenever the user is trying to access a stale
52 void AssertBrowserContextWasntDestroyed(content::BrowserContext
* context
);
55 static BrowserContextDependencyManager
* GetInstance();
58 friend class BrowserContextDependencyManagerUnittests
;
59 friend struct DefaultSingletonTraits
<BrowserContextDependencyManager
>;
61 BrowserContextDependencyManager();
62 virtual ~BrowserContextDependencyManager();
65 void DumpBrowserContextDependencies(content::BrowserContext
* context
);
68 DependencyGraph dependency_graph_
;
71 // A list of context objects that have gone through the Shutdown()
72 // phase. These pointers are most likely invalid, but we keep track of their
73 // locations in memory so we can nicely assert if we're asked to do anything
75 std::set
<content::BrowserContext
*> dead_context_pointers_
;
79 #endif // COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_DEPENDENCY_MANAGER_H_