Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / extensions / extension_system_factory.cc
blobbfe1b513290a734fb6e958528687862c00b471a3
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/extensions/extension_system_factory.h"
7 #include "chrome/browser/extensions/extension_prefs_factory.h"
8 #include "chrome/browser/extensions/extension_system.h"
9 #include "chrome/browser/policy/profile_policy_connector_factory.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
12 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
13 #include "extensions/browser/extension_registry_factory.h"
14 #include "extensions/browser/extensions_browser_client.h"
16 namespace extensions {
18 // ExtensionSystemSharedFactory
20 // static
21 ExtensionSystemImpl::Shared*
22 ExtensionSystemSharedFactory::GetForProfile(Profile* profile) {
23 return static_cast<ExtensionSystemImpl::Shared*>(
24 GetInstance()->GetServiceForBrowserContext(profile, true));
27 // static
28 ExtensionSystemSharedFactory* ExtensionSystemSharedFactory::GetInstance() {
29 return Singleton<ExtensionSystemSharedFactory>::get();
32 ExtensionSystemSharedFactory::ExtensionSystemSharedFactory()
33 : BrowserContextKeyedServiceFactory(
34 "ExtensionSystemShared",
35 BrowserContextDependencyManager::GetInstance()) {
36 DependsOn(ExtensionPrefsFactory::GetInstance());
37 // This depends on ExtensionService which depends on ExtensionRegistry.
38 DependsOn(ExtensionRegistryFactory::GetInstance());
39 DependsOn(GlobalErrorServiceFactory::GetInstance());
40 DependsOn(policy::ProfilePolicyConnectorFactory::GetInstance());
43 ExtensionSystemSharedFactory::~ExtensionSystemSharedFactory() {
46 BrowserContextKeyedService*
47 ExtensionSystemSharedFactory::BuildServiceInstanceFor(
48 content::BrowserContext* profile) const {
49 return new ExtensionSystemImpl::Shared(static_cast<Profile*>(profile));
52 content::BrowserContext* ExtensionSystemSharedFactory::GetBrowserContextToUse(
53 content::BrowserContext* context) const {
54 // Redirected in incognito.
55 return ExtensionsBrowserClient::Get()->GetOriginalContext(context);
58 // ExtensionSystemFactory
60 // static
61 ExtensionSystem* ExtensionSystemFactory::GetForProfile(Profile* profile) {
62 return static_cast<ExtensionSystem*>(
63 GetInstance()->GetServiceForBrowserContext(profile, true));
66 // static
67 ExtensionSystemFactory* ExtensionSystemFactory::GetInstance() {
68 return Singleton<ExtensionSystemFactory>::get();
71 ExtensionSystemFactory::ExtensionSystemFactory()
72 : BrowserContextKeyedServiceFactory(
73 "ExtensionSystem",
74 BrowserContextDependencyManager::GetInstance()) {
75 DCHECK(ExtensionsBrowserClient::Get())
76 << "ExtensionSystemFactory must be initialized after BrowserProcess";
77 std::vector<BrowserContextKeyedServiceFactory*> dependencies =
78 ExtensionsBrowserClient::Get()->GetExtensionSystemDependencies();
79 for (size_t i = 0; i < dependencies.size(); ++i)
80 DependsOn(dependencies[i]);
83 ExtensionSystemFactory::~ExtensionSystemFactory() {
86 BrowserContextKeyedService* ExtensionSystemFactory::BuildServiceInstanceFor(
87 content::BrowserContext* context) const {
88 return ExtensionsBrowserClient::Get()->CreateExtensionSystem(context);
91 content::BrowserContext* ExtensionSystemFactory::GetBrowserContextToUse(
92 content::BrowserContext* context) const {
93 // Separate instance in incognito.
94 return context;
97 bool ExtensionSystemFactory::ServiceIsCreatedWithBrowserContext() const {
98 return true;
101 } // namespace extensions