Fast user switcher: Distinguish supervised users from child accounts
[chromium-blink-merge.git] / chrome / browser / extensions / test_extension_system.cc
blob820f627ec28a041914c2a540580ac69b604ca538
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_management.h"
12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/extensions/install_verifier.h"
14 #include "chrome/browser/extensions/shared_module_service.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "content/public/browser/browser_thread.h"
18 #include "extensions/browser/declarative_user_script_manager.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/lazy_background_task_queue.h"
29 #include "extensions/browser/management_policy.h"
30 #include "extensions/browser/quota_service.h"
31 #include "extensions/browser/runtime_data.h"
32 #include "extensions/browser/state_store.h"
33 #include "extensions/browser/value_store/testing_value_store.h"
35 using content::BrowserThread;
37 namespace extensions {
39 TestExtensionSystem::TestExtensionSystem(Profile* profile)
40 : profile_(profile),
41 value_store_(NULL),
42 info_map_(new InfoMap()),
43 error_console_(new ErrorConsole(profile)),
44 quota_service_(new QuotaService()) {}
46 TestExtensionSystem::~TestExtensionSystem() {
49 void TestExtensionSystem::Shutdown() {
50 if (extension_service_)
51 extension_service_->Shutdown();
54 void TestExtensionSystem::CreateLazyBackgroundTaskQueue() {
55 lazy_background_task_queue_.reset(new LazyBackgroundTaskQueue(profile_));
58 ExtensionPrefs* TestExtensionSystem::CreateExtensionPrefs(
59 const base::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 ExtensionPrefs
66 // are not reflected in the pref service. One would need to
67 // inject a new ExtensionPrefStore(extension_pref_value_map, false).
69 ExtensionPrefs* extension_prefs = ExtensionPrefs::Create(
70 profile_->GetPrefs(),
71 install_directory,
72 ExtensionPrefValueMapFactory::GetForBrowserContext(profile_),
73 ExtensionsBrowserClient::Get()->CreateAppSorting().Pass(),
74 extensions_disabled,
75 std::vector<ExtensionPrefsObserver*>());
76 ExtensionPrefsFactory::GetInstance()->SetInstanceForTesting(
77 profile_,
78 extension_prefs);
79 return extension_prefs;
82 ExtensionService* TestExtensionSystem::CreateExtensionService(
83 const base::CommandLine* command_line,
84 const base::FilePath& install_directory,
85 bool autoupdate_enabled) {
86 if (!ExtensionPrefs::Get(profile_))
87 CreateExtensionPrefs(command_line, install_directory);
88 install_verifier_.reset(
89 new InstallVerifier(ExtensionPrefs::Get(profile_), profile_));
90 // The ownership of |value_store_| is immediately transferred to state_store_,
91 // but we keep a naked pointer to the TestingValueStore.
92 scoped_ptr<TestingValueStore> value_store(new TestingValueStore());
93 value_store_ = value_store.get();
94 state_store_.reset(new StateStore(profile_, value_store.Pass()));
95 declarative_user_script_manager_.reset(
96 new DeclarativeUserScriptManager(profile_));
97 management_policy_.reset(new ManagementPolicy());
98 management_policy_->RegisterProviders(
99 ExtensionManagementFactory::GetForBrowserContext(profile_)
100 ->GetProviders());
101 runtime_data_.reset(new RuntimeData(ExtensionRegistry::Get(profile_)));
102 extension_service_.reset(new ExtensionService(profile_,
103 command_line,
104 install_directory,
105 ExtensionPrefs::Get(profile_),
106 Blacklist::Get(profile_),
107 autoupdate_enabled,
108 true,
109 &ready_));
110 extension_service_->ClearProvidersForTesting();
111 return extension_service_.get();
114 ExtensionService* TestExtensionSystem::extension_service() {
115 return extension_service_.get();
118 RuntimeData* TestExtensionSystem::runtime_data() {
119 return runtime_data_.get();
122 ManagementPolicy* TestExtensionSystem::management_policy() {
123 return management_policy_.get();
126 void TestExtensionSystem::SetExtensionService(ExtensionService* service) {
127 extension_service_.reset(service);
130 SharedUserScriptMaster* TestExtensionSystem::shared_user_script_master() {
131 return NULL;
134 DeclarativeUserScriptManager*
135 TestExtensionSystem::declarative_user_script_manager() {
136 return declarative_user_script_manager_.get();
139 StateStore* TestExtensionSystem::state_store() {
140 return state_store_.get();
143 StateStore* TestExtensionSystem::rules_store() {
144 return state_store_.get();
147 InfoMap* TestExtensionSystem::info_map() { return info_map_.get(); }
149 LazyBackgroundTaskQueue*
150 TestExtensionSystem::lazy_background_task_queue() {
151 return lazy_background_task_queue_.get();
154 void TestExtensionSystem::SetEventRouter(scoped_ptr<EventRouter> event_router) {
155 event_router_.reset(event_router.release());
158 EventRouter* TestExtensionSystem::event_router() { return event_router_.get(); }
160 ErrorConsole* TestExtensionSystem::error_console() {
161 return error_console_.get();
164 InstallVerifier* TestExtensionSystem::install_verifier() {
165 return install_verifier_.get();
168 QuotaService* TestExtensionSystem::quota_service() {
169 return quota_service_.get();
172 const OneShotEvent& TestExtensionSystem::ready() const {
173 return ready_;
176 ContentVerifier* TestExtensionSystem::content_verifier() {
177 return NULL;
180 scoped_ptr<ExtensionSet> TestExtensionSystem::GetDependentExtensions(
181 const Extension* extension) {
182 return extension_service()->shared_module_service()->GetDependentExtensions(
183 extension);
186 // static
187 KeyedService* TestExtensionSystem::Build(content::BrowserContext* profile) {
188 return new TestExtensionSystem(static_cast<Profile*>(profile));
191 } // namespace extensions