Move ownership of AppSorting from ExtensionPrefs to ExtensionSystem
[chromium-blink-merge.git] / chrome / browser / extensions / test_extension_system.cc
blob74e2c143c693547f6d33a2a03df482384939675f
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/chrome_app_sorting.h"
11 #include "chrome/browser/extensions/extension_management.h"
12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/extensions/shared_module_service.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "extensions/browser/extension_prefs.h"
18 #include "extensions/browser/extension_registry.h"
19 #include "extensions/browser/extension_system.h"
20 #include "extensions/browser/extensions_browser_client.h"
21 #include "extensions/browser/info_map.h"
22 #include "extensions/browser/management_policy.h"
23 #include "extensions/browser/quota_service.h"
24 #include "extensions/browser/runtime_data.h"
25 #include "extensions/browser/state_store.h"
26 #include "extensions/browser/value_store/testing_value_store.h"
28 using content::BrowserThread;
30 namespace extensions {
32 TestExtensionSystem::TestExtensionSystem(Profile* profile)
33 : profile_(profile),
34 value_store_(NULL),
35 info_map_(new InfoMap()),
36 quota_service_(new QuotaService()),
37 app_sorting_(new ChromeAppSorting(profile_)) {
40 TestExtensionSystem::~TestExtensionSystem() {
43 void TestExtensionSystem::Shutdown() {
44 if (extension_service_)
45 extension_service_->Shutdown();
48 ExtensionService* TestExtensionSystem::CreateExtensionService(
49 const base::CommandLine* command_line,
50 const base::FilePath& install_directory,
51 bool autoupdate_enabled) {
52 // The ownership of |value_store_| is immediately transferred to state_store_,
53 // but we keep a naked pointer to the TestingValueStore.
54 scoped_ptr<TestingValueStore> value_store(new TestingValueStore());
55 value_store_ = value_store.get();
56 state_store_.reset(new StateStore(profile_, value_store.Pass()));
57 management_policy_.reset(new ManagementPolicy());
58 management_policy_->RegisterProviders(
59 ExtensionManagementFactory::GetForBrowserContext(profile_)
60 ->GetProviders());
61 runtime_data_.reset(new RuntimeData(ExtensionRegistry::Get(profile_)));
62 extension_service_.reset(new ExtensionService(profile_,
63 command_line,
64 install_directory,
65 ExtensionPrefs::Get(profile_),
66 Blacklist::Get(profile_),
67 autoupdate_enabled,
68 true,
69 &ready_));
70 extension_service_->ClearProvidersForTesting();
71 return extension_service_.get();
74 ExtensionService* TestExtensionSystem::extension_service() {
75 return extension_service_.get();
78 RuntimeData* TestExtensionSystem::runtime_data() {
79 return runtime_data_.get();
82 ManagementPolicy* TestExtensionSystem::management_policy() {
83 return management_policy_.get();
86 void TestExtensionSystem::SetExtensionService(ExtensionService* service) {
87 extension_service_.reset(service);
90 SharedUserScriptMaster* TestExtensionSystem::shared_user_script_master() {
91 return NULL;
94 StateStore* TestExtensionSystem::state_store() {
95 return state_store_.get();
98 StateStore* TestExtensionSystem::rules_store() {
99 return state_store_.get();
102 InfoMap* TestExtensionSystem::info_map() { return info_map_.get(); }
104 QuotaService* TestExtensionSystem::quota_service() {
105 return quota_service_.get();
108 AppSorting* TestExtensionSystem::app_sorting() {
109 return app_sorting_.get();
112 const OneShotEvent& TestExtensionSystem::ready() const {
113 return ready_;
116 ContentVerifier* TestExtensionSystem::content_verifier() {
117 return NULL;
120 scoped_ptr<ExtensionSet> TestExtensionSystem::GetDependentExtensions(
121 const Extension* extension) {
122 return extension_service()->shared_module_service()->GetDependentExtensions(
123 extension);
126 // static
127 scoped_ptr<KeyedService> TestExtensionSystem::Build(
128 content::BrowserContext* profile) {
129 return make_scoped_ptr(
130 new TestExtensionSystem(static_cast<Profile*>(profile)));
133 void TestExtensionSystem::RecreateAppSorting() {
134 app_sorting_.reset(new ChromeAppSorting(profile_));
137 } // namespace extensions