Home | History | Annotate | Download | only in custom_handlers
      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/custom_handlers/protocol_handler_registry_factory.h"
      6 
      7 #include "base/memory/singleton.h"
      8 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
      9 #include "chrome/browser/extensions/extension_system_factory.h"
     10 #include "chrome/browser/profiles/incognito_helpers.h"
     11 #include "chrome/browser/profiles/profile.h"
     12 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
     13 
     14 // static
     15 ProtocolHandlerRegistryFactory* ProtocolHandlerRegistryFactory::GetInstance() {
     16   return Singleton<ProtocolHandlerRegistryFactory>::get();
     17 }
     18 
     19 // static
     20 ProtocolHandlerRegistry* ProtocolHandlerRegistryFactory::GetForProfile(
     21     Profile* profile) {
     22   return static_cast<ProtocolHandlerRegistry*>(
     23       GetInstance()->GetServiceForBrowserContext(profile, true));
     24 }
     25 
     26 ProtocolHandlerRegistryFactory::ProtocolHandlerRegistryFactory()
     27     : BrowserContextKeyedServiceFactory(
     28         "ProtocolHandlerRegistry",
     29         BrowserContextDependencyManager::GetInstance()) {
     30 }
     31 
     32 ProtocolHandlerRegistryFactory::~ProtocolHandlerRegistryFactory() {
     33 }
     34 
     35 // Will be created when initializing profile_io_data, so we might
     36 // as well have the framework create this along with other
     37 // PKSs to preserve orderly civic conduct :)
     38 bool
     39 ProtocolHandlerRegistryFactory::ServiceIsCreatedWithBrowserContext() const {
     40   return true;
     41 }
     42 
     43 // Allows the produced registry to be used in incognito mode.
     44 content::BrowserContext* ProtocolHandlerRegistryFactory::GetBrowserContextToUse(
     45     content::BrowserContext* context) const {
     46   return chrome::GetBrowserContextRedirectedInIncognito(context);
     47 }
     48 
     49 // Do not create this service for tests. MANY tests will fail
     50 // due to the threading requirements of this service. ALSO,
     51 // not creating this increases test isolation (which is GOOD!)
     52 bool ProtocolHandlerRegistryFactory::ServiceIsNULLWhileTesting() const {
     53   return true;
     54 }
     55 
     56 BrowserContextKeyedService*
     57 ProtocolHandlerRegistryFactory::BuildServiceInstanceFor(
     58     content::BrowserContext* profile) const {
     59   ProtocolHandlerRegistry* registry = new ProtocolHandlerRegistry(
     60       static_cast<Profile*>(profile), new ProtocolHandlerRegistry::Delegate());
     61 
     62 #if defined(OS_CHROMEOS)
     63   // If installing defaults, they must be installed prior calling
     64   // InitProtocolSettings
     65   registry->InstallDefaultsForChromeOS();
     66 #endif
     67 
     68   // Must be called as a part of the creation process.
     69   registry->InitProtocolSettings();
     70 
     71   return registry;
     72 }
     73