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