testing_pref_service_syncable.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (c) 2013 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. #ifndef COMPONENTS_SYNC_PREFERENCES_TESTING_PREF_SERVICE_SYNCABLE_H_
  5. #define COMPONENTS_SYNC_PREFERENCES_TESTING_PREF_SERVICE_SYNCABLE_H_
  6. #include "components/prefs/testing_pref_service.h"
  7. #include "components/sync_preferences/pref_service_syncable.h"
  8. namespace user_prefs {
  9. class PrefRegistrySyncable;
  10. }
  11. namespace sync_preferences {
  12. // Test version of PrefServiceSyncable.
  13. // This class hierarchy has a flaw: TestingPrefServiceBase is inheriting from
  14. // the first template parameter (PrefServiceSyncable in this case). This means,
  15. // all of the supported parameter types must support the same constructor
  16. // signatures -- which they don't. Hence, it's not possible to properly inject
  17. // a PrefModelAssociatorClient.
  18. // TODO(tschumann) The whole purpose of TestingPrefServiceBase is questionable
  19. // and I'd be in favor of removing it completely:
  20. // -- it hides the dependency injection of the different stores
  21. // -- just to later offer ways to manipulate specific stores.
  22. // -- if tests just dependency injects the individual stores directly, they
  23. // already have full control and won't need that indirection at all.
  24. // See PrefServiceSyncableMergeTest as an example of a cleaner way.
  25. class TestingPrefServiceSyncable
  26. : public TestingPrefServiceBase<PrefServiceSyncable,
  27. user_prefs::PrefRegistrySyncable> {
  28. public:
  29. TestingPrefServiceSyncable();
  30. TestingPrefServiceSyncable(TestingPrefStore* managed_prefs,
  31. TestingPrefStore* supervised_user_prefs,
  32. TestingPrefStore* extension_prefs,
  33. TestingPrefStore* standalone_browser_prefs,
  34. TestingPrefStore* user_prefs,
  35. TestingPrefStore* recommended_prefs,
  36. user_prefs::PrefRegistrySyncable* pref_registry,
  37. PrefNotifierImpl* pref_notifier);
  38. TestingPrefServiceSyncable(const TestingPrefServiceSyncable&) = delete;
  39. TestingPrefServiceSyncable& operator=(const TestingPrefServiceSyncable&) =
  40. delete;
  41. ~TestingPrefServiceSyncable() override;
  42. // This is provided as a convenience; on a production PrefService
  43. // you would do all registrations before constructing it, passing it
  44. // a PrefRegistry via its constructor (or via e.g. PrefServiceFactory).
  45. user_prefs::PrefRegistrySyncable* registry();
  46. };
  47. } // namespace sync_preferences
  48. template <>
  49. TestingPrefServiceBase<sync_preferences::PrefServiceSyncable,
  50. user_prefs::PrefRegistrySyncable>::
  51. TestingPrefServiceBase(TestingPrefStore* managed_prefs,
  52. TestingPrefStore* supervised_user_prefs,
  53. TestingPrefStore* extension_prefs,
  54. TestingPrefStore* standalone_browser_prefs,
  55. TestingPrefStore* user_prefs,
  56. TestingPrefStore* recommended_prefs,
  57. user_prefs::PrefRegistrySyncable* pref_registry,
  58. PrefNotifierImpl* pref_notifier);
  59. #endif // COMPONENTS_SYNC_PREFERENCES_TESTING_PREF_SERVICE_SYNCABLE_H_