NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / extensions / test_extension_system.cc
blob416ca664f742d9a27643eb17cc8009d7d01eaffd
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.
5 #include "chrome/browser/extensions/test_extension_system.h"
7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/extensions/blacklist.h"
10 #include "chrome/browser/extensions/error_console/error_console.h"
11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/install_verifier.h"
13 #include "chrome/browser/extensions/standard_management_policy_provider.h"
14 #include "chrome/browser/extensions/state_store.h"
15 #include "chrome/browser/extensions/user_script_master.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/value_store/testing_value_store.h"
18 #include "chrome/common/chrome_switches.h"
19 #include "content/public/browser/browser_thread.h"
20 #include "extensions/browser/event_router.h"
21 #include "extensions/browser/extension_pref_value_map.h"
22 #include "extensions/browser/extension_pref_value_map_factory.h"
23 #include "extensions/browser/extension_prefs.h"
24 #include "extensions/browser/extension_prefs_factory.h"
25 #include "extensions/browser/extension_registry.h"
26 #include "extensions/browser/extension_system.h"
27 #include "extensions/browser/extensions_browser_client.h"
28 #include "extensions/browser/info_map.h"
29 #include "extensions/browser/management_policy.h"
30 #include "extensions/browser/process_manager.h"
31 #include "extensions/browser/quota_service.h"
32 #include "extensions/browser/runtime_data.h"
34 using content::BrowserThread;
36 namespace extensions {
38 TestExtensionSystem::TestExtensionSystem(Profile* profile)
39 : profile_(profile),
40 value_store_(NULL),
41 info_map_(new InfoMap()),
42 error_console_(new ErrorConsole(profile, NULL)),
43 quota_service_(new QuotaService()) {}
45 TestExtensionSystem::~TestExtensionSystem() {
48 void TestExtensionSystem::Shutdown() {
49 process_manager_.reset();
52 void TestExtensionSystem::CreateProcessManager() {
53 process_manager_.reset(ProcessManager::Create(profile_));
56 void TestExtensionSystem::SetProcessManager(ProcessManager* manager) {
57 process_manager_.reset(manager);
60 ExtensionPrefs* TestExtensionSystem::CreateExtensionPrefs(
61 const CommandLine* command_line,
62 const base::FilePath& install_directory) {
63 bool extensions_disabled =
64 command_line && command_line->HasSwitch(switches::kDisableExtensions);
66 // Note that the GetPrefs() creates a TestingPrefService, therefore
67 // the extension controlled pref values set in ExtensionPrefs
68 // are not reflected in the pref service. One would need to
69 // inject a new ExtensionPrefStore(extension_pref_value_map, false).
71 ExtensionPrefs* extension_prefs = ExtensionPrefs::Create(
72 profile_->GetPrefs(),
73 install_directory,
74 ExtensionPrefValueMapFactory::GetForBrowserContext(profile_),
75 ExtensionsBrowserClient::Get()->CreateAppSorting().Pass(),
76 extensions_disabled);
77 ExtensionPrefsFactory::GetInstance()->SetInstanceForTesting(
78 profile_,
79 extension_prefs);
80 return extension_prefs;
83 ExtensionService* TestExtensionSystem::CreateExtensionService(
84 const CommandLine* command_line,
85 const base::FilePath& install_directory,
86 bool autoupdate_enabled) {
87 if (!ExtensionPrefs::Get(profile_))
88 CreateExtensionPrefs(command_line, install_directory);
89 install_verifier_.reset(new InstallVerifier(ExtensionPrefs::Get(profile_),
90 NULL));
91 // The ownership of |value_store_| is immediately transferred to state_store_,
92 // but we keep a naked pointer to the TestingValueStore.
93 scoped_ptr<TestingValueStore> value_store(new TestingValueStore());
94 value_store_ = value_store.get();
95 state_store_.reset(
96 new StateStore(profile_, value_store.PassAs<ValueStore>()));
97 blacklist_.reset(new Blacklist(ExtensionPrefs::Get(profile_)));
98 standard_management_policy_provider_.reset(
99 new StandardManagementPolicyProvider(ExtensionPrefs::Get(profile_)));
100 management_policy_.reset(new ManagementPolicy());
101 management_policy_->RegisterProvider(
102 standard_management_policy_provider_.get());
103 runtime_data_.reset(new RuntimeData(ExtensionRegistry::Get(profile_)));
104 extension_service_.reset(new ExtensionService(profile_,
105 command_line,
106 install_directory,
107 ExtensionPrefs::Get(profile_),
108 blacklist_.get(),
109 autoupdate_enabled,
110 true,
111 &ready_));
112 extension_service_->ClearProvidersForTesting();
113 return extension_service_.get();
116 ExtensionService* TestExtensionSystem::extension_service() {
117 return extension_service_.get();
120 RuntimeData* TestExtensionSystem::runtime_data() {
121 return runtime_data_.get();
124 ManagementPolicy* TestExtensionSystem::management_policy() {
125 return management_policy_.get();
128 void TestExtensionSystem::SetExtensionService(ExtensionService* service) {
129 extension_service_.reset(service);
132 UserScriptMaster* TestExtensionSystem::user_script_master() {
133 return NULL;
136 ProcessManager* TestExtensionSystem::process_manager() {
137 return process_manager_.get();
140 StateStore* TestExtensionSystem::state_store() {
141 return state_store_.get();
144 StateStore* TestExtensionSystem::rules_store() {
145 return state_store_.get();
148 InfoMap* TestExtensionSystem::info_map() { return info_map_.get(); }
150 LazyBackgroundTaskQueue*
151 TestExtensionSystem::lazy_background_task_queue() {
152 return NULL;
155 EventRouter* TestExtensionSystem::event_router() {
156 return NULL;
159 ExtensionWarningService* TestExtensionSystem::warning_service() {
160 return NULL;
163 Blacklist* TestExtensionSystem::blacklist() {
164 return blacklist_.get();
167 ErrorConsole* TestExtensionSystem::error_console() {
168 return error_console_.get();
171 InstallVerifier* TestExtensionSystem::install_verifier() {
172 return install_verifier_.get();
175 QuotaService* TestExtensionSystem::quota_service() {
176 return quota_service_.get();
179 const OneShotEvent& TestExtensionSystem::ready() const {
180 return ready_;
183 // static
184 BrowserContextKeyedService* TestExtensionSystem::Build(
185 content::BrowserContext* profile) {
186 return new TestExtensionSystem(static_cast<Profile*>(profile));
189 } // namespace extensions