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.
5 #ifndef COMPONENTS_USER_PREFS_PREF_REGISTRY_SYNCABLE_H_
6 #define COMPONENTS_USER_PREFS_PREF_REGISTRY_SYNCABLE_H_
11 #include "base/prefs/pref_registry.h"
12 #include "components/user_prefs/user_prefs_export.h"
15 class DictionaryValue;
21 namespace user_prefs {
23 // A PrefRegistry that forces users to choose whether each registered
24 // preference is syncable or not.
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 {
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.
43 SYNCABLE_PRIORITY_PREF,
47 base::Callback<void(const char* path, const PrefSyncStatus sync_status)>
48 SyncableRegistrationCallback;
50 PrefRegistrySyncable();
52 typedef std::map<std::string, PrefSyncStatus> PrefToStatus;
54 // Retrieve the set of syncable preferences currently registered.
55 const PrefToStatus& syncable_preferences() const;
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.
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
64 void SetSyncableRegistrationCallback(const SyncableRegistrationCallback& cb);
66 void RegisterBooleanPref(const char* path,
68 PrefSyncStatus sync_status);
69 void RegisterIntegerPref(const char* path,
71 PrefSyncStatus sync_status);
72 void RegisterDoublePref(const char* path,
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,
105 PrefSyncStatus sync_status);
106 void RegisterUint64Pref(const char* path,
107 uint64 default_value,
108 PrefSyncStatus sync_status);
110 // Returns a new PrefRegistrySyncable that uses the same defaults
112 scoped_refptr<PrefRegistrySyncable> ForkForIncognito();
115 virtual ~PrefRegistrySyncable();
117 void RegisterSyncablePreference(const char* path,
118 base::Value* default_value,
119 PrefSyncStatus sync_status);
121 SyncableRegistrationCallback callback_;
123 // Contains the names of all registered preferences that are syncable.
124 PrefToStatus syncable_preferences_;
126 DISALLOW_COPY_AND_ASSIGN(PrefRegistrySyncable);
129 } // namespace user_prefs
131 #endif // COMPONENTS_USER_PREFS_PREF_REGISTRY_SYNCABLE_H_