OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/test_extension_system.h" | 5 #include "chrome/browser/extensions/test_extension_system.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "chrome/browser/extensions/blacklist.h" | 9 #include "chrome/browser/extensions/blacklist.h" |
10 #include "chrome/browser/extensions/chrome_app_sorting.h" | |
10 #include "chrome/browser/extensions/extension_management.h" | 11 #include "chrome/browser/extensions/extension_management.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/extensions/shared_module_service.h" | 13 #include "chrome/browser/extensions/shared_module_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
15 #include "content/public/browser/browser_thread.h" | 16 #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" | 17 #include "extensions/browser/extension_prefs.h" |
19 #include "extensions/browser/extension_registry.h" | 18 #include "extensions/browser/extension_registry.h" |
20 #include "extensions/browser/extension_system.h" | 19 #include "extensions/browser/extension_system.h" |
21 #include "extensions/browser/extensions_browser_client.h" | 20 #include "extensions/browser/extensions_browser_client.h" |
22 #include "extensions/browser/info_map.h" | 21 #include "extensions/browser/info_map.h" |
23 #include "extensions/browser/management_policy.h" | 22 #include "extensions/browser/management_policy.h" |
24 #include "extensions/browser/quota_service.h" | 23 #include "extensions/browser/quota_service.h" |
25 #include "extensions/browser/runtime_data.h" | 24 #include "extensions/browser/runtime_data.h" |
26 #include "extensions/browser/state_store.h" | 25 #include "extensions/browser/state_store.h" |
27 #include "extensions/browser/value_store/testing_value_store.h" | 26 #include "extensions/browser/value_store/testing_value_store.h" |
28 | 27 |
29 using content::BrowserThread; | 28 using content::BrowserThread; |
30 | 29 |
31 namespace extensions { | 30 namespace extensions { |
32 | 31 |
33 TestExtensionSystem::TestExtensionSystem(Profile* profile) | 32 TestExtensionSystem::TestExtensionSystem(Profile* profile) |
34 : profile_(profile), | 33 : profile_(profile), |
35 value_store_(NULL), | 34 value_store_(NULL), |
36 info_map_(new InfoMap()), | 35 info_map_(new InfoMap()), |
37 quota_service_(new QuotaService()) {} | 36 quota_service_(new QuotaService()), |
37 app_sorting_(new ChromeAppSorting(profile_)) { | |
Marc Treib
2015/08/03 15:28:03
Turns out a bunch of tests depend on this returnin
| |
38 ExtensionPrefs::Get(profile_)->set_app_sorting(app_sorting_.get()); | |
39 } | |
38 | 40 |
39 TestExtensionSystem::~TestExtensionSystem() { | 41 TestExtensionSystem::~TestExtensionSystem() { |
40 } | 42 } |
41 | 43 |
42 void TestExtensionSystem::Shutdown() { | 44 void TestExtensionSystem::Shutdown() { |
43 if (extension_service_) | 45 if (extension_service_) |
44 extension_service_->Shutdown(); | 46 extension_service_->Shutdown(); |
45 } | 47 } |
46 | 48 |
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); | |
52 | |
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). | |
57 | |
58 return make_scoped_ptr(ExtensionPrefs::Create( | |
59 profile_->GetPrefs(), install_directory, | |
60 ExtensionPrefValueMapFactory::GetForBrowserContext(profile_), | |
61 ExtensionsBrowserClient::Get()->CreateAppSorting(profile_).Pass(), | |
62 extensions_disabled, std::vector<ExtensionPrefsObserver*>())); | |
63 } | |
64 | |
65 ExtensionService* TestExtensionSystem::CreateExtensionService( | 49 ExtensionService* TestExtensionSystem::CreateExtensionService( |
66 const base::CommandLine* command_line, | 50 const base::CommandLine* command_line, |
67 const base::FilePath& install_directory, | 51 const base::FilePath& install_directory, |
68 bool autoupdate_enabled) { | 52 bool autoupdate_enabled) { |
69 // The ownership of |value_store_| is immediately transferred to state_store_, | 53 // The ownership of |value_store_| is immediately transferred to state_store_, |
70 // but we keep a naked pointer to the TestingValueStore. | 54 // but we keep a naked pointer to the TestingValueStore. |
71 scoped_ptr<TestingValueStore> value_store(new TestingValueStore()); | 55 scoped_ptr<TestingValueStore> value_store(new TestingValueStore()); |
72 value_store_ = value_store.get(); | 56 value_store_ = value_store.get(); |
73 state_store_.reset(new StateStore(profile_, value_store.Pass())); | 57 state_store_.reset(new StateStore(profile_, value_store.Pass())); |
74 management_policy_.reset(new ManagementPolicy()); | 58 management_policy_.reset(new ManagementPolicy()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 StateStore* TestExtensionSystem::rules_store() { | 99 StateStore* TestExtensionSystem::rules_store() { |
116 return state_store_.get(); | 100 return state_store_.get(); |
117 } | 101 } |
118 | 102 |
119 InfoMap* TestExtensionSystem::info_map() { return info_map_.get(); } | 103 InfoMap* TestExtensionSystem::info_map() { return info_map_.get(); } |
120 | 104 |
121 QuotaService* TestExtensionSystem::quota_service() { | 105 QuotaService* TestExtensionSystem::quota_service() { |
122 return quota_service_.get(); | 106 return quota_service_.get(); |
123 } | 107 } |
124 | 108 |
109 AppSorting* TestExtensionSystem::app_sorting() { | |
110 return app_sorting_.get(); | |
111 } | |
112 | |
125 const OneShotEvent& TestExtensionSystem::ready() const { | 113 const OneShotEvent& TestExtensionSystem::ready() const { |
126 return ready_; | 114 return ready_; |
127 } | 115 } |
128 | 116 |
129 ContentVerifier* TestExtensionSystem::content_verifier() { | 117 ContentVerifier* TestExtensionSystem::content_verifier() { |
130 return NULL; | 118 return NULL; |
131 } | 119 } |
132 | 120 |
133 scoped_ptr<ExtensionSet> TestExtensionSystem::GetDependentExtensions( | 121 scoped_ptr<ExtensionSet> TestExtensionSystem::GetDependentExtensions( |
134 const Extension* extension) { | 122 const Extension* extension) { |
135 return extension_service()->shared_module_service()->GetDependentExtensions( | 123 return extension_service()->shared_module_service()->GetDependentExtensions( |
136 extension); | 124 extension); |
137 } | 125 } |
138 | 126 |
139 // static | 127 // static |
140 scoped_ptr<KeyedService> TestExtensionSystem::Build( | 128 scoped_ptr<KeyedService> TestExtensionSystem::Build( |
141 content::BrowserContext* profile) { | 129 content::BrowserContext* profile) { |
142 return make_scoped_ptr( | 130 return make_scoped_ptr( |
143 new TestExtensionSystem(static_cast<Profile*>(profile))); | 131 new TestExtensionSystem(static_cast<Profile*>(profile))); |
144 } | 132 } |
145 | 133 |
146 } // namespace extensions | 134 } // namespace extensions |
OLD | NEW |