custom_links_store.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2018 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_NTP_TILES_CUSTOM_LINKS_STORE_H_
  5. #define COMPONENTS_NTP_TILES_CUSTOM_LINKS_STORE_H_
  6. #include <vector>
  7. #include "base/memory/raw_ptr.h"
  8. #include "components/ntp_tiles/custom_links_manager.h"
  9. class PrefService;
  10. namespace user_prefs {
  11. class PrefRegistrySyncable;
  12. } // namespace user_prefs
  13. namespace ntp_tiles {
  14. // A helper class for reading and writing custom links to the profile's
  15. // preference file. All virtual functions are for testing.
  16. class CustomLinksStore {
  17. public:
  18. explicit CustomLinksStore(PrefService* prefs);
  19. CustomLinksStore(const CustomLinksStore&) = delete;
  20. CustomLinksStore& operator=(const CustomLinksStore&) = delete;
  21. // Virtual for testing.
  22. virtual ~CustomLinksStore();
  23. // Retrieves the custom link data from the profile's preferences and returns
  24. // them as a list of |Link|s. If there is a problem with retrieval, the pref
  25. // value is cleared and an empty list is returned.
  26. // Virtual for testing.
  27. virtual std::vector<CustomLinksManager::Link> RetrieveLinks();
  28. // Stores the provided |links| to the profile's preferences.
  29. // Virtual for testing.
  30. virtual void StoreLinks(const std::vector<CustomLinksManager::Link>& links);
  31. // Clears any custom link data from the profile's preferences.
  32. // Virtual for testing.
  33. virtual void ClearLinks();
  34. // Register CustomLinksStore related prefs in the Profile prefs.
  35. static void RegisterProfilePrefs(
  36. user_prefs::PrefRegistrySyncable* user_prefs);
  37. private:
  38. // The pref service used to persist the custom link data.
  39. raw_ptr<PrefService> prefs_;
  40. };
  41. } // namespace ntp_tiles
  42. #endif // COMPONENTS_NTP_TILES_CUSTOM_LINKS_STORE_H_