Update V8 to version 4.7.1.
[chromium-blink-merge.git] / components / suggestions / suggestions_store.h
blob3ad8b093b8201b8f67cc4d2287e1032a314290db
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_SUGGESTIONS_STORE_H_
6 #define COMPONENTS_SUGGESTIONS_SUGGESTIONS_STORE_H_
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/clock.h"
11 #include "components/suggestions/proto/suggestions.pb.h"
13 class PrefService;
15 namespace user_prefs {
16 class PrefRegistrySyncable;
17 } // namespace user_prefs
19 namespace suggestions {
21 // A helper class for reading and writing the suggestions to the profile's
22 // preference file.
23 class SuggestionsStore {
24 public:
25 explicit SuggestionsStore(PrefService* profile_prefs);
26 virtual ~SuggestionsStore();
28 // Loads the suggestion data from the profile's preferences into
29 // |suggestions|. If there is a problem with loading, the pref value is
30 // cleared, false is returned and |suggestions| is cleared. If successful,
31 // |suggestions| will contain the loaded data and true is returned.
32 virtual bool LoadSuggestions(SuggestionsProfile* suggestions);
34 // Stores the provided |suggestions| to the profile's preferences, using
35 // a base64 encoding of its protobuf serialization.
36 virtual bool StoreSuggestions(const SuggestionsProfile& suggestions);
38 // Clears any suggestion data from the profile's preferences.
39 virtual void ClearSuggestions();
41 // Register SuggestionsStore related prefs in the Profile prefs.
42 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
44 void SetClockForTesting(scoped_ptr<base::Clock> clock);
46 protected:
47 // Test seam. For simplicity of mock creation.
48 SuggestionsStore();
50 private:
51 // The pref service used to persist the suggestions data.
52 PrefService* pref_service_;
53 // Can be set for testing.
54 scoped_ptr<base::Clock> clock_;
56 DISALLOW_COPY_AND_ASSIGN(SuggestionsStore);
58 // Filters expired suggestions.
59 void FilterExpiredSuggestions(SuggestionsProfile* suggestions);
62 } // namespace suggestions
64 #endif // COMPONENTS_SUGGESTIONS_SUGGESTIONS_STORE_H_