- add sources.
[platform/framework/web/crosswalk.git] / src / components / user_prefs / pref_registry_syncable.h
1 // Copyright (c) 2012 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_USER_PREFS_PREF_REGISTRY_SYNCABLE_H_
6 #define COMPONENTS_USER_PREFS_PREF_REGISTRY_SYNCABLE_H_
7
8 #include <set>
9 #include <string>
10
11 #include "base/prefs/pref_registry.h"
12 #include "components/user_prefs/user_prefs_export.h"
13
14 namespace base {
15 class DictionaryValue;
16 class FilePath;
17 class ListValue;
18 class Value;
19 }
20
21 namespace user_prefs {
22
23 // A PrefRegistry that forces users to choose whether each registered
24 // preference is syncable or not.
25 //
26 // Classes or components that want to register such preferences should
27 // define a static function named RegisterUserPrefs that takes a
28 // PrefRegistrySyncable*, and the top-level application using the
29 // class or embedding the component should call this function at an
30 // appropriate time before the PrefService for these preferences is
31 // constructed. See e.g. chrome/browser/prefs/browser_prefs.cc which
32 // does this for Chrome.
33 class USER_PREFS_EXPORT PrefRegistrySyncable : public PrefRegistry {
34  public:
35   // Enum used when registering preferences to determine if it should
36   // be synced or not. Syncable priority preferences are preferences that are
37   // never encrypted and are synced before other datatypes. Because they're
38   // never encrypted, on first sync, they can be synced down before the user
39   // is prompted for a passphrase.
40   enum PrefSyncStatus {
41     UNSYNCABLE_PREF,
42     SYNCABLE_PREF,
43     SYNCABLE_PRIORITY_PREF,
44   };
45
46   typedef
47       base::Callback<void(const char* path, const PrefSyncStatus sync_status)>
48           SyncableRegistrationCallback;
49
50   PrefRegistrySyncable();
51
52   typedef std::map<std::string, PrefSyncStatus> PrefToStatus;
53
54   // Retrieve the set of syncable preferences currently registered.
55   const PrefToStatus& syncable_preferences() const;
56
57   // Exactly one callback can be set for the event of a syncable
58   // preference being registered. It will be fired after the
59   // registration has occurred.
60   //
61   // Calling this method after a callback has already been set will
62   // make the object forget the previous callback and use the new one
63   // instead.
64   void SetSyncableRegistrationCallback(const SyncableRegistrationCallback& cb);
65
66   void RegisterBooleanPref(const char* path,
67                            bool default_value,
68                            PrefSyncStatus sync_status);
69   void RegisterIntegerPref(const char* path,
70                            int default_value,
71                            PrefSyncStatus sync_status);
72   void RegisterDoublePref(const char* path,
73                           double default_value,
74                           PrefSyncStatus sync_status);
75   void RegisterStringPref(const char* path,
76                           const std::string& default_value,
77                           PrefSyncStatus sync_status);
78   void RegisterFilePathPref(const char* path,
79                             const base::FilePath& default_value,
80                             PrefSyncStatus sync_status);
81   void RegisterListPref(const char* path,
82                         PrefSyncStatus sync_status);
83   void RegisterDictionaryPref(const char* path,
84                               PrefSyncStatus sync_status);
85   void RegisterListPref(const char* path,
86                         base::ListValue* default_value,
87                         PrefSyncStatus sync_status);
88   void RegisterDictionaryPref(const char* path,
89                               base::DictionaryValue* default_value,
90                               PrefSyncStatus sync_status);
91   void RegisterLocalizedBooleanPref(const char* path,
92                                     int locale_default_message_id,
93                                     PrefSyncStatus sync_status);
94   void RegisterLocalizedIntegerPref(const char* path,
95                                     int locale_default_message_id,
96                                     PrefSyncStatus sync_status);
97   void RegisterLocalizedDoublePref(const char* path,
98                                    int locale_default_message_id,
99                                    PrefSyncStatus sync_status);
100   void RegisterLocalizedStringPref(const char* path,
101                                    int locale_default_message_id,
102                                    PrefSyncStatus sync_status);
103   void RegisterInt64Pref(const char* path,
104                          int64 default_value,
105                          PrefSyncStatus sync_status);
106   void RegisterUint64Pref(const char* path,
107                           uint64 default_value,
108                           PrefSyncStatus sync_status);
109
110   // Returns a new PrefRegistrySyncable that uses the same defaults
111   // store.
112   scoped_refptr<PrefRegistrySyncable> ForkForIncognito();
113
114  private:
115   virtual ~PrefRegistrySyncable();
116
117   void RegisterSyncablePreference(const char* path,
118                                   base::Value* default_value,
119                                   PrefSyncStatus sync_status);
120
121   SyncableRegistrationCallback callback_;
122
123   // Contains the names of all registered preferences that are syncable.
124   PrefToStatus syncable_preferences_;
125
126   DISALLOW_COPY_AND_ASSIGN(PrefRegistrySyncable);
127 };
128
129 }  // namespace user_prefs
130
131 #endif  // COMPONENTS_USER_PREFS_PREF_REGISTRY_SYNCABLE_H_