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/extensions/extension_management.h" 8#include "chrome/browser/policy/profile_policy_connector_factory.h" 9#include "chrome/browser/profiles/profile.h" 10#include "chrome/browser/ui/global_error/global_error_service_factory.h" 11#include "components/keyed_service/content/browser_context_dependency_manager.h" 12#include "extensions/browser/extension_prefs_factory.h" 13#include "extensions/browser/extension_registry_factory.h" 14#include "extensions/browser/extension_system.h" 15#include "extensions/browser/extensions_browser_client.h" 16#include "extensions/browser/renderer_startup_helper.h" 17 18namespace extensions { 19 20// ExtensionSystemSharedFactory 21 22// static 23ExtensionSystemImpl::Shared* 24ExtensionSystemSharedFactory::GetForBrowserContext( 25 content::BrowserContext* context) { 26 return static_cast<ExtensionSystemImpl::Shared*>( 27 GetInstance()->GetServiceForBrowserContext(context, true)); 28} 29 30// static 31ExtensionSystemSharedFactory* ExtensionSystemSharedFactory::GetInstance() { 32 return Singleton<ExtensionSystemSharedFactory>::get(); 33} 34 35ExtensionSystemSharedFactory::ExtensionSystemSharedFactory() 36 : BrowserContextKeyedServiceFactory( 37 "ExtensionSystemShared", 38 BrowserContextDependencyManager::GetInstance()) { 39 DependsOn(ExtensionPrefsFactory::GetInstance()); 40 DependsOn(ExtensionManagementFactory::GetInstance()); 41 // This depends on ExtensionService which depends on ExtensionRegistry. 42 DependsOn(ExtensionRegistryFactory::GetInstance()); 43 DependsOn(GlobalErrorServiceFactory::GetInstance()); 44 DependsOn(policy::ProfilePolicyConnectorFactory::GetInstance()); 45 DependsOn(RendererStartupHelperFactory::GetInstance()); 46} 47 48ExtensionSystemSharedFactory::~ExtensionSystemSharedFactory() { 49} 50 51KeyedService* ExtensionSystemSharedFactory::BuildServiceInstanceFor( 52 content::BrowserContext* context) const { 53 return new ExtensionSystemImpl::Shared(static_cast<Profile*>(context)); 54} 55 56content::BrowserContext* ExtensionSystemSharedFactory::GetBrowserContextToUse( 57 content::BrowserContext* context) const { 58 // Redirected in incognito. 59 return ExtensionsBrowserClient::Get()->GetOriginalContext(context); 60} 61 62// ExtensionSystemFactory 63 64// static 65ExtensionSystem* ExtensionSystemFactory::GetForBrowserContext( 66 content::BrowserContext* context) { 67 return static_cast<ExtensionSystem*>( 68 GetInstance()->GetServiceForBrowserContext(context, true)); 69} 70 71// static 72ExtensionSystemFactory* ExtensionSystemFactory::GetInstance() { 73 return Singleton<ExtensionSystemFactory>::get(); 74} 75 76ExtensionSystemFactory::ExtensionSystemFactory() 77 : ExtensionSystemProvider("ExtensionSystem", 78 BrowserContextDependencyManager::GetInstance()) { 79 DCHECK(ExtensionsBrowserClient::Get()) 80 << "ExtensionSystemFactory must be initialized after BrowserProcess"; 81 DependsOn(ExtensionSystemSharedFactory::GetInstance()); 82} 83 84ExtensionSystemFactory::~ExtensionSystemFactory() { 85} 86 87KeyedService* ExtensionSystemFactory::BuildServiceInstanceFor( 88 content::BrowserContext* context) const { 89 return new ExtensionSystemImpl(static_cast<Profile*>(context)); 90} 91 92content::BrowserContext* ExtensionSystemFactory::GetBrowserContextToUse( 93 content::BrowserContext* context) const { 94 // Separate instance in incognito. 95 return context; 96} 97 98bool ExtensionSystemFactory::ServiceIsCreatedWithBrowserContext() const { 99 return true; 100} 101 102} // namespace extensions 103