protocol_handler_registry_factory.cc revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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 "chrome/browser/profiles/profile_dependency_manager.h" 13 14// static 15ProtocolHandlerRegistryFactory* ProtocolHandlerRegistryFactory::GetInstance() { 16 return Singleton<ProtocolHandlerRegistryFactory>::get(); 17} 18 19// static 20ProtocolHandlerRegistry* ProtocolHandlerRegistryFactory::GetForProfile( 21 Profile* profile) { 22 return static_cast<ProtocolHandlerRegistry*>( 23 GetInstance()->GetServiceForProfile(profile, true)); 24} 25 26ProtocolHandlerRegistryFactory::ProtocolHandlerRegistryFactory() 27 : ProfileKeyedServiceFactory("ProtocolHandlerRegistry", 28 ProfileDependencyManager::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 ProtocolHandlerRegistryFactory::ServiceIsCreatedWithProfile() const { 38 return true; 39} 40 41// Allows the produced registry to be used in incognito mode. 42content::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!) 50bool ProtocolHandlerRegistryFactory::ServiceIsNULLWhileTesting() const { 51 return true; 52} 53 54ProfileKeyedService* ProtocolHandlerRegistryFactory::BuildServiceInstanceFor( 55 content::BrowserContext* profile) const { 56 ProtocolHandlerRegistry* registry = new ProtocolHandlerRegistry( 57 static_cast<Profile*>(profile), 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