[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_IMPL_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_IMPL_H_ |
| 7 | |
asargent | 8380bd39 | 2016-03-21 23:47:33 | [diff] [blame] | 8 | #include <string> |
| 9 | |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 10 | #include "base/macros.h" |
Christopher Lam | ebb9020 | 2019-04-04 03:42:36 | [diff] [blame] | 11 | #include "base/one_shot_event.h" |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 12 | #include "build/build_config.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 13 | #include "extensions/browser/extension_system.h" |
Devlin Cronin | c9c4efe | 2020-01-07 21:04:05 | [diff] [blame] | 14 | #include "extensions/browser/unloaded_extension_reason.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 15 | |
| 16 | class Profile; |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 17 | |
antrim | 5876956 | 2016-11-14 14:48:41 | [diff] [blame] | 18 | #if defined(OS_CHROMEOS) |
| 19 | namespace chromeos { |
| 20 | class DeviceLocalAccountManagementPolicyProvider; |
| 21 | class SigninScreenPolicyProvider; |
| 22 | } |
| 23 | #endif // defined(OS_CHROMEOS) |
| 24 | |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 25 | namespace extensions { |
| 26 | |
| 27 | class ExtensionSystemSharedFactory; |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 28 | class NavigationObserver; |
[email protected] | 479e392 | 2014-07-30 07:12:57 | [diff] [blame] | 29 | class StateStoreNotificationObserver; |
asargent | 8380bd39 | 2016-03-21 23:47:33 | [diff] [blame] | 30 | class UninstallPingSender; |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 31 | class InstallGate; |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 32 | class ValueStoreFactory; |
| 33 | class ValueStoreFactoryImpl; |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 34 | |
| 35 | // The ExtensionSystem for ProfileImpl and OffTheRecordProfileImpl. |
| 36 | // Implementation details: non-shared services are owned by |
[email protected] | b33f0b11 | 2014-03-13 17:05:30 | [diff] [blame] | 37 | // ExtensionSystemImpl, a KeyedService with separate incognito |
| 38 | // instances. A private Shared class (also a KeyedService, |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 39 | // but with a shared instance for incognito) keeps the common services. |
| 40 | class ExtensionSystemImpl : public ExtensionSystem { |
| 41 | public: |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 42 | using InstallUpdateCallback = ExtensionSystem::InstallUpdateCallback; |
| 43 | |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 44 | explicit ExtensionSystemImpl(Profile* profile); |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 45 | ~ExtensionSystemImpl() override; |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 46 | |
[email protected] | b33f0b11 | 2014-03-13 17:05:30 | [diff] [blame] | 47 | // KeyedService implementation. |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 48 | void Shutdown() override; |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 49 | |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 50 | void InitForRegularProfile(bool extensions_enabled) override; |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 51 | |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 52 | ExtensionService* extension_service() override; // shared |
| 53 | RuntimeData* runtime_data() override; // shared |
| 54 | ManagementPolicy* management_policy() override; // shared |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 55 | ServiceWorkerManager* service_worker_manager() override; // shared |
hanxi | 6d9b43a | 2014-12-12 21:53:46 | [diff] [blame] | 56 | SharedUserScriptMaster* shared_user_script_master() override; // shared |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 57 | StateStore* state_store() override; // shared |
| 58 | StateStore* rules_store() override; // shared |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 59 | scoped_refptr<ValueStoreFactory> store_factory() override; // shared |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 60 | InfoMap* info_map() override; // shared |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 61 | QuotaService* quota_service() override; // shared |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 62 | AppSorting* app_sorting() override; // shared |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 63 | |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 64 | void RegisterExtensionWithRequestContexts( |
rockot | 494f007 | 2015-07-29 17:58:07 | [diff] [blame] | 65 | const Extension* extension, |
danakj | f6d89bf | 2020-01-07 01:21:29 | [diff] [blame] | 66 | base::OnceClosure callback) override; |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 67 | |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 68 | void UnregisterExtensionWithRequestContexts( |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 69 | const std::string& extension_id, |
limasdf | 0deef204 | 2017-05-03 19:17:17 | [diff] [blame] | 70 | const UnloadedExtensionReason reason) override; |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 71 | |
Christopher Lam | ebb9020 | 2019-04-04 03:42:36 | [diff] [blame] | 72 | const base::OneShotEvent& ready() const override; |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 73 | ContentVerifier* content_verifier() override; // shared |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 74 | std::unique_ptr<ExtensionSet> GetDependentExtensions( |
mostynb | a15bee1 | 2014-10-04 00:40:32 | [diff] [blame] | 75 | const Extension* extension) override; |
asargent | 631a99a | 2015-10-15 21:51:48 | [diff] [blame] | 76 | void InstallUpdate(const std::string& extension_id, |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 77 | const std::string& public_key, |
| 78 | const base::FilePath& unpacked_dir, |
Minh X. Nguyen | 039eb99 | 2018-06-26 20:12:13 | [diff] [blame] | 79 | bool install_immediately, |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 80 | InstallUpdateCallback install_update_callback) override; |
Minh X. Nguyen | b4fbf92 | 2018-01-29 18:28:10 | [diff] [blame] | 81 | bool FinishDelayedInstallationIfReady(const std::string& extension_id, |
| 82 | bool install_immediately) override; |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 83 | |
| 84 | private: |
| 85 | friend class ExtensionSystemSharedFactory; |
| 86 | |
| 87 | // Owns the Extension-related systems that have a single instance |
| 88 | // shared between normal and incognito profiles. |
Devlin Cronin | c5c5a0c | 2018-08-15 04:04:10 | [diff] [blame] | 89 | class Shared : public KeyedService { |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 90 | public: |
| 91 | explicit Shared(Profile* profile); |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 92 | ~Shared() override; |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 93 | |
| 94 | // Initialization takes place in phases. |
| 95 | virtual void InitPrefs(); |
| 96 | // This must not be called until all the providers have been created. |
| 97 | void RegisterManagementPolicyProviders(); |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 98 | void InitInstallGates(); |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 99 | void Init(bool extensions_enabled); |
| 100 | |
[email protected] | b33f0b11 | 2014-03-13 17:05:30 | [diff] [blame] | 101 | // KeyedService implementation. |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 102 | void Shutdown() override; |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 103 | |
| 104 | StateStore* state_store(); |
| 105 | StateStore* rules_store(); |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 106 | scoped_refptr<ValueStoreFactory> store_factory() const; |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 107 | ExtensionService* extension_service(); |
| 108 | RuntimeData* runtime_data(); |
| 109 | ManagementPolicy* management_policy(); |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 110 | ServiceWorkerManager* service_worker_manager(); |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 111 | SharedUserScriptMaster* shared_user_script_master(); |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 112 | InfoMap* info_map(); |
[email protected] | aab2310 | 2014-02-05 18:57:55 | [diff] [blame] | 113 | QuotaService* quota_service(); |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 114 | AppSorting* app_sorting(); |
Christopher Lam | ebb9020 | 2019-04-04 03:42:36 | [diff] [blame] | 115 | const base::OneShotEvent& ready() const { return ready_; } |
[email protected] | fd3df778 | 2014-05-08 23:54:27 | [diff] [blame] | 116 | ContentVerifier* content_verifier(); |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 117 | |
| 118 | private: |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 119 | Profile* profile_; |
| 120 | |
| 121 | // The services that are shared between normal and incognito profiles. |
| 122 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 123 | std::unique_ptr<StateStore> state_store_; |
| 124 | std::unique_ptr<StateStoreNotificationObserver> |
[email protected] | 479e392 | 2014-07-30 07:12:57 | [diff] [blame] | 125 | state_store_notification_observer_; |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 126 | std::unique_ptr<StateStore> rules_store_; |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 127 | scoped_refptr<ValueStoreFactoryImpl> store_factory_; |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 128 | std::unique_ptr<NavigationObserver> navigation_observer_; |
| 129 | std::unique_ptr<ServiceWorkerManager> service_worker_manager_; |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 130 | // Shared memory region manager for scripts statically declared in extension |
| 131 | // manifests. This region is shared between all extensions. |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 132 | std::unique_ptr<SharedUserScriptMaster> shared_user_script_master_; |
| 133 | std::unique_ptr<RuntimeData> runtime_data_; |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 134 | // ExtensionService depends on StateStore, Blacklist and RuntimeData. |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 135 | std::unique_ptr<ExtensionService> extension_service_; |
| 136 | std::unique_ptr<ManagementPolicy> management_policy_; |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 137 | // extension_info_map_ needs to outlive process_manager_. |
| 138 | scoped_refptr<InfoMap> extension_info_map_; |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 139 | std::unique_ptr<QuotaService> quota_service_; |
| 140 | std::unique_ptr<AppSorting> app_sorting_; |
xiyuan | f6a4c6a6 | 2016-04-19 18:14:54 | [diff] [blame] | 141 | std::unique_ptr<InstallGate> update_install_gate_; |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 142 | |
[email protected] | fd3df778 | 2014-05-08 23:54:27 | [diff] [blame] | 143 | // For verifying the contents of extensions read from disk. |
| 144 | scoped_refptr<ContentVerifier> content_verifier_; |
| 145 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 146 | std::unique_ptr<UninstallPingSender> uninstall_ping_sender_; |
asargent | 8380bd39 | 2016-03-21 23:47:33 | [diff] [blame] | 147 | |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 148 | #if defined(OS_CHROMEOS) |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 149 | std::unique_ptr<chromeos::DeviceLocalAccountManagementPolicyProvider> |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 150 | device_local_account_management_policy_provider_; |
antrim | 5876956 | 2016-11-14 14:48:41 | [diff] [blame] | 151 | std::unique_ptr<chromeos::SigninScreenPolicyProvider> |
| 152 | signin_screen_policy_provider_; |
xiyuan | a0a6aaaa | 2016-04-19 23:34:16 | [diff] [blame] | 153 | std::unique_ptr<InstallGate> kiosk_app_update_install_gate_; |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 154 | #endif |
| 155 | |
Christopher Lam | ebb9020 | 2019-04-04 03:42:36 | [diff] [blame] | 156 | base::OneShotEvent ready_; |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 157 | }; |
| 158 | |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 159 | Profile* profile_; |
| 160 | |
| 161 | Shared* shared_; |
| 162 | |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 163 | DISALLOW_COPY_AND_ASSIGN(ExtensionSystemImpl); |
| 164 | }; |
| 165 | |
| 166 | } // namespace extensions |
| 167 | |
| 168 | #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SYSTEM_IMPL_H_ |