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_PREF_REGISTRY_PREF_REGISTRY_SYNCABLE_H_
6 #define COMPONENTS_PREF_REGISTRY_PREF_REGISTRY_SYNCABLE_H_
10 #include "base/callback.h"
11 #include "base/prefs/pref_registry_simple.h"
14 class DictionaryValue
;
20 // TODO(tfarina): Change this namespace to pref_registry.
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.
34 // TODO(raymes): This class only exists to support SyncableRegistrationCallback
35 // logic which is only required to support pref registration after the
36 // PrefService has been created which is only used by tests. We can remove this
37 // entire class and those tests with some work.
38 class PrefRegistrySyncable
: public PrefRegistrySimple
{
40 // Enum of flags used when registering preferences to determine if it should
41 // be synced or not. These flags are mutually exclusive, only one of them
42 // should ever be specified.
44 // Note: These must NOT overlap with PrefRegistry::PrefRegistrationFlags.
45 enum PrefRegistrationFlags
: uint32
{
46 // The pref will be synced.
47 SYNCABLE_PREF
= 1 << 0,
49 // The pref will be synced. The pref will never be encrypted and will be
50 // synced before other datatypes. Because they're never encrypted, on first
51 // sync, they can be synced down before the user is prompted for a
53 SYNCABLE_PRIORITY_PREF
= 1 << 1,
56 typedef base::Callback
<void(const std::string
& path
, uint32 flags
)>
57 SyncableRegistrationCallback
;
59 PrefRegistrySyncable();
61 // Exactly one callback can be set for the event of a syncable
62 // preference being registered. It will be fired after the
63 // registration has occurred.
65 // Calling this method after a callback has already been set will
66 // make the object forget the previous callback and use the new one
68 void SetSyncableRegistrationCallback(const SyncableRegistrationCallback
& cb
);
70 // Returns a new PrefRegistrySyncable that uses the same defaults
72 scoped_refptr
<PrefRegistrySyncable
> ForkForIncognito();
75 ~PrefRegistrySyncable() override
;
77 // PrefRegistrySimple overrides.
78 void OnPrefRegistered(const std::string
& path
,
79 base::Value
* default_value
,
80 uint32 flags
) override
;
82 SyncableRegistrationCallback callback_
;
84 DISALLOW_COPY_AND_ASSIGN(PrefRegistrySyncable
);
87 } // namespace user_prefs
89 #endif // COMPONENTS_PREF_REGISTRY_PREF_REGISTRY_SYNCABLE_H_