Apply _RELATIVE relocations ahead of others.
[chromium-blink-merge.git] / components / suggestions / blacklist_store.h
blob072e3f69c0e2b3120b847c9c3d733f0113401686
1 // Copyright 2014 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.
5 #ifndef COMPONENTS_SUGGESTIONS_BLACKLIST_STORE_H_
6 #define COMPONENTS_SUGGESTIONS_BLACKLIST_STORE_H_
8 #include "base/macros.h"
9 #include "components/suggestions/proto/suggestions.pb.h"
10 #include "url/gurl.h"
12 class PrefService;
14 namespace user_prefs {
15 class PrefRegistrySyncable;
16 } // namespace user_prefs
18 namespace suggestions {
20 // A helper class for reading, writing and modifying a small blacklist stored
21 // in the Profile preferences. It also handles SuggestionsProfile
22 // filtering based on the stored blacklist.
23 class BlacklistStore {
24 public:
25 explicit BlacklistStore(PrefService* profile_prefs);
26 virtual ~BlacklistStore();
28 // Returns true if successful or |url| was already in the blacklist.
29 virtual bool BlacklistUrl(const GURL& url);
31 // Sets |url| to the first URL from the blacklist. Returns false if the
32 // blacklist is empty.
33 virtual bool GetFirstUrlFromBlacklist(GURL* url);
35 // Removes |url| from the stored blacklist. Returns true if successful or if
36 // |url| is not in the blacklist.
37 virtual bool RemoveUrl(const GURL& url);
39 // Applies the blacklist to |suggestions|.
40 virtual void FilterSuggestions(SuggestionsProfile* suggestions);
42 // Register BlacklistStore related prefs in the Profile prefs.
43 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
45 protected:
46 // Test seam. For simplicity of mock creation.
47 BlacklistStore() {}
49 // Loads the blacklist data from the Profile preferences into
50 // |blacklist|. If there is a problem with loading, the pref value is
51 // cleared, false is returned and |blacklist| is cleared. If successful,
52 // |blacklist| will contain the loaded data and true is returned.
53 bool LoadBlacklist(SuggestionsBlacklist* blacklist);
55 // Stores the provided |blacklist| to the Profile preferences, using
56 // a base64 encoding of its protobuf serialization.
57 bool StoreBlacklist(const SuggestionsBlacklist& blacklist);
59 // Clears any blacklist data from the profile's preferences.
60 void ClearBlacklist();
62 private:
63 // The pref service used to persist the suggestions blacklist.
64 PrefService* pref_service_;
66 DISALLOW_COPY_AND_ASSIGN(BlacklistStore);
69 } // namespace suggestions
71 #endif // COMPONENTS_SUGGESTIONS_BLACKLIST_STORE_H_