test_pref_service_provider.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2019 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 ASH_SESSION_TEST_PREF_SERVICE_PROVIDER_H_
  5. #define ASH_SESSION_TEST_PREF_SERVICE_PROVIDER_H_
  6. #include <map>
  7. #include <memory>
  8. class AccountId;
  9. class PrefService;
  10. namespace ash {
  11. // Helper class to own sign-in and user pref services. This simulates production
  12. // code that these pref services outlives session controller and its client.
  13. // Some of the tests re-create user sessions to simulate re-login or create its
  14. // own SessionControllerClient. This class holds on to the pref services so that
  15. // various ash components (by way of PrefChangeRegsitrar) still holds valid
  16. // references to them when that happens.
  17. class TestPrefServiceProvider {
  18. public:
  19. TestPrefServiceProvider();
  20. TestPrefServiceProvider(const TestPrefServiceProvider&) = delete;
  21. TestPrefServiceProvider& operator=(const TestPrefServiceProvider&) = delete;
  22. ~TestPrefServiceProvider();
  23. void CreateSigninPrefsIfNeeded();
  24. void SetSigninPrefs(std::unique_ptr<PrefService> signin_prefs);
  25. PrefService* GetSigninPrefs();
  26. void CreateUserPrefs(const AccountId& account_id);
  27. void SetUserPrefs(const AccountId& account_id,
  28. std::unique_ptr<PrefService> pref_service);
  29. PrefService* GetUserPrefs(const AccountId& account_id);
  30. private:
  31. std::unique_ptr<PrefService> signin_prefs_;
  32. std::map<AccountId, std::unique_ptr<PrefService>> user_prefs_map_;
  33. };
  34. } // namespace ash
  35. #endif // ASH_SESSION_TEST_PREF_SERVICE_PROVIDER_H_