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