user_prefs.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 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_USER_PREFS_USER_PREFS_H_
  5. #define COMPONENTS_USER_PREFS_USER_PREFS_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "base/supports_user_data.h"
  8. #include "components/user_prefs/user_prefs_export.h"
  9. class PrefService;
  10. namespace user_prefs {
  11. // Components may use preferences associated with a given user. These hang off
  12. // of base::SupportsUserData and can be retrieved using UserPrefs::Get().
  13. //
  14. // It is up to the embedder to create and own the PrefService and attach it to
  15. // base::SupportsUserData using the UserPrefs::Set() function.
  16. class USER_PREFS_EXPORT UserPrefs : public base::SupportsUserData::Data {
  17. public:
  18. UserPrefs(const UserPrefs&) = delete;
  19. UserPrefs& operator=(const UserPrefs&) = delete;
  20. ~UserPrefs() override;
  21. // Retrieves the PrefService for a given context, or null if none is attached.
  22. static PrefService* Get(base::SupportsUserData* context);
  23. // Hangs the specified |prefs| off of |context|. Should be called
  24. // only once per context.
  25. static void Set(base::SupportsUserData* context, PrefService* prefs);
  26. private:
  27. explicit UserPrefs(PrefService* prefs);
  28. // Non-owning; owned by embedder.
  29. raw_ptr<PrefService> prefs_;
  30. };
  31. } // namespace user_prefs
  32. #endif // COMPONENTS_USER_PREFS_USER_PREFS_H_