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