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 EXTENSIONS_BROWSER_EXTENSION_SYSTEM_H_
6 #define EXTENSIONS_BROWSER_EXTENSION_SYSTEM_H_
10 #include "base/callback_forward.h"
11 #include "base/memory/ref_counted.h"
12 #include "components/keyed_service/core/keyed_service.h"
13 #include "extensions/common/extension.h"
15 #if !defined(ENABLE_EXTENSIONS)
16 #error "Extensions must be enabled"
19 class ExtensionService
;
21 #if defined(OS_CHROMEOS)
23 class DeviceLocalAccountManagementPolicyProvider
;
25 #endif // defined(OS_CHROMEOS)
31 namespace extensions
{
34 class ContentVerifier
;
38 class ManagementPolicy
;
42 class ServiceWorkerManager
;
43 class SharedUserScriptMaster
;
46 // ExtensionSystem manages the lifetime of many of the services used by the
47 // extensions and apps system, and it handles startup and shutdown as needed.
48 // Eventually, we'd like to make more of these services into KeyedServices in
50 class ExtensionSystem
: public KeyedService
{
53 ~ExtensionSystem() override
;
55 // Returns the instance for the given browser context, or NULL if none.
56 static ExtensionSystem
* Get(content::BrowserContext
* context
);
58 // Initializes extensions machinery.
59 // Component extensions are always enabled, external and user extensions are
60 // controlled by |extensions_enabled|.
61 virtual void InitForRegularProfile(bool extensions_enabled
) = 0;
63 // The ExtensionService is created at startup.
64 virtual ExtensionService
* extension_service() = 0;
66 // Per-extension data that can change during the life of the process but
67 // does not persist across restarts. Lives on UI thread. Created at startup.
68 virtual RuntimeData
* runtime_data() = 0;
70 // The class controlling whether users are permitted to perform certain
71 // actions on extensions (install, uninstall, disable, etc.).
72 // The ManagementPolicy is created at startup.
73 virtual ManagementPolicy
* management_policy() = 0;
75 // The ServiceWorkerManager is created at startup.
76 virtual ServiceWorkerManager
* service_worker_manager() = 0;
78 // The SharedUserScriptMaster is created at startup.
79 virtual SharedUserScriptMaster
* shared_user_script_master() = 0;
81 // The StateStore is created at startup.
82 virtual StateStore
* state_store() = 0;
84 // The rules store is created at startup.
85 virtual StateStore
* rules_store() = 0;
87 // Returns the IO-thread-accessible extension data.
88 virtual InfoMap
* info_map() = 0;
90 // Returns the QuotaService that limits calls to certain extension functions.
91 // Lives on the UI thread. Created at startup.
92 virtual QuotaService
* quota_service() = 0;
94 // Returns the AppSorting which provides an ordering for all installed apps.
95 virtual AppSorting
* app_sorting() = 0;
97 // Called by the ExtensionService that lives in this system. Gives the
98 // info map a chance to react to the load event before the EXTENSION_LOADED
99 // notification has fired. The purpose for handling this event first is to
100 // avoid race conditions by making sure URLRequestContexts learn about new
101 // extensions before anything else needs them to know. This operation happens
102 // asynchronously. |callback| is run on the calling thread once completed.
103 virtual void RegisterExtensionWithRequestContexts(
104 const Extension
* extension
,
105 const base::Closure
& callback
) {}
107 // Called by the ExtensionService that lives in this system. Lets the
108 // info map clean up its RequestContexts once all the listeners to the
109 // EXTENSION_UNLOADED notification have finished running.
110 virtual void UnregisterExtensionWithRequestContexts(
111 const std::string
& extension_id
,
112 const UnloadedExtensionInfo::Reason reason
) {}
114 // Signaled when the extension system has completed its startup tasks.
115 virtual const OneShotEvent
& ready() const = 0;
117 // Returns the content verifier, if any.
118 virtual ContentVerifier
* content_verifier() = 0;
120 // Get a set of extensions that depend on the given extension.
121 // TODO(elijahtaylor): Move SharedModuleService out of chrome/browser
122 // so it can be retrieved from ExtensionSystem directly.
123 virtual scoped_ptr
<ExtensionSet
> GetDependentExtensions(
124 const Extension
* extension
) = 0;
127 } // namespace extensions
129 #endif // EXTENSIONS_BROWSER_EXTENSION_SYSTEM_H_