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