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