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 #include "chrome/browser/extensions/extension_system_factory.h"
7 #include "chrome/browser/policy/profile_policy_connector_factory.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
10 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
11 #include "extensions/browser/extension_prefs_factory.h"
12 #include "extensions/browser/extension_registry_factory.h"
13 #include "extensions/browser/extension_system.h"
14 #include "extensions/browser/extensions_browser_client.h"
15 #include "extensions/browser/renderer_startup_helper.h"
17 namespace extensions
{
19 // ExtensionSystemSharedFactory
22 ExtensionSystemImpl::Shared
*
23 ExtensionSystemSharedFactory::GetForBrowserContext(
24 content::BrowserContext
* context
) {
25 return static_cast<ExtensionSystemImpl::Shared
*>(
26 GetInstance()->GetServiceForBrowserContext(context
, true));
30 ExtensionSystemSharedFactory
* ExtensionSystemSharedFactory::GetInstance() {
31 return Singleton
<ExtensionSystemSharedFactory
>::get();
34 ExtensionSystemSharedFactory::ExtensionSystemSharedFactory()
35 : BrowserContextKeyedServiceFactory(
36 "ExtensionSystemShared",
37 BrowserContextDependencyManager::GetInstance()) {
38 DependsOn(ExtensionPrefsFactory::GetInstance());
39 // This depends on ExtensionService which depends on ExtensionRegistry.
40 DependsOn(ExtensionRegistryFactory::GetInstance());
41 DependsOn(GlobalErrorServiceFactory::GetInstance());
42 DependsOn(policy::ProfilePolicyConnectorFactory::GetInstance());
43 DependsOn(RendererStartupHelperFactory::GetInstance());
46 ExtensionSystemSharedFactory::~ExtensionSystemSharedFactory() {
49 BrowserContextKeyedService
*
50 ExtensionSystemSharedFactory::BuildServiceInstanceFor(
51 content::BrowserContext
* context
) const {
52 return new ExtensionSystemImpl::Shared(static_cast<Profile
*>(context
));
55 content::BrowserContext
* ExtensionSystemSharedFactory::GetBrowserContextToUse(
56 content::BrowserContext
* context
) const {
57 // Redirected in incognito.
58 return ExtensionsBrowserClient::Get()->GetOriginalContext(context
);
61 // ExtensionSystemFactory
64 ExtensionSystem
* ExtensionSystemFactory::GetForBrowserContext(
65 content::BrowserContext
* context
) {
66 return static_cast<ExtensionSystem
*>(
67 GetInstance()->GetServiceForBrowserContext(context
, true));
71 ExtensionSystemFactory
* ExtensionSystemFactory::GetInstance() {
72 return Singleton
<ExtensionSystemFactory
>::get();
75 ExtensionSystemFactory::ExtensionSystemFactory()
76 : ExtensionSystemProvider("ExtensionSystem",
77 BrowserContextDependencyManager::GetInstance()) {
78 DCHECK(ExtensionsBrowserClient::Get())
79 << "ExtensionSystemFactory must be initialized after BrowserProcess";
80 DependsOn(ExtensionSystemSharedFactory::GetInstance());
83 ExtensionSystemFactory::~ExtensionSystemFactory() {
86 BrowserContextKeyedService
* ExtensionSystemFactory::BuildServiceInstanceFor(
87 content::BrowserContext
* context
) const {
88 return new ExtensionSystemImpl(static_cast<Profile
*>(context
));
91 content::BrowserContext
* ExtensionSystemFactory::GetBrowserContextToUse(
92 content::BrowserContext
* context
) const {
93 // Separate instance in incognito.
97 bool ExtensionSystemFactory::ServiceIsCreatedWithBrowserContext() const {
101 } // namespace extensions