app_list: Re-enable people search.
[chromium-blink-merge.git] / chrome / browser / extensions / test_extension_system.cc
blob2897549399b19d5a097c732506f652bfb120cae2
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/declarative_user_script_manager.h"
11 #include "chrome/browser/extensions/error_console/error_console.h"
12 #include "chrome/browser/extensions/extension_management.h"
13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/install_verifier.h"
15 #include "chrome/browser/extensions/shared_module_service.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/chrome_switches.h"
18 #include "content/public/browser/browser_thread.h"
19 #include "extensions/browser/event_router.h"
20 #include "extensions/browser/extension_pref_value_map.h"
21 #include "extensions/browser/extension_pref_value_map_factory.h"
22 #include "extensions/browser/extension_prefs.h"
23 #include "extensions/browser/extension_prefs_factory.h"
24 #include "extensions/browser/extension_registry.h"
25 #include "extensions/browser/extension_system.h"
26 #include "extensions/browser/extensions_browser_client.h"
27 #include "extensions/browser/info_map.h"
28 #include "extensions/browser/management_policy.h"
29 #include "extensions/browser/quota_service.h"
30 #include "extensions/browser/runtime_data.h"
31 #include "extensions/browser/state_store.h"
32 #include "extensions/browser/value_store/testing_value_store.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)),
43 quota_service_(new QuotaService()) {}
45 TestExtensionSystem::~TestExtensionSystem() {
48 void TestExtensionSystem::Shutdown() {
49 if (extension_service_)
50 extension_service_->Shutdown();
53 ExtensionPrefs* TestExtensionSystem::CreateExtensionPrefs(
54 const base::CommandLine* command_line,
55 const base::FilePath& install_directory) {
56 bool extensions_disabled =
57 command_line && command_line->HasSwitch(switches::kDisableExtensions);
59 // Note that the GetPrefs() creates a TestingPrefService, therefore
60 // the extension controlled pref values set in ExtensionPrefs
61 // are not reflected in the pref service. One would need to
62 // inject a new ExtensionPrefStore(extension_pref_value_map, false).
64 ExtensionPrefs* extension_prefs = ExtensionPrefs::Create(
65 profile_->GetPrefs(),
66 install_directory,
67 ExtensionPrefValueMapFactory::GetForBrowserContext(profile_),
68 ExtensionsBrowserClient::Get()->CreateAppSorting().Pass(),
69 extensions_disabled,
70 std::vector<ExtensionPrefsObserver*>());
71 ExtensionPrefsFactory::GetInstance()->SetInstanceForTesting(
72 profile_,
73 extension_prefs);
74 return extension_prefs;
77 ExtensionService* TestExtensionSystem::CreateExtensionService(
78 const base::CommandLine* command_line,
79 const base::FilePath& install_directory,
80 bool autoupdate_enabled) {
81 if (!ExtensionPrefs::Get(profile_))
82 CreateExtensionPrefs(command_line, install_directory);
83 install_verifier_.reset(
84 new InstallVerifier(ExtensionPrefs::Get(profile_), profile_));
85 // The ownership of |value_store_| is immediately transferred to state_store_,
86 // but we keep a naked pointer to the TestingValueStore.
87 scoped_ptr<TestingValueStore> value_store(new TestingValueStore());
88 value_store_ = value_store.get();
89 state_store_.reset(new StateStore(profile_, value_store.Pass()));
90 declarative_user_script_manager_.reset(
91 new DeclarativeUserScriptManager(profile_));
92 management_policy_.reset(new ManagementPolicy());
93 management_policy_->RegisterProviders(
94 ExtensionManagementFactory::GetForBrowserContext(profile_)
95 ->GetProviders());
96 runtime_data_.reset(new RuntimeData(ExtensionRegistry::Get(profile_)));
97 extension_service_.reset(new ExtensionService(profile_,
98 command_line,
99 install_directory,
100 ExtensionPrefs::Get(profile_),
101 Blacklist::Get(profile_),
102 autoupdate_enabled,
103 true,
104 &ready_));
105 extension_service_->ClearProvidersForTesting();
106 return extension_service_.get();
109 ExtensionService* TestExtensionSystem::extension_service() {
110 return extension_service_.get();
113 RuntimeData* TestExtensionSystem::runtime_data() {
114 return runtime_data_.get();
117 ManagementPolicy* TestExtensionSystem::management_policy() {
118 return management_policy_.get();
121 void TestExtensionSystem::SetExtensionService(ExtensionService* service) {
122 extension_service_.reset(service);
125 SharedUserScriptMaster* TestExtensionSystem::shared_user_script_master() {
126 return NULL;
129 DeclarativeUserScriptManager*
130 TestExtensionSystem::declarative_user_script_manager() {
131 return declarative_user_script_manager_.get();
134 StateStore* TestExtensionSystem::state_store() {
135 return state_store_.get();
138 StateStore* TestExtensionSystem::rules_store() {
139 return state_store_.get();
142 InfoMap* TestExtensionSystem::info_map() { return info_map_.get(); }
144 LazyBackgroundTaskQueue*
145 TestExtensionSystem::lazy_background_task_queue() {
146 return NULL;
149 void TestExtensionSystem::SetEventRouter(scoped_ptr<EventRouter> event_router) {
150 event_router_.reset(event_router.release());
153 EventRouter* TestExtensionSystem::event_router() { return event_router_.get(); }
155 ErrorConsole* TestExtensionSystem::error_console() {
156 return error_console_.get();
159 InstallVerifier* TestExtensionSystem::install_verifier() {
160 return install_verifier_.get();
163 QuotaService* TestExtensionSystem::quota_service() {
164 return quota_service_.get();
167 const OneShotEvent& TestExtensionSystem::ready() const {
168 return ready_;
171 ContentVerifier* TestExtensionSystem::content_verifier() {
172 return NULL;
175 scoped_ptr<ExtensionSet> TestExtensionSystem::GetDependentExtensions(
176 const Extension* extension) {
177 return extension_service()->shared_module_service()->GetDependentExtensions(
178 extension);
181 // static
182 KeyedService* TestExtensionSystem::Build(content::BrowserContext* profile) {
183 return new TestExtensionSystem(static_cast<Profile*>(profile));
186 } // namespace extensions