blob: ab7d2f6436fa1244209e023863c6292ccf164427 [file] [log] [blame]
Avi Drissman60039d42022-09-13 21:49:051// Copyright 2014 The Chromium Authors
[email protected]59b0e602014-01-30 00:41:242// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef EXTENSIONS_BROWSER_EXTENSION_SYSTEM_H_
6#define EXTENSIONS_BROWSER_EXTENSION_SYSTEM_H_
7
8#include <string>
9
danakjf6d89bf2020-01-07 01:21:2910#include "base/callback.h"
[email protected]59b0e602014-01-30 00:41:2411#include "base/memory/ref_counted.h"
avic9cec102015-12-23 00:39:2612#include "build/build_config.h"
[email protected]b33f0b112014-03-13 17:05:3013#include "components/keyed_service/core/keyed_service.h"
Minh X. Nguyen8803f4e2018-05-25 01:03:1014#include "extensions/browser/install/crx_install_error.h"
Scott Violetc8240b02018-03-08 22:03:5915#include "extensions/buildflags/buildflags.h"
[email protected]59b0e602014-01-30 00:41:2416#include "extensions/common/extension.h"
Anton Bikineev6d678472021-05-15 18:48:5117#include "third_party/abseil-cpp/absl/types/optional.h"
[email protected]59b0e602014-01-30 00:41:2418
brettw00899e62016-11-12 02:10:1719#if !BUILDFLAG(ENABLE_EXTENSIONS)
thestig44b9ce22014-10-17 03:19:2820#error "Extensions must be enabled"
21#endif
22
Christopher Lamebb90202019-04-04 03:42:3623namespace base {
24class OneShotEvent;
25}
26
[email protected]59b0e602014-01-30 00:41:2427namespace content {
28class BrowserContext;
29}
30
Louise Brett88346ae12021-09-09 04:47:3231namespace value_store {
32class ValueStoreFactory;
33}
34
[email protected]59b0e602014-01-30 00:41:2435namespace extensions {
36
treib926ee2d2015-08-06 10:55:4237class AppSorting;
[email protected]fd3df7782014-05-08 23:54:2738class ContentVerifier;
[email protected]59b0e602014-01-30 00:41:2439class Extension;
Devlin Cronineea1b7a2018-05-26 02:46:2140class ExtensionService;
[email protected]f698c162014-06-13 00:46:2641class ExtensionSet;
[email protected]59b0e602014-01-30 00:41:2442class InfoMap;
[email protected]59b0e602014-01-30 00:41:2443class ManagementPolicy;
[email protected]aab23102014-02-05 18:57:5544class QuotaService;
rdevlin.croninf5863da2015-09-10 19:21:4545class ServiceWorkerManager;
[email protected]59b0e602014-01-30 00:41:2446class StateStore;
Kelvin Jianga115a752021-02-11 03:04:0147class UserScriptManager;
Devlin Croninc9c4efe2020-01-07 21:04:0548enum class UnloadedExtensionReason;
[email protected]59b0e602014-01-30 00:41:2449
50// ExtensionSystem manages the lifetime of many of the services used by the
51// extensions and apps system, and it handles startup and shutdown as needed.
[email protected]b33f0b112014-03-13 17:05:3052// Eventually, we'd like to make more of these services into KeyedServices in
53// their own right.
54class ExtensionSystem : public KeyedService {
[email protected]59b0e602014-01-30 00:41:2455 public:
Minh X. Nguyen2c17b3982017-10-13 18:32:2956 // A callback to be executed when InstallUpdate finishes.
Minh X. Nguyen8803f4e2018-05-25 01:03:1057 using InstallUpdateCallback =
Anton Bikineev6d678472021-05-15 18:48:5158 base::OnceCallback<void(const absl::optional<CrxInstallError>& result)>;
Minh X. Nguyen2c17b3982017-10-13 18:32:2959
[email protected]59b0e602014-01-30 00:41:2460 ExtensionSystem();
dcheng9168b2f2014-10-21 12:38:2461 ~ExtensionSystem() override;
[email protected]59b0e602014-01-30 00:41:2462
63 // Returns the instance for the given browser context, or NULL if none.
[email protected]59b0e602014-01-30 00:41:2464 static ExtensionSystem* Get(content::BrowserContext* context);
65
66 // Initializes extensions machinery.
67 // Component extensions are always enabled, external and user extensions are
Randy Smith64399d62017-12-20 04:33:4068 // controlled (for both incognito and non-incognito profiles) by the
69 // |extensions_enabled| flag passed to non-incognito initialization.
70 // These calls should occur after the profile IO data is initialized,
71 // as extensions initialization depends on that.
[email protected]59b0e602014-01-30 00:41:2472 virtual void InitForRegularProfile(bool extensions_enabled) = 0;
73
Michael Giuffrida023e3532017-09-28 23:21:2174 // The ExtensionService is created at startup. ExtensionService is only
75 // defined in Chrome.
[email protected]59b0e602014-01-30 00:41:2476 virtual ExtensionService* extension_service() = 0;
77
[email protected]59b0e602014-01-30 00:41:2478 // The class controlling whether users are permitted to perform certain
79 // actions on extensions (install, uninstall, disable, etc.).
80 // The ManagementPolicy is created at startup.
81 virtual ManagementPolicy* management_policy() = 0;
82
rdevlin.croninf5863da2015-09-10 19:21:4583 // The ServiceWorkerManager is created at startup.
84 virtual ServiceWorkerManager* service_worker_manager() = 0;
85
Kelvin Jianga115a752021-02-11 03:04:0186 // The UserScriptManager is created at startup.
87 virtual UserScriptManager* user_script_manager() = 0;
[email protected]59b0e602014-01-30 00:41:2488
[email protected]59b0e602014-01-30 00:41:2489 // The StateStore is created at startup.
90 virtual StateStore* state_store() = 0;
91
92 // The rules store is created at startup.
93 virtual StateStore* rules_store() = 0;
94
Kelvin Jiang31277362021-09-24 00:41:3395 // The dynamic user scripts store is created at startup.
96 virtual StateStore* dynamic_user_scripts_store() = 0;
97
cmumford6ae8d462016-03-24 20:35:2798 // Returns the |ValueStore| factory created at startup.
Louise Brett88346ae12021-09-09 04:47:3299 virtual scoped_refptr<value_store::ValueStoreFactory> store_factory() = 0;
cmumford6ae8d462016-03-24 20:35:27100
[email protected]59b0e602014-01-30 00:41:24101 // Returns the IO-thread-accessible extension data.
102 virtual InfoMap* info_map() = 0;
103
[email protected]aab23102014-02-05 18:57:55104 // Returns the QuotaService that limits calls to certain extension functions.
105 // Lives on the UI thread. Created at startup.
106 virtual QuotaService* quota_service() = 0;
107
treib926ee2d2015-08-06 10:55:42108 // Returns the AppSorting which provides an ordering for all installed apps.
109 virtual AppSorting* app_sorting() = 0;
110
[email protected]59b0e602014-01-30 00:41:24111 // Called by the ExtensionService that lives in this system. Gives the
112 // info map a chance to react to the load event before the EXTENSION_LOADED
113 // notification has fired. The purpose for handling this event first is to
114 // avoid race conditions by making sure URLRequestContexts learn about new
rockot494f0072015-07-29 17:58:07115 // extensions before anything else needs them to know. This operation happens
116 // asynchronously. |callback| is run on the calling thread once completed.
[email protected]59b0e602014-01-30 00:41:24117 virtual void RegisterExtensionWithRequestContexts(
rockot494f0072015-07-29 17:58:07118 const Extension* extension,
danakjf6d89bf2020-01-07 01:21:29119 base::OnceClosure callback) {}
[email protected]59b0e602014-01-30 00:41:24120
121 // Called by the ExtensionService that lives in this system. Lets the
122 // info map clean up its RequestContexts once all the listeners to the
123 // EXTENSION_UNLOADED notification have finished running.
124 virtual void UnregisterExtensionWithRequestContexts(
Tal Keren9ba46e152022-01-25 18:13:59125 const std::string& extension_id) {}
[email protected]59b0e602014-01-30 00:41:24126
127 // Signaled when the extension system has completed its startup tasks.
Christopher Lamebb90202019-04-04 03:42:36128 virtual const base::OneShotEvent& ready() const = 0;
[email protected]fd3df7782014-05-08 23:54:27129
Ghazale Hosseinabadi1d810e92020-06-01 20:43:02130 // Whether the extension system is ready.
131 virtual bool is_ready() const = 0;
132
[email protected]fd3df7782014-05-08 23:54:27133 // Returns the content verifier, if any.
134 virtual ContentVerifier* content_verifier() = 0;
[email protected]f698c162014-06-13 00:46:26135
136 // Get a set of extensions that depend on the given extension.
137 // TODO(elijahtaylor): Move SharedModuleService out of chrome/browser
138 // so it can be retrieved from ExtensionSystem directly.
dchengf5d241082016-04-21 03:43:11139 virtual std::unique_ptr<ExtensionSet> GetDependentExtensions(
[email protected]f698c162014-06-13 00:46:26140 const Extension* extension) = 0;
asargent631a99a2015-10-15 21:51:48141
142 // Install an updated version of |extension_id| with the version given in
Minh X. Nguyen039eb992018-06-26 20:12:13143 // |unpacked_dir|. If |install_immediately| is true, the system will install
144 // the given extension immediately instead of waiting until idle. Ownership
145 // of |unpacked_dir| in the filesystem is transferred and implementors of
146 // this function are responsible for cleaning it up on errors, etc.
asargent631a99a2015-10-15 21:51:48147 virtual void InstallUpdate(const std::string& extension_id,
Minh X. Nguyen30975342017-12-04 22:02:41148 const std::string& public_key,
149 const base::FilePath& unpacked_dir,
Minh X. Nguyen039eb992018-06-26 20:12:13150 bool install_immediately,
Minh X. Nguyen30975342017-12-04 22:02:41151 InstallUpdateCallback install_update_callback) = 0;
Minh X. Nguyenb4fbf922018-01-29 18:28:10152
Bettina45e1a942020-04-10 22:29:47153 // Perform various actions depending on the Omaga attributes on the extension.
154 virtual void PerformActionBasedOnOmahaAttributes(
155 const std::string& extension_id,
156 const base::Value& attributes) = 0;
157
Minh X. Nguyenb4fbf922018-01-29 18:28:10158 // Attempts finishing installation of an update for an extension with the
159 // specified id, when installation of that extension was previously delayed.
160 // |install_immediately| - Install the extension should be installed if it is
161 // currently in use.
162 // Returns whether the extension installation was finished.
163 virtual bool FinishDelayedInstallationIfReady(const std::string& extension_id,
164 bool install_immediately) = 0;
[email protected]59b0e602014-01-30 00:41:24165};
166
167} // namespace extensions
168
169#endif // EXTENSIONS_BROWSER_EXTENSION_SYSTEM_H_