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. 4 5 #include "chrome/browser/extensions/extension_system_factory.h" 6 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/keyed_service/content/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" 16 17 namespace extensions { 18 19 // ExtensionSystemSharedFactory 20 21 // static 22 ExtensionSystemImpl::Shared* 23 ExtensionSystemSharedFactory::GetForBrowserContext( 24 content::BrowserContext* context) { 25 return static_cast<ExtensionSystemImpl::Shared*>( 26 GetInstance()->GetServiceForBrowserContext(context, true)); 27 } 28 29 // static 30 ExtensionSystemSharedFactory* ExtensionSystemSharedFactory::GetInstance() { 31 return Singleton<ExtensionSystemSharedFactory>::get(); 32 } 33 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()); 44 } 45 46 ExtensionSystemSharedFactory::~ExtensionSystemSharedFactory() { 47 } 48 49 KeyedService* ExtensionSystemSharedFactory::BuildServiceInstanceFor( 50 content::BrowserContext* context) const { 51 return new ExtensionSystemImpl::Shared(static_cast<Profile*>(context)); 52 } 53 54 content::BrowserContext* ExtensionSystemSharedFactory::GetBrowserContextToUse( 55 content::BrowserContext* context) const { 56 // Redirected in incognito. 57 return ExtensionsBrowserClient::Get()->GetOriginalContext(context); 58 } 59 60 // ExtensionSystemFactory 61 62 // static 63 ExtensionSystem* ExtensionSystemFactory::GetForBrowserContext( 64 content::BrowserContext* context) { 65 return static_cast<ExtensionSystem*>( 66 GetInstance()->GetServiceForBrowserContext(context, true)); 67 } 68 69 // static 70 ExtensionSystemFactory* ExtensionSystemFactory::GetInstance() { 71 return Singleton<ExtensionSystemFactory>::get(); 72 } 73 74 ExtensionSystemFactory::ExtensionSystemFactory() 75 : ExtensionSystemProvider("ExtensionSystem", 76 BrowserContextDependencyManager::GetInstance()) { 77 DCHECK(ExtensionsBrowserClient::Get()) 78 << "ExtensionSystemFactory must be initialized after BrowserProcess"; 79 DependsOn(ExtensionSystemSharedFactory::GetInstance()); 80 } 81 82 ExtensionSystemFactory::~ExtensionSystemFactory() { 83 } 84 85 KeyedService* ExtensionSystemFactory::BuildServiceInstanceFor( 86 content::BrowserContext* context) const { 87 return new ExtensionSystemImpl(static_cast<Profile*>(context)); 88 } 89 90 content::BrowserContext* ExtensionSystemFactory::GetBrowserContextToUse( 91 content::BrowserContext* context) const { 92 // Separate instance in incognito. 93 return context; 94 } 95 96 bool ExtensionSystemFactory::ServiceIsCreatedWithBrowserContext() const { 97 return true; 98 } 99 100 } // namespace extensions 101