1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/extensions/test_extension_system.h"
#include "base/command_line.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/extensions/blacklist.h"
#include "chrome/browser/extensions/declarative_user_script_manager.h"
#include "chrome/browser/extensions/error_console/error_console.h"
#include "chrome/browser/extensions/extension_management.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/install_verifier.h"
#include "chrome/browser/extensions/shared_module_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_pref_value_map.h"
#include "extensions/browser/extension_pref_value_map_factory.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_prefs_factory.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/info_map.h"
#include "extensions/browser/management_policy.h"
#include "extensions/browser/quota_service.h"
#include "extensions/browser/runtime_data.h"
#include "extensions/browser/state_store.h"
#include "extensions/browser/value_store/testing_value_store.h"
using content::BrowserThread;
namespace extensions {
TestExtensionSystem::TestExtensionSystem(Profile* profile)
: profile_(profile),
value_store_(NULL),
info_map_(new InfoMap()),
error_console_(new ErrorConsole(profile)),
quota_service_(new QuotaService()) {}
TestExtensionSystem::~TestExtensionSystem() {
}
void TestExtensionSystem::Shutdown() {
if (extension_service_)
extension_service_->Shutdown();
}
ExtensionPrefs* TestExtensionSystem::CreateExtensionPrefs(
const base::CommandLine* command_line,
const base::FilePath& install_directory) {
bool extensions_disabled =
command_line && command_line->HasSwitch(switches::kDisableExtensions);
// Note that the GetPrefs() creates a TestingPrefService, therefore
// the extension controlled pref values set in ExtensionPrefs
// are not reflected in the pref service. One would need to
// inject a new ExtensionPrefStore(extension_pref_value_map, false).
ExtensionPrefs* extension_prefs = ExtensionPrefs::Create(
profile_->GetPrefs(),
install_directory,
ExtensionPrefValueMapFactory::GetForBrowserContext(profile_),
ExtensionsBrowserClient::Get()->CreateAppSorting().Pass(),
extensions_disabled,
std::vector<ExtensionPrefsObserver*>());
ExtensionPrefsFactory::GetInstance()->SetInstanceForTesting(
profile_,
extension_prefs);
return extension_prefs;
}
ExtensionService* TestExtensionSystem::CreateExtensionService(
const base::CommandLine* command_line,
const base::FilePath& install_directory,
bool autoupdate_enabled) {
if (!ExtensionPrefs::Get(profile_))
CreateExtensionPrefs(command_line, install_directory);
install_verifier_.reset(
new InstallVerifier(ExtensionPrefs::Get(profile_), profile_));
// The ownership of |value_store_| is immediately transferred to state_store_,
// but we keep a naked pointer to the TestingValueStore.
scoped_ptr<TestingValueStore> value_store(new TestingValueStore());
value_store_ = value_store.get();
state_store_.reset(new StateStore(profile_, value_store.Pass()));
declarative_user_script_manager_.reset(
new DeclarativeUserScriptManager(profile_));
management_policy_.reset(new ManagementPolicy());
management_policy_->RegisterProviders(
ExtensionManagementFactory::GetForBrowserContext(profile_)
->GetProviders());
runtime_data_.reset(new RuntimeData(ExtensionRegistry::Get(profile_)));
extension_service_.reset(new ExtensionService(profile_,
command_line,
install_directory,
ExtensionPrefs::Get(profile_),
Blacklist::Get(profile_),
autoupdate_enabled,
true,
&ready_));
extension_service_->ClearProvidersForTesting();
return extension_service_.get();
}
ExtensionService* TestExtensionSystem::extension_service() {
return extension_service_.get();
}
RuntimeData* TestExtensionSystem::runtime_data() {
return runtime_data_.get();
}
ManagementPolicy* TestExtensionSystem::management_policy() {
return management_policy_.get();
}
void TestExtensionSystem::SetExtensionService(ExtensionService* service) {
extension_service_.reset(service);
}
SharedUserScriptMaster* TestExtensionSystem::shared_user_script_master() {
return NULL;
}
DeclarativeUserScriptManager*
TestExtensionSystem::declarative_user_script_manager() {
return declarative_user_script_manager_.get();
}
StateStore* TestExtensionSystem::state_store() {
return state_store_.get();
}
StateStore* TestExtensionSystem::rules_store() {
return state_store_.get();
}
InfoMap* TestExtensionSystem::info_map() { return info_map_.get(); }
LazyBackgroundTaskQueue*
TestExtensionSystem::lazy_background_task_queue() {
return NULL;
}
void TestExtensionSystem::SetEventRouter(scoped_ptr<EventRouter> event_router) {
event_router_.reset(event_router.release());
}
EventRouter* TestExtensionSystem::event_router() { return event_router_.get(); }
ErrorConsole* TestExtensionSystem::error_console() {
return error_console_.get();
}
InstallVerifier* TestExtensionSystem::install_verifier() {
return install_verifier_.get();
}
QuotaService* TestExtensionSystem::quota_service() {
return quota_service_.get();
}
const OneShotEvent& TestExtensionSystem::ready() const {
return ready_;
}
ContentVerifier* TestExtensionSystem::content_verifier() {
return NULL;
}
scoped_ptr<ExtensionSet> TestExtensionSystem::GetDependentExtensions(
const Extension* extension) {
return extension_service()->shared_module_service()->GetDependentExtensions(
extension);
}
// static
KeyedService* TestExtensionSystem::Build(content::BrowserContext* profile) {
return new TestExtensionSystem(static_cast<Profile*>(profile));
}
} // namespace extensions
|