| 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/extension_management.h" | 10 #include "chrome/browser/extensions/extension_management.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/shared_module_service.h" | 12 #include "chrome/browser/extensions/shared_module_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "extensions/browser/extension_pref_value_map.h" | 16 #include "extensions/browser/extension_pref_value_map.h" |
| 17 #include "extensions/browser/extension_pref_value_map_factory.h" | 17 #include "extensions/browser/extension_pref_value_map_factory.h" |
| 18 #include "extensions/browser/extension_prefs.h" | 18 #include "extensions/browser/extension_prefs.h" |
| 19 #include "extensions/browser/extension_registry.h" | 19 #include "extensions/browser/extension_registry.h" |
| 20 #include "extensions/browser/extension_system.h" | 20 #include "extensions/browser/extension_system.h" |
| 21 #include "extensions/browser/extensions_browser_client.h" | 21 #include "extensions/browser/extensions_browser_client.h" |
| 22 #include "extensions/browser/info_map.h" | 22 #include "extensions/browser/info_map.h" |
| 23 #include "extensions/browser/management_policy.h" | 23 #include "extensions/browser/management_policy.h" |
| 24 #include "extensions/browser/null_app_sorting.h" |
| 24 #include "extensions/browser/quota_service.h" | 25 #include "extensions/browser/quota_service.h" |
| 25 #include "extensions/browser/runtime_data.h" | 26 #include "extensions/browser/runtime_data.h" |
| 26 #include "extensions/browser/state_store.h" | 27 #include "extensions/browser/state_store.h" |
| 27 #include "extensions/browser/value_store/testing_value_store.h" | 28 #include "extensions/browser/value_store/testing_value_store.h" |
| 28 | 29 |
| 29 using content::BrowserThread; | 30 using content::BrowserThread; |
| 30 | 31 |
| 31 namespace extensions { | 32 namespace extensions { |
| 32 | 33 |
| 33 TestExtensionSystem::TestExtensionSystem(Profile* profile) | 34 TestExtensionSystem::TestExtensionSystem(Profile* profile) |
| 34 : profile_(profile), | 35 : profile_(profile), |
| 35 value_store_(NULL), | 36 value_store_(NULL), |
| 36 info_map_(new InfoMap()), | 37 info_map_(new InfoMap()), |
| 37 quota_service_(new QuotaService()) {} | 38 quota_service_(new QuotaService()), |
| 39 app_sorting_(new NullAppSorting) { |
| 40 } |
| 38 | 41 |
| 39 TestExtensionSystem::~TestExtensionSystem() { | 42 TestExtensionSystem::~TestExtensionSystem() { |
| 40 } | 43 } |
| 41 | 44 |
| 42 void TestExtensionSystem::Shutdown() { | 45 void TestExtensionSystem::Shutdown() { |
| 43 if (extension_service_) | 46 if (extension_service_) |
| 44 extension_service_->Shutdown(); | 47 extension_service_->Shutdown(); |
| 45 } | 48 } |
| 46 | 49 |
| 47 scoped_ptr<ExtensionPrefs> TestExtensionSystem::CreateExtensionPrefs( | 50 scoped_ptr<ExtensionPrefs> TestExtensionSystem::CreateExtensionPrefs( |
| 48 const base::CommandLine* command_line, | 51 const base::CommandLine* command_line, |
| 49 const base::FilePath& install_directory) { | 52 const base::FilePath& install_directory) { |
| 50 bool extensions_disabled = | 53 bool extensions_disabled = |
| 51 command_line && command_line->HasSwitch(switches::kDisableExtensions); | 54 command_line && command_line->HasSwitch(switches::kDisableExtensions); |
| 52 | 55 |
| 53 // Note that the GetPrefs() creates a TestingPrefService, therefore | 56 // Note that the GetPrefs() creates a TestingPrefService, therefore |
| 54 // the extension controlled pref values set in ExtensionPrefs | 57 // the extension controlled pref values set in ExtensionPrefs |
| 55 // are not reflected in the pref service. One would need to | 58 // are not reflected in the pref service. One would need to |
| 56 // inject a new ExtensionPrefStore(extension_pref_value_map, false). | 59 // inject a new ExtensionPrefStore(extension_pref_value_map, false). |
| 57 | 60 |
| 58 return make_scoped_ptr(ExtensionPrefs::Create( | 61 auto prefs = make_scoped_ptr(ExtensionPrefs::Create( |
| 59 profile_->GetPrefs(), install_directory, | 62 profile_->GetPrefs(), install_directory, |
| 60 ExtensionPrefValueMapFactory::GetForBrowserContext(profile_), | 63 ExtensionPrefValueMapFactory::GetForBrowserContext(profile_), |
| 61 ExtensionsBrowserClient::Get()->CreateAppSorting(profile_).Pass(), | |
| 62 extensions_disabled, std::vector<ExtensionPrefsObserver*>())); | 64 extensions_disabled, std::vector<ExtensionPrefsObserver*>())); |
| 65 prefs->set_app_sorting(app_sorting_.get()); |
| 66 return prefs; |
| 63 } | 67 } |
| 64 | 68 |
| 65 ExtensionService* TestExtensionSystem::CreateExtensionService( | 69 ExtensionService* TestExtensionSystem::CreateExtensionService( |
| 66 const base::CommandLine* command_line, | 70 const base::CommandLine* command_line, |
| 67 const base::FilePath& install_directory, | 71 const base::FilePath& install_directory, |
| 68 bool autoupdate_enabled) { | 72 bool autoupdate_enabled) { |
| 69 // The ownership of |value_store_| is immediately transferred to state_store_, | 73 // The ownership of |value_store_| is immediately transferred to state_store_, |
| 70 // but we keep a naked pointer to the TestingValueStore. | 74 // but we keep a naked pointer to the TestingValueStore. |
| 71 scoped_ptr<TestingValueStore> value_store(new TestingValueStore()); | 75 scoped_ptr<TestingValueStore> value_store(new TestingValueStore()); |
| 72 value_store_ = value_store.get(); | 76 value_store_ = value_store.get(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 StateStore* TestExtensionSystem::rules_store() { | 119 StateStore* TestExtensionSystem::rules_store() { |
| 116 return state_store_.get(); | 120 return state_store_.get(); |
| 117 } | 121 } |
| 118 | 122 |
| 119 InfoMap* TestExtensionSystem::info_map() { return info_map_.get(); } | 123 InfoMap* TestExtensionSystem::info_map() { return info_map_.get(); } |
| 120 | 124 |
| 121 QuotaService* TestExtensionSystem::quota_service() { | 125 QuotaService* TestExtensionSystem::quota_service() { |
| 122 return quota_service_.get(); | 126 return quota_service_.get(); |
| 123 } | 127 } |
| 124 | 128 |
| 129 AppSorting* TestExtensionSystem::app_sorting() { |
| 130 return app_sorting_.get(); |
| 131 } |
| 132 |
| 125 const OneShotEvent& TestExtensionSystem::ready() const { | 133 const OneShotEvent& TestExtensionSystem::ready() const { |
| 126 return ready_; | 134 return ready_; |
| 127 } | 135 } |
| 128 | 136 |
| 129 ContentVerifier* TestExtensionSystem::content_verifier() { | 137 ContentVerifier* TestExtensionSystem::content_verifier() { |
| 130 return NULL; | 138 return NULL; |
| 131 } | 139 } |
| 132 | 140 |
| 133 scoped_ptr<ExtensionSet> TestExtensionSystem::GetDependentExtensions( | 141 scoped_ptr<ExtensionSet> TestExtensionSystem::GetDependentExtensions( |
| 134 const Extension* extension) { | 142 const Extension* extension) { |
| 135 return extension_service()->shared_module_service()->GetDependentExtensions( | 143 return extension_service()->shared_module_service()->GetDependentExtensions( |
| 136 extension); | 144 extension); |
| 137 } | 145 } |
| 138 | 146 |
| 139 // static | 147 // static |
| 140 scoped_ptr<KeyedService> TestExtensionSystem::Build( | 148 scoped_ptr<KeyedService> TestExtensionSystem::Build( |
| 141 content::BrowserContext* profile) { | 149 content::BrowserContext* profile) { |
| 142 return make_scoped_ptr( | 150 return make_scoped_ptr( |
| 143 new TestExtensionSystem(static_cast<Profile*>(profile))); | 151 new TestExtensionSystem(static_cast<Profile*>(profile))); |
| 144 } | 152 } |
| 145 | 153 |
| 146 } // namespace extensions | 154 } // namespace extensions |
| OLD | NEW |