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