| 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_prefs.h" | 5 #include "chrome/browser/extensions/test_extension_prefs.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 9 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 10 #include "base/macros.h" | 12 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 13 #include "base/prefs/json_pref_store.h" | 15 #include "base/prefs/json_pref_store.h" |
| 14 #include "base/prefs/pref_value_store.h" | 16 #include "base/prefs/pref_value_store.h" |
| 15 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 16 #include "base/sequenced_task_runner.h" | 18 #include "base/sequenced_task_runner.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 base::Bind(&base::DoNothing), | 115 base::Bind(&base::DoNothing), |
| 114 run_loop.QuitClosure())); | 116 run_loop.QuitClosure())); |
| 115 run_loop.Run(); | 117 run_loop.Run(); |
| 116 } | 118 } |
| 117 | 119 |
| 118 extension_pref_value_map_.reset(new ExtensionPrefValueMap); | 120 extension_pref_value_map_.reset(new ExtensionPrefValueMap); |
| 119 syncable_prefs::PrefServiceMockFactory factory; | 121 syncable_prefs::PrefServiceMockFactory factory; |
| 120 factory.SetUserPrefsFile(preferences_file_, task_runner_.get()); | 122 factory.SetUserPrefsFile(preferences_file_, task_runner_.get()); |
| 121 factory.set_extension_prefs( | 123 factory.set_extension_prefs( |
| 122 new ExtensionPrefStore(extension_pref_value_map_.get(), false)); | 124 new ExtensionPrefStore(extension_pref_value_map_.get(), false)); |
| 123 pref_service_ = factory.CreateSyncable(pref_registry_.get()).Pass(); | 125 pref_service_ = factory.CreateSyncable(pref_registry_.get()); |
| 124 scoped_ptr<ExtensionPrefs> prefs(ExtensionPrefs::Create( | 126 scoped_ptr<ExtensionPrefs> prefs(ExtensionPrefs::Create( |
| 125 &profile_, | 127 &profile_, |
| 126 pref_service_.get(), | 128 pref_service_.get(), |
| 127 temp_dir_.path(), | 129 temp_dir_.path(), |
| 128 extension_pref_value_map_.get(), | 130 extension_pref_value_map_.get(), |
| 129 extensions_disabled_, | 131 extensions_disabled_, |
| 130 std::vector<ExtensionPrefsObserver*>(), | 132 std::vector<ExtensionPrefsObserver*>(), |
| 131 // Guarantee that no two extensions get the same installation time | 133 // Guarantee that no two extensions get the same installation time |
| 132 // stamp and we can reliably assert the installation order in the tests. | 134 // stamp and we can reliably assert the installation order in the tests. |
| 133 scoped_ptr<ExtensionPrefs::TimeProvider>(new IncrementalTimeProvider()))); | 135 scoped_ptr<ExtensionPrefs::TimeProvider>(new IncrementalTimeProvider()))); |
| 134 ExtensionPrefsFactory::GetInstance()->SetInstanceForTesting(&profile_, | 136 ExtensionPrefsFactory::GetInstance()->SetInstanceForTesting(&profile_, |
| 135 prefs.Pass()); | 137 std::move(prefs)); |
| 136 // Hack: After recreating ExtensionPrefs, the AppSorting also needs to be | 138 // Hack: After recreating ExtensionPrefs, the AppSorting also needs to be |
| 137 // recreated. (ExtensionPrefs is never recreated in non-test code.) | 139 // recreated. (ExtensionPrefs is never recreated in non-test code.) |
| 138 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(&profile_)) | 140 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(&profile_)) |
| 139 ->RecreateAppSorting(); | 141 ->RecreateAppSorting(); |
| 140 } | 142 } |
| 141 | 143 |
| 142 scoped_refptr<Extension> TestExtensionPrefs::AddExtension( | 144 scoped_refptr<Extension> TestExtensionPrefs::AddExtension( |
| 143 const std::string& name) { | 145 const std::string& name) { |
| 144 base::DictionaryValue dictionary; | 146 base::DictionaryValue dictionary; |
| 145 dictionary.SetString(manifest_keys::kName, name); | 147 dictionary.SetString(manifest_keys::kName, name); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 void TestExtensionPrefs::set_extensions_disabled(bool extensions_disabled) { | 209 void TestExtensionPrefs::set_extensions_disabled(bool extensions_disabled) { |
| 208 extensions_disabled_ = extensions_disabled; | 210 extensions_disabled_ = extensions_disabled; |
| 209 } | 211 } |
| 210 | 212 |
| 211 ChromeAppSorting* TestExtensionPrefs::app_sorting() { | 213 ChromeAppSorting* TestExtensionPrefs::app_sorting() { |
| 212 return static_cast<ChromeAppSorting*>( | 214 return static_cast<ChromeAppSorting*>( |
| 213 ExtensionSystem::Get(&profile_)->app_sorting()); | 215 ExtensionSystem::Get(&profile_)->app_sorting()); |
| 214 } | 216 } |
| 215 | 217 |
| 216 } // namespace extensions | 218 } // namespace extensions |
| OLD | NEW |