protocol_handler_registry_factory.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
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/profile.h"
11#include "chrome/browser/profiles/profile_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()->GetServiceForProfile(profile, true));
23}
24
25ProtocolHandlerRegistryFactory::ProtocolHandlerRegistryFactory()
26    : ProfileKeyedServiceFactory("ProtocolHandlerRegistry",
27                                 ProfileDependencyManager::GetInstance()) {
28}
29
30ProtocolHandlerRegistryFactory::~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 :)
36bool ProtocolHandlerRegistryFactory::ServiceIsCreatedWithProfile() const {
37  return true;
38}
39
40// Allows the produced registry to be used in incognito mode.
41bool ProtocolHandlerRegistryFactory::ServiceRedirectedInIncognito() const {
42  return true;
43}
44
45// Do not create this service for tests. MANY tests will fail
46// due to the threading requirements of this service. ALSO,
47// not creating this increases test isolation (which is GOOD!)
48bool ProtocolHandlerRegistryFactory::ServiceIsNULLWhileTesting() const {
49  return true;
50}
51
52ProfileKeyedService* ProtocolHandlerRegistryFactory::BuildServiceInstanceFor(
53    Profile* profile) const {
54  ProtocolHandlerRegistry* registry = new ProtocolHandlerRegistry(
55      profile, new ProtocolHandlerRegistry::Delegate());
56
57#if defined(OS_CHROMEOS)
58  // If installing defaults, they must be installed prior calling
59  // InitProtocolSettings
60  registry->InstallDefaultsForChromeOS();
61#endif
62
63  // Must be called as a part of the creation process.
64  registry->InitProtocolSettings();
65
66  return registry;
67}
68