| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_PREF_REGISTRY_PREF_REGISTRY_SYNCABLE_H_ | 5 #ifndef COMPONENTS_PREF_REGISTRY_PREF_REGISTRY_SYNCABLE_H_ |
| 6 #define COMPONENTS_PREF_REGISTRY_PREF_REGISTRY_SYNCABLE_H_ | 6 #define COMPONENTS_PREF_REGISTRY_PREF_REGISTRY_SYNCABLE_H_ |
| 7 | 7 |
| 8 #include <set> | |
| 9 #include <string> | 8 #include <string> |
| 10 | 9 |
| 11 #include "base/callback.h" | 10 #include "base/callback.h" |
| 12 #include "base/containers/hash_tables.h" | |
| 13 #include "base/prefs/pref_registry.h" | 11 #include "base/prefs/pref_registry.h" |
| 14 #include "components/pref_registry/pref_registry_export.h" | 12 #include "components/pref_registry/pref_registry_export.h" |
| 15 | 13 |
| 16 namespace base { | 14 namespace base { |
| 17 class DictionaryValue; | 15 class DictionaryValue; |
| 18 class FilePath; | 16 class FilePath; |
| 19 class ListValue; | 17 class ListValue; |
| 20 class Value; | 18 class Value; |
| 21 } | 19 } |
| 22 | 20 |
| 23 // TODO(tfarina): Change this namespace to pref_registry. | 21 // TODO(tfarina): Change this namespace to pref_registry. |
| 24 namespace user_prefs { | 22 namespace user_prefs { |
| 25 | 23 |
| 26 // A PrefRegistry that forces users to choose whether each registered | 24 // A PrefRegistry that forces users to choose whether each registered |
| 27 // preference is syncable or not. | 25 // preference is syncable or not. |
| 28 // | 26 // |
| 29 // Classes or components that want to register such preferences should | 27 // Classes or components that want to register such preferences should |
| 30 // define a static function named RegisterUserPrefs that takes a | 28 // define a static function named RegisterUserPrefs that takes a |
| 31 // PrefRegistrySyncable*, and the top-level application using the | 29 // PrefRegistrySyncable*, and the top-level application using the |
| 32 // class or embedding the component should call this function at an | 30 // class or embedding the component should call this function at an |
| 33 // appropriate time before the PrefService for these preferences is | 31 // appropriate time before the PrefService for these preferences is |
| 34 // constructed. See e.g. chrome/browser/prefs/browser_prefs.cc which | 32 // constructed. See e.g. chrome/browser/prefs/browser_prefs.cc which |
| 35 // does this for Chrome. | 33 // does this for Chrome. |
| 36 class PREF_REGISTRY_EXPORT PrefRegistrySyncable : public PrefRegistry { | 34 class PREF_REGISTRY_EXPORT PrefRegistrySyncable : public PrefRegistry { |
| 37 public: | 35 public: |
| 38 // Enum used when registering preferences to determine if it should | 36 // Enum of flags used when registering preferences to determine if it should |
| 39 // be synced or not. Syncable priority preferences are preferences that are | 37 // be synced or not. These flags are mutually exclusive, only one of them |
| 40 // never encrypted and are synced before other datatypes. Because they're | 38 // should ever be specified. |
| 41 // never encrypted, on first sync, they can be synced down before the user | 39 // |
| 42 // is prompted for a passphrase. | 40 // Note: These must NOT overlap with PrefRegistry::PrefRegistrationFlags. |
| 43 enum PrefSyncStatus { | 41 enum PrefRegistrationFlags { |
| 44 UNSYNCABLE_PREF, | 42 // The pref will not be synced. |
| 45 SYNCABLE_PREF, | 43 UNSYNCABLE_PREF = PrefRegistry::NO_REGISTRATION_FLAGS, |
| 46 SYNCABLE_PRIORITY_PREF, | 44 |
| 45 // The pref will be synced. |
| 46 SYNCABLE_PREF = 1 << 1, |
| 47 |
| 48 // The pref will be synced. The pref will never be encrypted and will be |
| 49 // synced before other datatypes. Because they're never encrypted, on first |
| 50 // sync, they can be synced down before the user is prompted for a |
| 51 // passphrase. |
| 52 SYNCABLE_PRIORITY_PREF = 1 << 2, |
| 47 }; | 53 }; |
| 48 | 54 |
| 49 typedef | 55 typedef base::Callback<void(const char* path, uint32 flags)> |
| 50 base::Callback<void(const char* path, const PrefSyncStatus sync_status)> | 56 SyncableRegistrationCallback; |
| 51 SyncableRegistrationCallback; | |
| 52 | 57 |
| 53 PrefRegistrySyncable(); | 58 PrefRegistrySyncable(); |
| 54 | 59 |
| 55 typedef base::hash_map<std::string, PrefSyncStatus> PrefToStatus; | |
| 56 | |
| 57 // Retrieve the set of syncable preferences currently registered. | |
| 58 const PrefToStatus& syncable_preferences() const; | |
| 59 | |
| 60 // Exactly one callback can be set for the event of a syncable | 60 // Exactly one callback can be set for the event of a syncable |
| 61 // preference being registered. It will be fired after the | 61 // preference being registered. It will be fired after the |
| 62 // registration has occurred. | 62 // registration has occurred. |
| 63 // | 63 // |
| 64 // Calling this method after a callback has already been set will | 64 // Calling this method after a callback has already been set will |
| 65 // make the object forget the previous callback and use the new one | 65 // make the object forget the previous callback and use the new one |
| 66 // instead. | 66 // instead. |
| 67 void SetSyncableRegistrationCallback(const SyncableRegistrationCallback& cb); | 67 void SetSyncableRegistrationCallback(const SyncableRegistrationCallback& cb); |
| 68 | 68 |
| 69 // |flags| is a bitmask of PrefRegistrationFlags. |
| 69 void RegisterBooleanPref(const char* path, | 70 void RegisterBooleanPref(const char* path, |
| 70 bool default_value, | 71 bool default_value, |
| 71 PrefSyncStatus sync_status); | 72 uint32 flags); |
| 72 void RegisterIntegerPref(const char* path, | 73 void RegisterIntegerPref(const char* path, int default_value, uint32 flags); |
| 73 int default_value, | |
| 74 PrefSyncStatus sync_status); | |
| 75 void RegisterDoublePref(const char* path, | 74 void RegisterDoublePref(const char* path, |
| 76 double default_value, | 75 double default_value, |
| 77 PrefSyncStatus sync_status); | 76 uint32 flags); |
| 78 void RegisterStringPref(const char* path, | 77 void RegisterStringPref(const char* path, |
| 79 const std::string& default_value, | 78 const std::string& default_value, |
| 80 PrefSyncStatus sync_status); | 79 uint32 flags); |
| 81 void RegisterFilePathPref(const char* path, | 80 void RegisterFilePathPref(const char* path, |
| 82 const base::FilePath& default_value, | 81 const base::FilePath& default_value, |
| 83 PrefSyncStatus sync_status); | 82 uint32 flags); |
| 84 void RegisterListPref(const char* path, | 83 void RegisterListPref(const char* path, uint32 flags); |
| 85 PrefSyncStatus sync_status); | 84 void RegisterDictionaryPref(const char* path, uint32 flags); |
| 86 void RegisterDictionaryPref(const char* path, | |
| 87 PrefSyncStatus sync_status); | |
| 88 void RegisterListPref(const char* path, | 85 void RegisterListPref(const char* path, |
| 89 base::ListValue* default_value, | 86 base::ListValue* default_value, |
| 90 PrefSyncStatus sync_status); | 87 uint32 flags); |
| 91 void RegisterDictionaryPref(const char* path, | 88 void RegisterDictionaryPref(const char* path, |
| 92 base::DictionaryValue* default_value, | 89 base::DictionaryValue* default_value, |
| 93 PrefSyncStatus sync_status); | 90 uint32 flags); |
| 94 void RegisterInt64Pref(const char* path, | 91 void RegisterInt64Pref(const char* path, int64 default_value, uint32 flags); |
| 95 int64 default_value, | |
| 96 PrefSyncStatus sync_status); | |
| 97 void RegisterUint64Pref(const char* path, | 92 void RegisterUint64Pref(const char* path, |
| 98 uint64 default_value, | 93 uint64 default_value, |
| 99 PrefSyncStatus sync_status); | 94 uint32 flags); |
| 100 | 95 |
| 101 // Returns a new PrefRegistrySyncable that uses the same defaults | 96 // Returns a new PrefRegistrySyncable that uses the same defaults |
| 102 // store. | 97 // store. |
| 103 scoped_refptr<PrefRegistrySyncable> ForkForIncognito(); | 98 scoped_refptr<PrefRegistrySyncable> ForkForIncognito(); |
| 104 | 99 |
| 105 private: | 100 private: |
| 106 ~PrefRegistrySyncable() override; | 101 ~PrefRegistrySyncable() override; |
| 107 | 102 |
| 103 // |flags| is a bitmask of PrefRegistrationFlags. |
| 108 void RegisterSyncablePreference(const char* path, | 104 void RegisterSyncablePreference(const char* path, |
| 109 base::Value* default_value, | 105 base::Value* default_value, |
| 110 PrefSyncStatus sync_status); | 106 uint32 flags); |
| 111 | 107 |
| 112 SyncableRegistrationCallback callback_; | 108 SyncableRegistrationCallback callback_; |
| 113 | 109 |
| 114 // Contains the names of all registered preferences that are syncable. | |
| 115 PrefToStatus syncable_preferences_; | |
| 116 | |
| 117 DISALLOW_COPY_AND_ASSIGN(PrefRegistrySyncable); | 110 DISALLOW_COPY_AND_ASSIGN(PrefRegistrySyncable); |
| 118 }; | 111 }; |
| 119 | 112 |
| 120 } // namespace user_prefs | 113 } // namespace user_prefs |
| 121 | 114 |
| 122 #endif // COMPONENTS_PREF_REGISTRY_PREF_REGISTRY_SYNCABLE_H_ | 115 #endif // COMPONENTS_PREF_REGISTRY_PREF_REGISTRY_SYNCABLE_H_ |
| OLD | NEW |