[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 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/extensions/extension_system_factory.h" | ||||
6 | |||||
[email protected] | d81bb3e | 2013-05-02 18:17:03 | [diff] [blame] | 7 | #include "chrome/browser/policy/profile_policy_connector_factory.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 8 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 1ba55cf | 2012-06-29 19:11:39 | [diff] [blame] | 9 | #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
[email protected] | 0dd6f203 | 2013-05-20 23:33:40 | [diff] [blame] | 10 | #include "components/browser_context_keyed_service/browser_context_dependency_manager.h" |
[email protected] | 489db084 | 2014-01-22 18:20:03 | [diff] [blame] | 11 | #include "extensions/browser/extension_prefs_factory.h" |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 12 | #include "extensions/browser/extension_registry_factory.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 13 | #include "extensions/browser/extension_system.h" |
[email protected] | da762a8 | 2013-12-07 03:45:58 | [diff] [blame] | 14 | #include "extensions/browser/extensions_browser_client.h" |
[email protected] | 44366da1 | 2014-01-28 01:38:41 | [diff] [blame] | 15 | #include "extensions/browser/renderer_startup_helper.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 16 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 17 | namespace extensions { |
18 | |||||
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 19 | // ExtensionSystemSharedFactory |
20 | |||||
21 | // static | ||||
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 22 | ExtensionSystemImpl::Shared* |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 23 | ExtensionSystemSharedFactory::GetForBrowserContext( |
24 | content::BrowserContext* context) { | ||||
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 25 | return static_cast<ExtensionSystemImpl::Shared*>( |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 26 | GetInstance()->GetServiceForBrowserContext(context, true)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 27 | } |
28 | |||||
29 | // static | ||||
30 | ExtensionSystemSharedFactory* ExtensionSystemSharedFactory::GetInstance() { | ||||
31 | return Singleton<ExtensionSystemSharedFactory>::get(); | ||||
32 | } | ||||
33 | |||||
34 | ExtensionSystemSharedFactory::ExtensionSystemSharedFactory() | ||||
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 35 | : BrowserContextKeyedServiceFactory( |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 36 | "ExtensionSystemShared", |
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 37 | BrowserContextDependencyManager::GetInstance()) { |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 38 | DependsOn(ExtensionPrefsFactory::GetInstance()); |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 39 | // This depends on ExtensionService which depends on ExtensionRegistry. |
40 | DependsOn(ExtensionRegistryFactory::GetInstance()); | ||||
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 41 | DependsOn(GlobalErrorServiceFactory::GetInstance()); |
[email protected] | d81bb3e | 2013-05-02 18:17:03 | [diff] [blame] | 42 | DependsOn(policy::ProfilePolicyConnectorFactory::GetInstance()); |
[email protected] | 44366da1 | 2014-01-28 01:38:41 | [diff] [blame] | 43 | DependsOn(RendererStartupHelperFactory::GetInstance()); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 44 | } |
45 | |||||
46 | ExtensionSystemSharedFactory::~ExtensionSystemSharedFactory() { | ||||
47 | } | ||||
48 | |||||
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 49 | BrowserContextKeyedService* |
50 | ExtensionSystemSharedFactory::BuildServiceInstanceFor( | ||||
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 51 | content::BrowserContext* context) const { |
52 | return new ExtensionSystemImpl::Shared(static_cast<Profile*>(context)); | ||||
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 53 | } |
54 | |||||
[email protected] | 018bf65 | 2013-05-03 23:18:34 | [diff] [blame] | 55 | content::BrowserContext* ExtensionSystemSharedFactory::GetBrowserContextToUse( |
56 | content::BrowserContext* context) const { | ||||
[email protected] | da762a8 | 2013-12-07 03:45:58 | [diff] [blame] | 57 | // Redirected in incognito. |
[email protected] | 8172a9d | 2014-01-09 23:18:30 | [diff] [blame] | 58 | return ExtensionsBrowserClient::Get()->GetOriginalContext(context); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 59 | } |
60 | |||||
61 | // ExtensionSystemFactory | ||||
62 | |||||
63 | // static | ||||
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 64 | ExtensionSystem* ExtensionSystemFactory::GetForBrowserContext( |
65 | content::BrowserContext* context) { | ||||
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 66 | return static_cast<ExtensionSystem*>( |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 67 | GetInstance()->GetServiceForBrowserContext(context, true)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 68 | } |
69 | |||||
70 | // static | ||||
71 | ExtensionSystemFactory* ExtensionSystemFactory::GetInstance() { | ||||
72 | return Singleton<ExtensionSystemFactory>::get(); | ||||
73 | } | ||||
74 | |||||
75 | ExtensionSystemFactory::ExtensionSystemFactory() | ||||
[email protected] | 7048930 | 2014-02-13 15:15:48 | [diff] [blame^] | 76 | : ExtensionSystemProvider("ExtensionSystem", |
77 | BrowserContextDependencyManager::GetInstance()) { | ||||
[email protected] | 8172a9d | 2014-01-09 23:18:30 | [diff] [blame] | 78 | DCHECK(ExtensionsBrowserClient::Get()) |
79 | << "ExtensionSystemFactory must be initialized after BrowserProcess"; | ||||
[email protected] | 7048930 | 2014-02-13 15:15:48 | [diff] [blame^] | 80 | DependsOn(ExtensionSystemSharedFactory::GetInstance()); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 81 | } |
82 | |||||
83 | ExtensionSystemFactory::~ExtensionSystemFactory() { | ||||
84 | } | ||||
85 | |||||
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 86 | BrowserContextKeyedService* ExtensionSystemFactory::BuildServiceInstanceFor( |
[email protected] | 8172a9d | 2014-01-09 23:18:30 | [diff] [blame] | 87 | content::BrowserContext* context) const { |
[email protected] | 7048930 | 2014-02-13 15:15:48 | [diff] [blame^] | 88 | return new ExtensionSystemImpl(static_cast<Profile*>(context)); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 89 | } |
90 | |||||
[email protected] | 018bf65 | 2013-05-03 23:18:34 | [diff] [blame] | 91 | content::BrowserContext* ExtensionSystemFactory::GetBrowserContextToUse( |
92 | content::BrowserContext* context) const { | ||||
[email protected] | da762a8 | 2013-12-07 03:45:58 | [diff] [blame] | 93 | // Separate instance in incognito. |
94 | return context; | ||||
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 95 | } |
96 | |||||
[email protected] | f1484c5 | 2013-05-22 23:25:44 | [diff] [blame] | 97 | bool ExtensionSystemFactory::ServiceIsCreatedWithBrowserContext() const { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 98 | return true; |
99 | } | ||||
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 100 | |
101 | } // namespace extensions |