testing_pref_service.cc 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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.
  4. #include "components/prefs/testing_pref_service.h"
  5. #include <memory>
  6. #include "base/bind.h"
  7. #include "base/compiler_specific.h"
  8. #include "components/prefs/default_pref_store.h"
  9. #include "components/prefs/pref_notifier_impl.h"
  10. #include "components/prefs/pref_registry_simple.h"
  11. #include "components/prefs/pref_value_store.h"
  12. #include "testing/gtest/include/gtest/gtest.h"
  13. template <>
  14. TestingPrefServiceBase<PrefService, PrefRegistry>::TestingPrefServiceBase(
  15. TestingPrefStore* managed_prefs,
  16. TestingPrefStore* supervised_user_prefs,
  17. TestingPrefStore* extension_prefs,
  18. TestingPrefStore* standalone_browser_prefs,
  19. TestingPrefStore* user_prefs,
  20. TestingPrefStore* recommended_prefs,
  21. PrefRegistry* pref_registry,
  22. PrefNotifierImpl* pref_notifier)
  23. : PrefService(
  24. std::unique_ptr<PrefNotifierImpl>(pref_notifier),
  25. std::make_unique<PrefValueStore>(managed_prefs,
  26. supervised_user_prefs,
  27. extension_prefs,
  28. standalone_browser_prefs,
  29. /*command_line_prefs=*/nullptr,
  30. user_prefs,
  31. recommended_prefs,
  32. pref_registry->defaults().get(),
  33. pref_notifier),
  34. user_prefs,
  35. standalone_browser_prefs,
  36. pref_registry,
  37. base::BindRepeating(
  38. &TestingPrefServiceBase<PrefService,
  39. PrefRegistry>::HandleReadError),
  40. false),
  41. managed_prefs_(managed_prefs),
  42. supervised_user_prefs_(supervised_user_prefs),
  43. extension_prefs_(extension_prefs),
  44. standalone_browser_prefs_(standalone_browser_prefs),
  45. user_prefs_(user_prefs),
  46. recommended_prefs_(recommended_prefs) {}
  47. TestingPrefServiceSimple::TestingPrefServiceSimple()
  48. : TestingPrefServiceBase<PrefService, PrefRegistry>(
  49. /*managed_prefs=*/new TestingPrefStore(),
  50. /*supervised_user_prefs=*/new TestingPrefStore(),
  51. /*extension_prefs=*/new TestingPrefStore(),
  52. /*standalone_browser_prefs=*/new TestingPrefStore(),
  53. /*user_prefs=*/new TestingPrefStore(),
  54. /*recommended_prefs=*/new TestingPrefStore(),
  55. new PrefRegistrySimple(),
  56. new PrefNotifierImpl()) {}
  57. TestingPrefServiceSimple::~TestingPrefServiceSimple() {
  58. }
  59. PrefRegistrySimple* TestingPrefServiceSimple::registry() {
  60. return static_cast<PrefRegistrySimple*>(DeprecatedGetPrefRegistry());
  61. }