1 // Copyright 2014 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_IMPL_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_IMPL_H_
8 #include "base/memory/scoped_vector.h"
9 #include "extensions/browser/extension_system.h"
10 #include "extensions/common/one_shot_event.h"
14 namespace extensions
{
16 class ContentVerifier
;
17 class DeclarativeUserScriptMaster
;
18 class ExtensionSystemSharedFactory
;
19 class ExtensionWarningBadgeService
;
20 class NavigationObserver
;
21 class SharedUserScriptMaster
;
22 class StateStoreNotificationObserver
;
24 // The ExtensionSystem for ProfileImpl and OffTheRecordProfileImpl.
25 // Implementation details: non-shared services are owned by
26 // ExtensionSystemImpl, a KeyedService with separate incognito
27 // instances. A private Shared class (also a KeyedService,
28 // but with a shared instance for incognito) keeps the common services.
29 class ExtensionSystemImpl
: public ExtensionSystem
{
31 explicit ExtensionSystemImpl(Profile
* profile
);
32 virtual ~ExtensionSystemImpl();
34 // KeyedService implementation.
35 virtual void Shutdown() override
;
37 virtual void InitForRegularProfile(bool extensions_enabled
) override
;
39 virtual ExtensionService
* extension_service() override
; // shared
40 virtual RuntimeData
* runtime_data() override
; // shared
41 virtual ManagementPolicy
* management_policy() override
; // shared
43 virtual SharedUserScriptMaster
* shared_user_script_master() override
;
44 virtual ProcessManager
* process_manager() override
;
45 virtual StateStore
* state_store() override
; // shared
46 virtual StateStore
* rules_store() override
; // shared
47 virtual LazyBackgroundTaskQueue
* lazy_background_task_queue()
49 virtual InfoMap
* info_map() override
; // shared
50 virtual EventRouter
* event_router() override
; // shared
51 virtual WarningService
* warning_service() override
;
52 virtual Blacklist
* blacklist() override
; // shared
53 virtual ErrorConsole
* error_console() override
;
54 virtual InstallVerifier
* install_verifier() override
;
55 virtual QuotaService
* quota_service() override
; // shared
57 virtual void RegisterExtensionWithRequestContexts(
58 const Extension
* extension
) override
;
60 virtual void UnregisterExtensionWithRequestContexts(
61 const std::string
& extension_id
,
62 const UnloadedExtensionInfo::Reason reason
) override
;
64 virtual const OneShotEvent
& ready() const override
;
65 virtual ContentVerifier
* content_verifier() override
; // shared
66 virtual scoped_ptr
<ExtensionSet
> GetDependentExtensions(
67 const Extension
* extension
) override
;
69 virtual DeclarativeUserScriptMaster
*
70 GetDeclarativeUserScriptMasterByExtension(
71 const ExtensionId
& extension_id
) override
; // shared
74 friend class ExtensionSystemSharedFactory
;
76 // Owns the Extension-related systems that have a single instance
77 // shared between normal and incognito profiles.
78 class Shared
: public KeyedService
{
80 explicit Shared(Profile
* profile
);
83 // Initialization takes place in phases.
84 virtual void InitPrefs();
85 // This must not be called until all the providers have been created.
86 void RegisterManagementPolicyProviders();
87 void Init(bool extensions_enabled
);
89 // KeyedService implementation.
90 virtual void Shutdown() override
;
92 StateStore
* state_store();
93 StateStore
* rules_store();
94 ExtensionService
* extension_service();
95 RuntimeData
* runtime_data();
96 ManagementPolicy
* management_policy();
97 SharedUserScriptMaster
* shared_user_script_master();
98 Blacklist
* blacklist();
100 LazyBackgroundTaskQueue
* lazy_background_task_queue();
101 EventRouter
* event_router();
102 WarningService
* warning_service();
103 ErrorConsole
* error_console();
104 InstallVerifier
* install_verifier();
105 QuotaService
* quota_service();
106 const OneShotEvent
& ready() const { return ready_
; }
107 ContentVerifier
* content_verifier();
109 DeclarativeUserScriptMaster
* GetDeclarativeUserScriptMasterByExtension(
110 const ExtensionId
& extension_id
);
115 // The services that are shared between normal and incognito profiles.
117 scoped_ptr
<StateStore
> state_store_
;
118 scoped_ptr
<StateStoreNotificationObserver
>
119 state_store_notification_observer_
;
120 scoped_ptr
<StateStore
> rules_store_
;
121 // LazyBackgroundTaskQueue is a dependency of
122 // MessageService and EventRouter.
123 scoped_ptr
<LazyBackgroundTaskQueue
> lazy_background_task_queue_
;
124 scoped_ptr
<EventRouter
> event_router_
;
125 scoped_ptr
<NavigationObserver
> navigation_observer_
;
126 // Shared memory region manager for scripts statically declared in extension
127 // manifests. This region is shared between all extensions.
128 scoped_ptr
<SharedUserScriptMaster
> shared_user_script_master_
;
129 // Shared memory region manager for programmatically declared scripts, one
130 // per extension. Managers are instantiated the first time the declarative
131 // API is used by an extension to request content scripts.
132 ScopedVector
<DeclarativeUserScriptMaster
> declarative_user_script_masters_
;
133 scoped_ptr
<Blacklist
> blacklist_
;
134 scoped_ptr
<RuntimeData
> runtime_data_
;
135 // ExtensionService depends on StateStore, Blacklist and RuntimeData.
136 scoped_ptr
<ExtensionService
> extension_service_
;
137 scoped_ptr
<ManagementPolicy
> management_policy_
;
138 // extension_info_map_ needs to outlive process_manager_.
139 scoped_refptr
<InfoMap
> extension_info_map_
;
140 scoped_ptr
<WarningService
> warning_service_
;
141 scoped_ptr
<ExtensionWarningBadgeService
> extension_warning_badge_service_
;
142 scoped_ptr
<ErrorConsole
> error_console_
;
143 scoped_ptr
<InstallVerifier
> install_verifier_
;
144 scoped_ptr
<QuotaService
> quota_service_
;
146 // For verifying the contents of extensions read from disk.
147 scoped_refptr
<ContentVerifier
> content_verifier_
;
149 #if defined(OS_CHROMEOS)
150 scoped_ptr
<chromeos::DeviceLocalAccountManagementPolicyProvider
>
151 device_local_account_management_policy_provider_
;
161 // |process_manager_| must be destroyed before the Profile's |io_data_|. While
162 // |process_manager_| still lives, we handle incoming resource requests from
163 // extension processes and those require access to the ResourceContext owned
165 scoped_ptr
<ProcessManager
> process_manager_
;
167 DISALLOW_COPY_AND_ASSIGN(ExtensionSystemImpl
);
170 } // namespace extensions
172 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_IMPL_H_