Revert 200220 "Make ExtensionPrefs a ProfileKeyedService."
[chromium-blink-merge.git] / chrome / browser / extensions / test_extension_system.cc
blobf1641e06941a17ae628a9181d8ce4fded21a0632
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/event_router.h"
11 #include "chrome/browser/extensions/extension_info_map.h"
12 #include "chrome/browser/extensions/extension_pref_value_map.h"
13 #include "chrome/browser/extensions/extension_pref_value_map_factory.h"
14 #include "chrome/browser/extensions/extension_process_manager.h"
15 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/extension_system.h"
17 #include "chrome/browser/extensions/management_policy.h"
18 #include "chrome/browser/extensions/shell_window_geometry_cache.h"
19 #include "chrome/browser/extensions/standard_management_policy_provider.h"
20 #include "chrome/browser/extensions/state_store.h"
21 #include "chrome/browser/extensions/user_script_master.h"
22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/value_store/testing_value_store.h"
24 #include "chrome/common/chrome_switches.h"
25 #include "content/public/browser/browser_thread.h"
27 using content::BrowserThread;
29 namespace extensions {
31 TestExtensionSystem::TestExtensionSystem(Profile* profile)
32 : profile_(profile),
33 info_map_(new ExtensionInfoMap()) {
36 TestExtensionSystem::~TestExtensionSystem() {
39 void TestExtensionSystem::Shutdown() {
40 extension_process_manager_.reset();
43 void TestExtensionSystem::CreateExtensionProcessManager() {
44 extension_process_manager_.reset(ExtensionProcessManager::Create(profile_));
47 void TestExtensionSystem::CreateSocketManager() {
48 // Note that we're intentionally creating the socket manager on the wrong
49 // thread (not the IO thread). This is because we don't want to presume or
50 // require that there be an IO thread in a lightweight test context. If we do
51 // need thread-specific behavior someday, we'll probably need something like
52 // CreateSocketManagerOnThreadForTesting(thread_id). But not today.
53 BrowserThread::ID id;
54 CHECK(BrowserThread::GetCurrentThreadIdentifier(&id));
55 socket_manager_.reset(new ApiResourceManager<Socket>(id));
58 ExtensionPrefs* TestExtensionSystem::CreateExtensionPrefs(
59 const CommandLine* command_line,
60 const base::FilePath& install_directory) {
61 bool extensions_disabled =
62 command_line && command_line->HasSwitch(switches::kDisableExtensions);
64 // Note that the GetPrefs() creates a TestingPrefService, therefore
65 // the extension controlled pref values set in extension_prefs_
66 // are not reflected in the pref service. One would need to
67 // inject a new ExtensionPrefStore(extension_pref_value_map, false).
69 extension_prefs_ = ExtensionPrefs::Create(
70 profile_->GetPrefs(),
71 install_directory,
72 ExtensionPrefValueMapFactory::GetForProfile(profile_),
73 extensions_disabled);
74 return extension_prefs_.get();
77 ExtensionService* TestExtensionSystem::CreateExtensionService(
78 const CommandLine* command_line,
79 const base::FilePath& install_directory,
80 bool autoupdate_enabled) {
81 if (!extension_prefs_)
82 CreateExtensionPrefs(command_line, install_directory);
83 state_store_.reset(new StateStore(profile_, new TestingValueStore()));
84 shell_window_geometry_cache_.reset(
85 new ShellWindowGeometryCache(profile_, extension_prefs_.get()));
86 blacklist_.reset(new Blacklist(extension_prefs_.get()));
87 standard_management_policy_provider_.reset(
88 new StandardManagementPolicyProvider(extension_prefs_.get()));
89 management_policy_.reset(new ManagementPolicy());
90 management_policy_->RegisterProvider(
91 standard_management_policy_provider_.get());
92 extension_service_.reset(new ExtensionService(profile_,
93 command_line,
94 install_directory,
95 extension_prefs_.get(),
96 blacklist_.get(),
97 autoupdate_enabled,
98 true));
99 extension_service_->ClearProvidersForTesting();
100 return extension_service_.get();
103 ExtensionService* TestExtensionSystem::extension_service() {
104 return extension_service_.get();
107 ManagementPolicy* TestExtensionSystem::management_policy() {
108 return management_policy_.get();
111 void TestExtensionSystem::SetExtensionService(ExtensionService* service) {
112 extension_service_.reset(service);
115 UserScriptMaster* TestExtensionSystem::user_script_master() {
116 return NULL;
119 ExtensionProcessManager* TestExtensionSystem::process_manager() {
120 return extension_process_manager_.get();
123 StateStore* TestExtensionSystem::state_store() {
124 return state_store_.get();
127 StateStore* TestExtensionSystem::rules_store() {
128 return state_store_.get();
131 ExtensionPrefs* TestExtensionSystem::extension_prefs() {
132 return extension_prefs_.get();
135 ShellWindowGeometryCache* TestExtensionSystem::shell_window_geometry_cache() {
136 return shell_window_geometry_cache_.get();
139 ExtensionInfoMap* TestExtensionSystem::info_map() {
140 return info_map_.get();
143 LazyBackgroundTaskQueue*
144 TestExtensionSystem::lazy_background_task_queue() {
145 return NULL;
148 EventRouter* TestExtensionSystem::event_router() {
149 return NULL;
152 RulesRegistryService* TestExtensionSystem::rules_registry_service() {
153 return NULL;
156 ApiResourceManager<SerialConnection>*
157 TestExtensionSystem::serial_connection_manager() {
158 return NULL;
161 ApiResourceManager<Socket>*TestExtensionSystem::socket_manager() {
162 return socket_manager_.get();
165 ApiResourceManager<UsbDeviceResource>*
166 TestExtensionSystem::usb_device_resource_manager() {
167 return NULL;
170 ExtensionWarningService* TestExtensionSystem::warning_service() {
171 return NULL;
174 Blacklist* TestExtensionSystem::blacklist() {
175 return blacklist_.get();
178 // static
179 ProfileKeyedService* TestExtensionSystem::Build(
180 content::BrowserContext* profile) {
181 return new TestExtensionSystem(static_cast<Profile*>(profile));
184 } // namespace extensions