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