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.
5 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
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"
14 ProtocolHandlerRegistryFactory
* ProtocolHandlerRegistryFactory::GetInstance() {
15 return Singleton
<ProtocolHandlerRegistryFactory
>::get();
19 ProtocolHandlerRegistry
* ProtocolHandlerRegistryFactory::GetForProfile(
21 return static_cast<ProtocolHandlerRegistry
*>(
22 GetInstance()->GetServiceForBrowserContext(profile
, true));
25 ProtocolHandlerRegistryFactory::ProtocolHandlerRegistryFactory()
26 : BrowserContextKeyedServiceFactory(
27 "ProtocolHandlerRegistry",
28 BrowserContextDependencyManager::GetInstance()) {
31 ProtocolHandlerRegistryFactory::~ProtocolHandlerRegistryFactory() {
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 :)
38 ProtocolHandlerRegistryFactory::ServiceIsCreatedWithBrowserContext() const {
42 // Allows the produced registry to be used in incognito mode.
43 content::BrowserContext
* ProtocolHandlerRegistryFactory::GetBrowserContextToUse(
44 content::BrowserContext
* context
) const {
45 return chrome::GetBrowserContextRedirectedInIncognito(context
);
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!)
51 bool ProtocolHandlerRegistryFactory::ServiceIsNULLWhileTesting() const {
55 KeyedService
* ProtocolHandlerRegistryFactory::BuildServiceInstanceFor(
56 content::BrowserContext
* profile
) const {
57 ProtocolHandlerRegistry
* registry
= new ProtocolHandlerRegistry(
58 static_cast<Profile
*>(profile
), new ProtocolHandlerRegistry::Delegate());
60 #if defined(OS_CHROMEOS)
61 // If installing defaults, they must be installed prior calling
62 // InitProtocolSettings
63 registry
->InstallDefaultsForChromeOS();
66 // Must be called as a part of the creation process.
67 registry
->InitProtocolSettings();