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/extension_management.h"
11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/shared_module_service.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/common/chrome_switches.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "extensions/browser/extension_pref_value_map.h"
17 #include "extensions/browser/extension_pref_value_map_factory.h"
18 #include "extensions/browser/extension_prefs.h"
19 #include "extensions/browser/extension_registry.h"
20 #include "extensions/browser/extension_system.h"
21 #include "extensions/browser/extensions_browser_client.h"
22 #include "extensions/browser/info_map.h"
23 #include "extensions/browser/management_policy.h"
24 #include "extensions/browser/quota_service.h"
25 #include "extensions/browser/runtime_data.h"
26 #include "extensions/browser/state_store.h"
27 #include "extensions/browser/value_store/testing_value_store.h"
29 using content::BrowserThread
;
31 namespace extensions
{
33 TestExtensionSystem::TestExtensionSystem(Profile
* profile
)
36 info_map_(new InfoMap()),
37 quota_service_(new QuotaService()) {}
39 TestExtensionSystem::~TestExtensionSystem() {
42 void TestExtensionSystem::Shutdown() {
43 if (extension_service_
)
44 extension_service_
->Shutdown();
47 scoped_ptr
<ExtensionPrefs
> TestExtensionSystem::CreateExtensionPrefs(
48 const base::CommandLine
* command_line
,
49 const base::FilePath
& install_directory
) {
50 bool extensions_disabled
=
51 command_line
&& command_line
->HasSwitch(switches::kDisableExtensions
);
53 // Note that the GetPrefs() creates a TestingPrefService, therefore
54 // the extension controlled pref values set in ExtensionPrefs
55 // are not reflected in the pref service. One would need to
56 // inject a new ExtensionPrefStore(extension_pref_value_map, false).
58 return make_scoped_ptr(ExtensionPrefs::Create(
59 profile_
->GetPrefs(), install_directory
,
60 ExtensionPrefValueMapFactory::GetForBrowserContext(profile_
),
61 ExtensionsBrowserClient::Get()->CreateAppSorting().Pass(),
62 extensions_disabled
, std::vector
<ExtensionPrefsObserver
*>()));
65 ExtensionService
* TestExtensionSystem::CreateExtensionService(
66 const base::CommandLine
* command_line
,
67 const base::FilePath
& install_directory
,
68 bool autoupdate_enabled
) {
69 // The ownership of |value_store_| is immediately transferred to state_store_,
70 // but we keep a naked pointer to the TestingValueStore.
71 scoped_ptr
<TestingValueStore
> value_store(new TestingValueStore());
72 value_store_
= value_store
.get();
73 state_store_
.reset(new StateStore(profile_
, value_store
.Pass()));
74 management_policy_
.reset(new ManagementPolicy());
75 management_policy_
->RegisterProviders(
76 ExtensionManagementFactory::GetForBrowserContext(profile_
)
78 runtime_data_
.reset(new RuntimeData(ExtensionRegistry::Get(profile_
)));
79 extension_service_
.reset(new ExtensionService(profile_
,
82 ExtensionPrefs::Get(profile_
),
83 Blacklist::Get(profile_
),
87 extension_service_
->ClearProvidersForTesting();
88 return extension_service_
.get();
91 ExtensionService
* TestExtensionSystem::extension_service() {
92 return extension_service_
.get();
95 RuntimeData
* TestExtensionSystem::runtime_data() {
96 return runtime_data_
.get();
99 ManagementPolicy
* TestExtensionSystem::management_policy() {
100 return management_policy_
.get();
103 void TestExtensionSystem::SetExtensionService(ExtensionService
* service
) {
104 extension_service_
.reset(service
);
107 SharedUserScriptMaster
* TestExtensionSystem::shared_user_script_master() {
111 StateStore
* TestExtensionSystem::state_store() {
112 return state_store_
.get();
115 StateStore
* TestExtensionSystem::rules_store() {
116 return state_store_
.get();
119 InfoMap
* TestExtensionSystem::info_map() { return info_map_
.get(); }
121 QuotaService
* TestExtensionSystem::quota_service() {
122 return quota_service_
.get();
125 const OneShotEvent
& TestExtensionSystem::ready() const {
129 ContentVerifier
* TestExtensionSystem::content_verifier() {
133 scoped_ptr
<ExtensionSet
> TestExtensionSystem::GetDependentExtensions(
134 const Extension
* extension
) {
135 return extension_service()->shared_module_service()->GetDependentExtensions(
140 scoped_ptr
<KeyedService
> TestExtensionSystem::Build(
141 content::BrowserContext
* profile
) {
142 return make_scoped_ptr(
143 new TestExtensionSystem(static_cast<Profile
*>(profile
)));
146 } // namespace extensions