Revert of Telemetry, Mac: Use the actual keychain for performance tests. (patchset...
[chromium-blink-merge.git] / components / pref_registry / pref_registry_syncable.h
blob0fd9980936584eeb44886da4a4e41e83a6457030
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 RegisterLocalizedBooleanPref(const char* path,
94 int locale_default_message_id,
95 PrefSyncStatus sync_status);
96 void RegisterLocalizedIntegerPref(const char* path,
97 int locale_default_message_id,
98 PrefSyncStatus sync_status);
99 void RegisterLocalizedDoublePref(const char* path,
100 int locale_default_message_id,
101 PrefSyncStatus sync_status);
102 void RegisterLocalizedStringPref(const char* path,
103 int locale_default_message_id,
104 PrefSyncStatus sync_status);
105 void RegisterInt64Pref(const char* path,
106 int64 default_value,
107 PrefSyncStatus sync_status);
108 void RegisterUint64Pref(const char* path,
109 uint64 default_value,
110 PrefSyncStatus sync_status);
112 // Returns a new PrefRegistrySyncable that uses the same defaults
113 // store.
114 scoped_refptr<PrefRegistrySyncable> ForkForIncognito();
116 private:
117 ~PrefRegistrySyncable() override;
119 void RegisterSyncablePreference(const char* path,
120 base::Value* default_value,
121 PrefSyncStatus sync_status);
123 SyncableRegistrationCallback callback_;
125 // Contains the names of all registered preferences that are syncable.
126 PrefToStatus syncable_preferences_;
128 DISALLOW_COPY_AND_ASSIGN(PrefRegistrySyncable);
131 } // namespace user_prefs
133 #endif // COMPONENTS_PREF_REGISTRY_PREF_REGISTRY_SYNCABLE_H_