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