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