blob: f67c96567091c276ed66d1fb1aee103b69adca10 [file] [log] [blame]
[email protected]31d8f5f22012-04-02 15:22:081// 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
dcheng1fc00f12015-12-26 22:18:037#include <utility>
8
[email protected]dc9a74f72012-08-17 18:07:219#include "base/command_line.h"
dchengc963c7142016-04-08 03:55:2210#include "base/memory/ptr_util.h"
[email protected]fdd679b2012-11-15 20:49:3911#include "chrome/browser/extensions/blacklist.h"
treib926ee2d2015-08-06 10:55:4212#include "chrome/browser/extensions/chrome_app_sorting.h"
Jay Civelliea8f3df2018-01-24 05:17:3213#include "chrome/browser/extensions/crx_installer.h"
binjin1569c9b2014-09-05 13:33:1814#include "chrome/browser/extensions/extension_management.h"
[email protected]31d8f5f22012-04-02 15:22:0815#include "chrome/browser/extensions/extension_service.h"
[email protected]f698c162014-06-13 00:46:2616#include "chrome/browser/extensions/shared_module_service.h"
[email protected]31d8f5f22012-04-02 15:22:0817#include "chrome/browser/profiles/profile.h"
18#include "chrome/common/chrome_switches.h"
brettwb1fc1b82016-02-02 00:19:0819#include "components/prefs/pref_service.h"
Ken Rockot61df0412019-07-26 17:12:1920#include "components/services/unzip/content/unzip_service.h"
21#include "components/services/unzip/in_process_unzipper.h"
[email protected]9f8394d2012-07-30 22:08:0022#include "content/public/browser/browser_thread.h"
Jay Civelliea8f3df2018-01-24 05:17:3223#include "content/public/common/service_manager_connection.h"
[email protected]489db0842014-01-22 18:20:0324#include "extensions/browser/extension_prefs.h"
[email protected]45f5b7d2014-01-22 23:47:1325#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2426#include "extensions/browser/extension_system.h"
[email protected]bf5ee7cc2013-11-23 20:48:4427#include "extensions/browser/extensions_browser_client.h"
[email protected]38427a12013-11-09 17:34:2028#include "extensions/browser/info_map.h"
[email protected]301116c62013-11-26 10:37:4529#include "extensions/browser/management_policy.h"
[email protected]aab23102014-02-05 18:57:5530#include "extensions/browser/quota_service.h"
[email protected]45f5b7d2014-01-22 23:47:1331#include "extensions/browser/runtime_data.h"
[email protected]daf3ffda2014-06-25 06:44:5732#include "extensions/browser/state_store.h"
cmumford6ae8d462016-03-24 20:35:2733#include "extensions/browser/value_store/test_value_store_factory.h"
[email protected]47b870f2014-03-01 00:34:0034#include "extensions/browser/value_store/testing_value_store.h"
Jay Civellif330ef02018-03-05 19:59:4435#include "services/data_decoder/data_decoder_service.h"
Ken Rockota373add2018-10-30 23:22:4236#include "services/data_decoder/public/mojom/constants.mojom.h"
Jay Civellif330ef02018-03-05 19:59:4437#include "services/service_manager/public/cpp/test/test_connector_factory.h"
alemate5f96a4f2017-06-02 21:09:4038#if defined(OS_CHROMEOS)
39#include "components/user_manager/user_manager.h"
40#endif
[email protected]9f8394d2012-07-30 22:08:0041
42using content::BrowserThread;
[email protected]31d8f5f22012-04-02 15:22:0843
[email protected]bd306722012-07-11 20:43:5944namespace extensions {
[email protected]31d8f5f22012-04-02 15:22:0845
46TestExtensionSystem::TestExtensionSystem(Profile* profile)
[email protected]466f5e22012-06-30 02:52:0747 : profile_(profile),
cmumford6ae8d462016-03-24 20:35:2748 store_factory_(new TestValueStoreFactory()),
[email protected]38427a12013-11-09 17:34:2049 info_map_(new InfoMap()),
treib926ee2d2015-08-06 10:55:4250 quota_service_(new QuotaService()),
alemate5f96a4f2017-06-02 21:09:4051 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]31d8f5f22012-04-02 15:22:0857
Ken Rockot61df0412019-07-26 17:12:1958TestExtensionSystem::~TestExtensionSystem() = default;
[email protected]31d8f5f22012-04-02 15:22:0859
60void TestExtensionSystem::Shutdown() {
binjin1569c9b2014-09-05 13:33:1861 if (extension_service_)
62 extension_service_->Shutdown();
[email protected]f7240212013-10-27 03:39:1263}
64
[email protected]b3aa7182013-04-25 04:45:2365ExtensionService* TestExtensionSystem::CreateExtensionService(
avi3ef9ec9e2014-12-22 22:50:1766 const base::CommandLine* command_line,
[email protected]b3aa7182013-04-25 04:45:2367 const base::FilePath& install_directory,
rdevlin.cronin7217be52017-03-24 20:47:0568 bool autoupdate_enabled,
69 bool extensions_enabled) {
cmumford6ae8d462016-03-24 20:35:2770 state_store_.reset(new StateStore(
71 profile_, store_factory_, ValueStoreFrontend::BackendType::RULES, false));
[email protected]fdd679b2012-11-15 20:49:3972 management_policy_.reset(new ManagementPolicy());
binjine6b58b52014-10-31 01:55:5773 management_policy_->RegisterProviders(
binjin1569c9b2014-09-05 13:33:1874 ExtensionManagementFactory::GetForBrowserContext(profile_)
binjine6b58b52014-10-31 01:55:5775 ->GetProviders());
[email protected]45f5b7d2014-01-22 23:47:1376 runtime_data_.reset(new RuntimeData(ExtensionRegistry::Get(profile_)));
rdevlin.cronin7217be52017-03-24 20:47:0577 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 Civellif330ef02018-03-05 19:59:4481
82 if (!connector_factory_) {
Jay Civellif330ef02018-03-05 19:59:4483 connector_factory_ =
Ken Rockota373add2018-10-30 23:22:4284 std::make_unique<service_manager::TestConnectorFactory>();
Ken Rockot10306292018-11-02 15:45:2985 connector_factory_->set_ignore_quit_requests(true);
Ken Rockota373add2018-10-30 23:22:4286 data_decoder_ = std::make_unique<data_decoder::DataDecoderService>(
87 connector_factory_->RegisterInstance(
88 data_decoder::mojom::kServiceName));
Ken Rockot61df0412019-07-26 17:12:1989 unzip::SetUnzipperLaunchOverrideForTesting(
90 base::BindRepeating(&unzip::LaunchInProcessUnzipper));
Jay Civellif330ef02018-03-05 19:59:4491 connector_ = connector_factory_->CreateConnector();
92 CrxInstaller::set_connector_for_test(connector_.get());
Jay Civelliea8f3df2018-01-24 05:17:3293 }
Jay Civellif330ef02018-03-05 19:59:4494
[email protected]f23736e2012-07-11 16:52:5995 extension_service_->ClearProvidersForTesting();
[email protected]31d8f5f22012-04-02 15:22:0896 return extension_service_.get();
97}
98
99ExtensionService* TestExtensionSystem::extension_service() {
100 return extension_service_.get();
101}
102
[email protected]45f5b7d2014-01-22 23:47:13103RuntimeData* TestExtensionSystem::runtime_data() {
104 return runtime_data_.get();
105}
106
[email protected]bd306722012-07-11 20:43:59107ManagementPolicy* TestExtensionSystem::management_policy() {
[email protected]65187152012-06-02 13:14:14108 return management_policy_.get();
109}
110
[email protected]31d8f5f22012-04-02 15:22:08111void TestExtensionSystem::SetExtensionService(ExtensionService* service) {
112 extension_service_.reset(service);
113}
114
rdevlin.croninf5863da2015-09-10 19:21:45115ServiceWorkerManager* TestExtensionSystem::service_worker_manager() {
116 return nullptr;
117}
118
[email protected]15ad2ee2014-08-15 19:15:26119SharedUserScriptMaster* TestExtensionSystem::shared_user_script_master() {
[email protected]31d8f5f22012-04-02 15:22:08120 return NULL;
121}
122
[email protected]bd306722012-07-11 20:43:59123StateStore* TestExtensionSystem::state_store() {
[email protected]bec64552012-06-13 20:25:49124 return state_store_.get();
[email protected]90e800c2012-06-12 23:11:00125}
126
[email protected]a690e292012-12-19 19:22:49127StateStore* TestExtensionSystem::rules_store() {
128 return state_store_.get();
129}
130
cmumford6ae8d462016-03-24 20:35:27131scoped_refptr<ValueStoreFactory> TestExtensionSystem::store_factory() {
132 return store_factory_;
133}
134
[email protected]38427a12013-11-09 17:34:20135InfoMap* TestExtensionSystem::info_map() { return info_map_.get(); }
[email protected]31d8f5f22012-04-02 15:22:08136
[email protected]aab23102014-02-05 18:57:55137QuotaService* TestExtensionSystem::quota_service() {
138 return quota_service_.get();
139}
140
treib926ee2d2015-08-06 10:55:42141AppSorting* TestExtensionSystem::app_sorting() {
142 return app_sorting_.get();
143}
144
Christopher Lamebb90202019-04-04 03:42:36145const base::OneShotEvent& TestExtensionSystem::ready() const {
[email protected]aab23102014-02-05 18:57:55146 return ready_;
147}
148
[email protected]fd3df7782014-05-08 23:54:27149ContentVerifier* TestExtensionSystem::content_verifier() {
150 return NULL;
151}
152
dchengc963c7142016-04-08 03:55:22153std::unique_ptr<ExtensionSet> TestExtensionSystem::GetDependentExtensions(
[email protected]f698c162014-06-13 00:46:26154 const Extension* extension) {
155 return extension_service()->shared_module_service()->GetDependentExtensions(
156 extension);
157}
158
Minh X. Nguyen30975342017-12-04 22:02:41159void TestExtensionSystem::InstallUpdate(
160 const std::string& extension_id,
161 const std::string& public_key,
162 const base::FilePath& temp_dir,
Minh X. Nguyen039eb992018-06-26 20:12:13163 bool install_immediately,
Minh X. Nguyen30975342017-12-04 22:02:41164 InstallUpdateCallback install_update_callback) {
asargent631a99a2015-10-15 21:51:48165 NOTREACHED();
166}
167
Minh X. Nguyenb4fbf922018-01-29 18:28:10168bool TestExtensionSystem::FinishDelayedInstallationIfReady(
169 const std::string& extension_id,
170 bool install_immediately) {
171 NOTREACHED();
172 return false;
173}
174
cmumfordf755705a2016-03-14 22:46:49175TestingValueStore* TestExtensionSystem::value_store() {
cmumford6ae8d462016-03-24 20:35:27176 // 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());
cmumfordf755705a2016-03-14 22:46:49179}
180
[email protected]31d8f5f22012-04-02 15:22:08181// static
dchengc963c7142016-04-08 03:55:22182std::unique_ptr<KeyedService> TestExtensionSystem::Build(
isherman30fa851a2015-06-09 23:32:10183 content::BrowserContext* profile) {
dchengc963c7142016-04-08 03:55:22184 return base::WrapUnique(
isherman30fa851a2015-06-09 23:32:10185 new TestExtensionSystem(static_cast<Profile*>(profile)));
[email protected]31d8f5f22012-04-02 15:22:08186}
[email protected]bd306722012-07-11 20:43:59187
treib926ee2d2015-08-06 10:55:42188void TestExtensionSystem::RecreateAppSorting() {
189 app_sorting_.reset(new ChromeAppSorting(profile_));
190}
191
[email protected]bd306722012-07-11 20:43:59192} // namespace extensions