[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 1 | // Copyright (c) 2012 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 | #include "chrome/browser/extensions/test_extension_system.h" |
| 6 | |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
[email protected] | dc9a74f7 | 2012-08-17 18:07:21 | [diff] [blame] | 9 | #include "base/command_line.h" |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 10 | #include "base/memory/ptr_util.h" |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 11 | #include "chrome/browser/extensions/blacklist.h" |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 12 | #include "chrome/browser/extensions/chrome_app_sorting.h" |
Jay Civelli | ea8f3df | 2018-01-24 05:17:32 | [diff] [blame] | 13 | #include "chrome/browser/extensions/crx_installer.h" |
binjin | 1569c9b | 2014-09-05 13:33:18 | [diff] [blame] | 14 | #include "chrome/browser/extensions/extension_management.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 15 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | f698c16 | 2014-06-13 00:46:26 | [diff] [blame] | 16 | #include "chrome/browser/extensions/shared_module_service.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 17 | #include "chrome/browser/profiles/profile.h" |
| 18 | #include "chrome/common/chrome_switches.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 19 | #include "components/prefs/pref_service.h" |
Ken Rockot | 61df041 | 2019-07-26 17:12:19 | [diff] [blame] | 20 | #include "components/services/unzip/content/unzip_service.h" |
| 21 | #include "components/services/unzip/in_process_unzipper.h" |
[email protected] | 9f8394d | 2012-07-30 22:08:00 | [diff] [blame] | 22 | #include "content/public/browser/browser_thread.h" |
Jay Civelli | ea8f3df | 2018-01-24 05:17:32 | [diff] [blame] | 23 | #include "content/public/common/service_manager_connection.h" |
[email protected] | 489db084 | 2014-01-22 18:20:03 | [diff] [blame] | 24 | #include "extensions/browser/extension_prefs.h" |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 25 | #include "extensions/browser/extension_registry.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 26 | #include "extensions/browser/extension_system.h" |
[email protected] | bf5ee7cc | 2013-11-23 20:48:44 | [diff] [blame] | 27 | #include "extensions/browser/extensions_browser_client.h" |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 28 | #include "extensions/browser/info_map.h" |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 29 | #include "extensions/browser/management_policy.h" |
[email protected] | aab2310 | 2014-02-05 18:57:55 | [diff] [blame] | 30 | #include "extensions/browser/quota_service.h" |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 31 | #include "extensions/browser/runtime_data.h" |
[email protected] | daf3ffda | 2014-06-25 06:44:57 | [diff] [blame] | 32 | #include "extensions/browser/state_store.h" |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 33 | #include "extensions/browser/value_store/test_value_store_factory.h" |
[email protected] | 47b870f | 2014-03-01 00:34:00 | [diff] [blame] | 34 | #include "extensions/browser/value_store/testing_value_store.h" |
Jay Civelli | f330ef0 | 2018-03-05 19:59:44 | [diff] [blame] | 35 | #include "services/data_decoder/data_decoder_service.h" |
Ken Rockot | a373add | 2018-10-30 23:22:42 | [diff] [blame] | 36 | #include "services/data_decoder/public/mojom/constants.mojom.h" |
Jay Civelli | f330ef0 | 2018-03-05 19:59:44 | [diff] [blame] | 37 | #include "services/service_manager/public/cpp/test/test_connector_factory.h" |
alemate | 5f96a4f | 2017-06-02 21:09:40 | [diff] [blame] | 38 | #if defined(OS_CHROMEOS) |
| 39 | #include "components/user_manager/user_manager.h" |
| 40 | #endif |
[email protected] | 9f8394d | 2012-07-30 22:08:00 | [diff] [blame] | 41 | |
| 42 | using content::BrowserThread; |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 43 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 44 | namespace extensions { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 45 | |
| 46 | TestExtensionSystem::TestExtensionSystem(Profile* profile) |
[email protected] | 466f5e2 | 2012-06-30 02:52:07 | [diff] [blame] | 47 | : profile_(profile), |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 48 | store_factory_(new TestValueStoreFactory()), |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 49 | info_map_(new InfoMap()), |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 50 | quota_service_(new QuotaService()), |
alemate | 5f96a4f | 2017-06-02 21:09:40 | [diff] [blame] | 51 | app_sorting_(new ChromeAppSorting(profile_)) { |
| 52 | #if defined(OS_CHROMEOS) |
| 53 | if (!user_manager::UserManager::IsInitialized()) |
| 54 | test_user_manager_.reset(new chromeos::ScopedTestUserManager); |
| 55 | #endif |
| 56 | } |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 57 | |
Ken Rockot | 61df041 | 2019-07-26 17:12:19 | [diff] [blame] | 58 | TestExtensionSystem::~TestExtensionSystem() = default; |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 59 | |
| 60 | void TestExtensionSystem::Shutdown() { |
binjin | 1569c9b | 2014-09-05 13:33:18 | [diff] [blame] | 61 | if (extension_service_) |
| 62 | extension_service_->Shutdown(); |
[email protected] | f724021 | 2013-10-27 03:39:12 | [diff] [blame] | 63 | } |
| 64 | |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 65 | ExtensionService* TestExtensionSystem::CreateExtensionService( |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 66 | const base::CommandLine* command_line, |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 67 | const base::FilePath& install_directory, |
rdevlin.cronin | 7217be5 | 2017-03-24 20:47:05 | [diff] [blame] | 68 | bool autoupdate_enabled, |
| 69 | bool extensions_enabled) { |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 70 | state_store_.reset(new StateStore( |
| 71 | profile_, store_factory_, ValueStoreFrontend::BackendType::RULES, false)); |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 72 | management_policy_.reset(new ManagementPolicy()); |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 73 | management_policy_->RegisterProviders( |
binjin | 1569c9b | 2014-09-05 13:33:18 | [diff] [blame] | 74 | ExtensionManagementFactory::GetForBrowserContext(profile_) |
binjin | e6b58b5 | 2014-10-31 01:55:57 | [diff] [blame] | 75 | ->GetProviders()); |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 76 | runtime_data_.reset(new RuntimeData(ExtensionRegistry::Get(profile_))); |
rdevlin.cronin | 7217be5 | 2017-03-24 20:47:05 | [diff] [blame] | 77 | extension_service_.reset(new ExtensionService( |
| 78 | profile_, command_line, install_directory, ExtensionPrefs::Get(profile_), |
| 79 | Blacklist::Get(profile_), autoupdate_enabled, extensions_enabled, |
| 80 | &ready_)); |
Jay Civelli | f330ef0 | 2018-03-05 19:59:44 | [diff] [blame] | 81 | |
| 82 | if (!connector_factory_) { |
Jay Civelli | f330ef0 | 2018-03-05 19:59:44 | [diff] [blame] | 83 | connector_factory_ = |
Ken Rockot | a373add | 2018-10-30 23:22:42 | [diff] [blame] | 84 | std::make_unique<service_manager::TestConnectorFactory>(); |
Ken Rockot | 1030629 | 2018-11-02 15:45:29 | [diff] [blame] | 85 | connector_factory_->set_ignore_quit_requests(true); |
Ken Rockot | a373add | 2018-10-30 23:22:42 | [diff] [blame] | 86 | data_decoder_ = std::make_unique<data_decoder::DataDecoderService>( |
| 87 | connector_factory_->RegisterInstance( |
| 88 | data_decoder::mojom::kServiceName)); |
Ken Rockot | 61df041 | 2019-07-26 17:12:19 | [diff] [blame] | 89 | unzip::SetUnzipperLaunchOverrideForTesting( |
| 90 | base::BindRepeating(&unzip::LaunchInProcessUnzipper)); |
Jay Civelli | f330ef0 | 2018-03-05 19:59:44 | [diff] [blame] | 91 | connector_ = connector_factory_->CreateConnector(); |
| 92 | CrxInstaller::set_connector_for_test(connector_.get()); |
Jay Civelli | ea8f3df | 2018-01-24 05:17:32 | [diff] [blame] | 93 | } |
Jay Civelli | f330ef0 | 2018-03-05 19:59:44 | [diff] [blame] | 94 | |
[email protected] | f23736e | 2012-07-11 16:52:59 | [diff] [blame] | 95 | extension_service_->ClearProvidersForTesting(); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 96 | return extension_service_.get(); |
| 97 | } |
| 98 | |
| 99 | ExtensionService* TestExtensionSystem::extension_service() { |
| 100 | return extension_service_.get(); |
| 101 | } |
| 102 | |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 103 | RuntimeData* TestExtensionSystem::runtime_data() { |
| 104 | return runtime_data_.get(); |
| 105 | } |
| 106 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 107 | ManagementPolicy* TestExtensionSystem::management_policy() { |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 108 | return management_policy_.get(); |
| 109 | } |
| 110 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 111 | void TestExtensionSystem::SetExtensionService(ExtensionService* service) { |
| 112 | extension_service_.reset(service); |
| 113 | } |
| 114 | |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 115 | ServiceWorkerManager* TestExtensionSystem::service_worker_manager() { |
| 116 | return nullptr; |
| 117 | } |
| 118 | |
[email protected] | 15ad2ee | 2014-08-15 19:15:26 | [diff] [blame] | 119 | SharedUserScriptMaster* TestExtensionSystem::shared_user_script_master() { |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 120 | return NULL; |
| 121 | } |
| 122 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 123 | StateStore* TestExtensionSystem::state_store() { |
[email protected] | bec6455 | 2012-06-13 20:25:49 | [diff] [blame] | 124 | return state_store_.get(); |
[email protected] | 90e800c | 2012-06-12 23:11:00 | [diff] [blame] | 125 | } |
| 126 | |
[email protected] | a690e29 | 2012-12-19 19:22:49 | [diff] [blame] | 127 | StateStore* TestExtensionSystem::rules_store() { |
| 128 | return state_store_.get(); |
| 129 | } |
| 130 | |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 131 | scoped_refptr<ValueStoreFactory> TestExtensionSystem::store_factory() { |
| 132 | return store_factory_; |
| 133 | } |
| 134 | |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 135 | InfoMap* TestExtensionSystem::info_map() { return info_map_.get(); } |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 136 | |
[email protected] | aab2310 | 2014-02-05 18:57:55 | [diff] [blame] | 137 | QuotaService* TestExtensionSystem::quota_service() { |
| 138 | return quota_service_.get(); |
| 139 | } |
| 140 | |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 141 | AppSorting* TestExtensionSystem::app_sorting() { |
| 142 | return app_sorting_.get(); |
| 143 | } |
| 144 | |
Christopher Lam | ebb9020 | 2019-04-04 03:42:36 | [diff] [blame] | 145 | const base::OneShotEvent& TestExtensionSystem::ready() const { |
[email protected] | aab2310 | 2014-02-05 18:57:55 | [diff] [blame] | 146 | return ready_; |
| 147 | } |
| 148 | |
[email protected] | fd3df778 | 2014-05-08 23:54:27 | [diff] [blame] | 149 | ContentVerifier* TestExtensionSystem::content_verifier() { |
| 150 | return NULL; |
| 151 | } |
| 152 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 153 | std::unique_ptr<ExtensionSet> TestExtensionSystem::GetDependentExtensions( |
[email protected] | f698c16 | 2014-06-13 00:46:26 | [diff] [blame] | 154 | const Extension* extension) { |
| 155 | return extension_service()->shared_module_service()->GetDependentExtensions( |
| 156 | extension); |
| 157 | } |
| 158 | |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 159 | void TestExtensionSystem::InstallUpdate( |
| 160 | const std::string& extension_id, |
| 161 | const std::string& public_key, |
| 162 | const base::FilePath& temp_dir, |
Minh X. Nguyen | 039eb99 | 2018-06-26 20:12:13 | [diff] [blame] | 163 | bool install_immediately, |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 164 | InstallUpdateCallback install_update_callback) { |
asargent | 631a99a | 2015-10-15 21:51:48 | [diff] [blame] | 165 | NOTREACHED(); |
| 166 | } |
| 167 | |
Minh X. Nguyen | b4fbf92 | 2018-01-29 18:28:10 | [diff] [blame] | 168 | bool TestExtensionSystem::FinishDelayedInstallationIfReady( |
| 169 | const std::string& extension_id, |
| 170 | bool install_immediately) { |
| 171 | NOTREACHED(); |
| 172 | return false; |
| 173 | } |
| 174 | |
cmumford | f755705a | 2016-03-14 22:46:49 | [diff] [blame] | 175 | TestingValueStore* TestExtensionSystem::value_store() { |
cmumford | 6ae8d46 | 2016-03-24 20:35:27 | [diff] [blame] | 176 | // These tests use TestingValueStore in a way that ensures it only ever mints |
| 177 | // instances of TestingValueStore. |
| 178 | return static_cast<TestingValueStore*>(store_factory_->LastCreatedStore()); |
cmumford | f755705a | 2016-03-14 22:46:49 | [diff] [blame] | 179 | } |
| 180 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 181 | // static |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 182 | std::unique_ptr<KeyedService> TestExtensionSystem::Build( |
isherman | 30fa851a | 2015-06-09 23:32:10 | [diff] [blame] | 183 | content::BrowserContext* profile) { |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 184 | return base::WrapUnique( |
isherman | 30fa851a | 2015-06-09 23:32:10 | [diff] [blame] | 185 | new TestExtensionSystem(static_cast<Profile*>(profile))); |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 186 | } |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 187 | |
treib | 926ee2d | 2015-08-06 10:55:42 | [diff] [blame] | 188 | void TestExtensionSystem::RecreateAppSorting() { |
| 189 | app_sorting_.reset(new ChromeAppSorting(profile_)); |
| 190 | } |
| 191 | |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 192 | } // namespace extensions |