• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_STORE_H_
6 #define CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_STORE_H_
7 
8 #include "base/macros.h"
9 #include "chrome/browser/search/suggestions/proto/suggestions.pb.h"
10 
11 class PrefService;
12 
13 namespace user_prefs {
14 class PrefRegistrySyncable;
15 }  // namespace user_prefs
16 
17 namespace suggestions {
18 
19 // A helper class for reading and writing the suggestions to the profile's
20 // preference file.
21 class SuggestionsStore {
22  public:
23   explicit SuggestionsStore(PrefService* profile_prefs);
24   virtual ~SuggestionsStore();
25 
26   // Loads the suggestion data from the profile's preferences into
27   // |suggestions|. If there is a problem with loading, the pref value is
28   // cleared, false is returned and |suggestions| is cleared. If successful,
29   // |suggestions| will contain the loaded data and true is returned.
30   virtual bool LoadSuggestions(SuggestionsProfile* suggestions);
31 
32   // Stores the provided |suggestions| to the profile's preferences, using
33   // a base64 encoding of its protobuf serialization.
34   virtual bool StoreSuggestions(const SuggestionsProfile& suggestions);
35 
36   // Clears any suggestion data from the profile's preferences.
37   virtual void ClearSuggestions();
38 
39   // Register SuggestionsStore related prefs in the Profile prefs.
40   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
41 
42  protected:
43   // Test seam. For simplicity of mock creation.
SuggestionsStore()44   SuggestionsStore() {}
45 
46  private:
47   // The pref service used to persist the suggestions data.
48   PrefService* pref_service_;
49 
50   DISALLOW_COPY_AND_ASSIGN(SuggestionsStore);
51 };
52 
53 }  // namespace suggestions
54 
55 #endif  // CHROME_BROWSER_SEARCH_SUGGESTIONS_SUGGESTIONS_STORE_H_
56