summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorraymes <raymes@chromium.org>2015-04-23 19:45:04 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-24 02:45:22 +0000
commit51b41a6f25281c3d7378eb21a69e4fcacc8d13f2 (patch)
tree09fcc70edafe59b657ff92cce912051c690c51e5
parenta960578de10cb263de359ec49bd29401f2849b24 (diff)
downloadchromium_src-51b41a6f25281c3d7378eb21a69e4fcacc8d13f2.zip
chromium_src-51b41a6f25281c3d7378eb21a69e4fcacc8d13f2.tar.gz
chromium_src-51b41a6f25281c3d7378eb21a69e4fcacc8d13f2.tar.bz2
Convert PrefSyncStatus into PrefRegistrationFlags
This converts the PrefSyncStatus enum which is passed at registration time of a syncable pref into a more general "registration flags" mechansim for prefs. PrefRegistrationFlags is an enum used in a bitmask to indicate different options which can be passed when registering a pref. Subclasses of PrefRegistry can use the first 8 bits of PrefRegistrationFlags to specify their own flags. These are used by PrefRegistrySyncable to specify whether or not the pref is syncable. In a subsequent CL we plan to add a flag to indicate whether the pref is "lossy" (see the bug linked). BUG=476800 Review URL: https://codereview.chromium.org/1096833003 Cr-Commit-Position: refs/heads/master@{#326727}
-rw-r--r--base/prefs/pref_registry.cc15
-rw-r--r--base/prefs/pref_registry.h27
-rw-r--r--base/prefs/pref_registry_simple.cc32
-rw-r--r--chrome/browser/prefs/pref_service_syncable.cc23
-rw-r--r--chrome/browser/prefs/pref_service_syncable.h4
-rw-r--r--chrome/browser/ui/prefs/prefs_tab_helper.cc11
-rw-r--r--components/pref_registry/pref_registry_syncable.cc68
-rw-r--r--components/pref_registry/pref_registry_syncable.h73
8 files changed, 141 insertions, 112 deletions
diff --git a/base/prefs/pref_registry.cc b/base/prefs/pref_registry.cc
index 69f0494..74f4b52 100644
--- a/base/prefs/pref_registry.cc
+++ b/base/prefs/pref_registry.cc
@@ -7,6 +7,7 @@
#include "base/logging.h"
#include "base/prefs/default_pref_store.h"
#include "base/prefs/pref_store.h"
+#include "base/stl_util.h"
#include "base/values.h"
PrefRegistry::PrefRegistry()
@@ -16,6 +17,13 @@ PrefRegistry::PrefRegistry()
PrefRegistry::~PrefRegistry() {
}
+uint32 PrefRegistry::GetRegistrationFlags(const std::string& pref_name) const {
+ const auto& it = registration_flags_.find(pref_name);
+ if (it == registration_flags_.end())
+ return NO_REGISTRATION_FLAGS;
+ return it->second;
+}
+
scoped_refptr<PrefStore> PrefRegistry::defaults() {
return defaults_.get();
}
@@ -41,13 +49,18 @@ void PrefRegistry::SetDefaultPrefValue(const std::string& pref_name,
}
void PrefRegistry::RegisterPreference(const std::string& path,
- base::Value* default_value) {
+ base::Value* default_value,
+ uint32 flags) {
base::Value::Type orig_type = default_value->GetType();
DCHECK(orig_type != base::Value::TYPE_NULL &&
orig_type != base::Value::TYPE_BINARY) <<
"invalid preference type: " << orig_type;
DCHECK(!defaults_->GetValue(path, NULL)) <<
"Trying to register a previously registered pref: " << path;
+ DCHECK(!ContainsKey(registration_flags_, path)) <<
+ "Trying to register a previously registered pref: " << path;
defaults_->SetDefaultValue(path, make_scoped_ptr(default_value));
+ if (flags != NO_REGISTRATION_FLAGS)
+ registration_flags_[path] = flags;
}
diff --git a/base/prefs/pref_registry.h b/base/prefs/pref_registry.h
index a500b6e..cc5804e 100644
--- a/base/prefs/pref_registry.h
+++ b/base/prefs/pref_registry.h
@@ -5,6 +5,7 @@
#ifndef BASE_PREFS_PREF_REGISTRY_H_
#define BASE_PREFS_PREF_REGISTRY_H_
+#include "base/containers/hash_tables.h"
#include "base/memory/ref_counted.h"
#include "base/prefs/base_prefs_export.h"
#include "base/prefs/pref_value_map.h"
@@ -27,10 +28,26 @@ class PrefStore;
// also work, but this is being deprecated.
class BASE_PREFS_EXPORT PrefRegistry : public base::RefCounted<PrefRegistry> {
public:
+ // Registration flags that can be specified which impact how the pref will
+ // behave or be stored. This will be passed in a bitmask when the pref is
+ // registered. Subclasses of PrefRegistry can specify their own flags. Care
+ // must be taken to ensure none of these overlap with the flags below.
+ enum PrefRegistrationFlags {
+ // No flags are specified.
+ NO_REGISTRATION_FLAGS = 0,
+
+ // The first 8 bits are reserved for subclasses of PrefRegistry to use.
+ };
+
typedef PrefValueMap::const_iterator const_iterator;
+ typedef base::hash_map<std::string, uint32> PrefRegistrationFlagsMap;
PrefRegistry();
+ // Retrieve the set of registration flags for the given preference. The return
+ // value is a bitmask of PrefRegistrationFlags.
+ uint32 GetRegistrationFlags(const std::string& pref_name) const;
+
// Gets the registered defaults.
scoped_refptr<PrefStore> defaults();
@@ -47,11 +64,17 @@ class BASE_PREFS_EXPORT PrefRegistry : public base::RefCounted<PrefRegistry> {
friend class base::RefCounted<PrefRegistry>;
virtual ~PrefRegistry();
- // Used by subclasses to register a default value for a preference.
- void RegisterPreference(const std::string& path, base::Value* default_value);
+ // Used by subclasses to register a default value and registration flags for
+ // a preference. |flags| is a bitmask of |PrefRegistrationFlags|.
+ void RegisterPreference(const std::string& path,
+ base::Value* default_value,
+ uint32 flags);
scoped_refptr<DefaultPrefStore> defaults_;
+ // A map of pref name to a bitmask of PrefRegistrationFlags.
+ PrefRegistrationFlagsMap registration_flags_;
+
private:
DISALLOW_COPY_AND_ASSIGN(PrefRegistry);
};
diff --git a/base/prefs/pref_registry_simple.cc b/base/prefs/pref_registry_simple.cc
index fa679dc..1719419 100644
--- a/base/prefs/pref_registry_simple.cc
+++ b/base/prefs/pref_registry_simple.cc
@@ -16,51 +16,63 @@ PrefRegistrySimple::~PrefRegistrySimple() {
void PrefRegistrySimple::RegisterBooleanPref(const std::string& path,
bool default_value) {
- RegisterPreference(path, new base::FundamentalValue(default_value));
+ RegisterPreference(path,
+ new base::FundamentalValue(default_value),
+ NO_REGISTRATION_FLAGS);
}
void PrefRegistrySimple::RegisterIntegerPref(const std::string& path,
int default_value) {
- RegisterPreference(path, new base::FundamentalValue(default_value));
+ RegisterPreference(path,
+ new base::FundamentalValue(default_value),
+ NO_REGISTRATION_FLAGS);
}
void PrefRegistrySimple::RegisterDoublePref(const std::string& path,
double default_value) {
- RegisterPreference(path, new base::FundamentalValue(default_value));
+ RegisterPreference(path,
+ new base::FundamentalValue(default_value),
+ NO_REGISTRATION_FLAGS);
}
void PrefRegistrySimple::RegisterStringPref(const std::string& path,
const std::string& default_value) {
- RegisterPreference(path, new base::StringValue(default_value));
+ RegisterPreference(path,
+ new base::StringValue(default_value),
+ NO_REGISTRATION_FLAGS);
}
void PrefRegistrySimple::RegisterFilePathPref(
const std::string& path,
const base::FilePath& default_value) {
- RegisterPreference(path, new base::StringValue(default_value.value()));
+ RegisterPreference(path,
+ new base::StringValue(default_value.value()),
+ NO_REGISTRATION_FLAGS);
}
void PrefRegistrySimple::RegisterListPref(const std::string& path) {
- RegisterPreference(path, new base::ListValue());
+ RegisterPreference(path, new base::ListValue(), NO_REGISTRATION_FLAGS);
}
void PrefRegistrySimple::RegisterListPref(const std::string& path,
base::ListValue* default_value) {
- RegisterPreference(path, default_value);
+ RegisterPreference(path, default_value, NO_REGISTRATION_FLAGS);
}
void PrefRegistrySimple::RegisterDictionaryPref(const std::string& path) {
- RegisterPreference(path, new base::DictionaryValue());
+ RegisterPreference(path, new base::DictionaryValue(), NO_REGISTRATION_FLAGS);
}
void PrefRegistrySimple::RegisterDictionaryPref(
const std::string& path,
base::DictionaryValue* default_value) {
- RegisterPreference(path, default_value);
+ RegisterPreference(path, default_value, NO_REGISTRATION_FLAGS);
}
void PrefRegistrySimple::RegisterInt64Pref(const std::string& path,
int64 default_value) {
RegisterPreference(
- path, new base::StringValue(base::Int64ToString(default_value)));
+ path,
+ new base::StringValue(base::Int64ToString(default_value)),
+ NO_REGISTRATION_FLAGS);
}
diff --git a/chrome/browser/prefs/pref_service_syncable.cc b/chrome/browser/prefs/pref_service_syncable.cc
index 0a8613c..856d46c 100644
--- a/chrome/browser/prefs/pref_service_syncable.cc
+++ b/chrome/browser/prefs/pref_service_syncable.cc
@@ -55,13 +55,11 @@ PrefServiceSyncable::PrefServiceSyncable(
base::Unretained(this)));
// Add already-registered syncable preferences to PrefModelAssociator.
- const user_prefs::PrefRegistrySyncable::PrefToStatus& syncable_preferences =
- pref_registry->syncable_preferences();
- for (user_prefs::PrefRegistrySyncable::PrefToStatus::const_iterator it =
- syncable_preferences.begin();
- it != syncable_preferences.end();
- ++it) {
- AddRegisteredSyncablePreference(it->first.c_str(), it->second);
+ for (PrefRegistry::const_iterator it = pref_registry->begin();
+ it != pref_registry->end(); ++it) {
+ const std::string& path = it->first;
+ AddRegisteredSyncablePreference(
+ path.c_str(), pref_registry_->GetRegistrationFlags(path));
}
// Watch for syncable preferences registered after this point.
@@ -162,17 +160,14 @@ void PrefServiceSyncable::RemoveSyncedPrefObserver(
priority_pref_sync_associator_.RemoveSyncedPrefObserver(name, observer);
}
-void PrefServiceSyncable::AddRegisteredSyncablePreference(
- const char* path,
- const user_prefs::PrefRegistrySyncable::PrefSyncStatus sync_status) {
+void PrefServiceSyncable::AddRegisteredSyncablePreference(const char* path,
+ uint32 flags) {
DCHECK(FindPreference(path));
- if (sync_status == user_prefs::PrefRegistrySyncable::SYNCABLE_PREF) {
+ if (flags & user_prefs::PrefRegistrySyncable::SYNCABLE_PREF) {
pref_sync_associator_.RegisterPref(path);
- } else if (sync_status ==
+ } else if (flags &
user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF) {
priority_pref_sync_associator_.RegisterPref(path);
- } else {
- NOTREACHED() << "invalid sync_status: " << sync_status;
}
}
diff --git a/chrome/browser/prefs/pref_service_syncable.h b/chrome/browser/prefs/pref_service_syncable.h
index c1b4960..37d1900 100644
--- a/chrome/browser/prefs/pref_service_syncable.h
+++ b/chrome/browser/prefs/pref_service_syncable.h
@@ -89,9 +89,7 @@ class PrefServiceSyncable : public PrefService {
private:
friend class PrefModelAssociator;
- void AddRegisteredSyncablePreference(
- const char* path,
- const user_prefs::PrefRegistrySyncable::PrefSyncStatus sync_status);
+ void AddRegisteredSyncablePreference(const char* path, uint32 flags);
// Invoked internally when the IsSyncing() state changes.
void OnIsSyncingChanged();
diff --git a/chrome/browser/ui/prefs/prefs_tab_helper.cc b/chrome/browser/ui/prefs/prefs_tab_helper.cc
index 68dc761..e32e65f 100644
--- a/chrome/browser/ui/prefs/prefs_tab_helper.cc
+++ b/chrome/browser/ui/prefs/prefs_tab_helper.cc
@@ -325,16 +325,15 @@ void OverrideFontFamily(WebPreferences* prefs,
(*map)[script] = base::UTF8ToUTF16(pref_value);
}
-void RegisterLocalizedFontPref(
- user_prefs::PrefRegistrySyncable* registry,
- const char* path,
- int default_message_id,
- user_prefs::PrefRegistrySyncable::PrefSyncStatus status) {
+void RegisterLocalizedFontPref(user_prefs::PrefRegistrySyncable* registry,
+ const char* path,
+ int default_message_id,
+ uint32 flags) {
int val = 0;
bool success = base::StringToInt(l10n_util::GetStringUTF8(
default_message_id), &val);
DCHECK(success);
- registry->RegisterIntegerPref(path, val, status);
+ registry->RegisterIntegerPref(path, val, flags);
}
} // namespace
diff --git a/components/pref_registry/pref_registry_syncable.cc b/components/pref_registry/pref_registry_syncable.cc
index 49d0020..12b2bc6 100644
--- a/components/pref_registry/pref_registry_syncable.cc
+++ b/components/pref_registry/pref_registry_syncable.cc
@@ -17,11 +17,6 @@ PrefRegistrySyncable::PrefRegistrySyncable() {
PrefRegistrySyncable::~PrefRegistrySyncable() {
}
-const PrefRegistrySyncable::PrefToStatus&
-PrefRegistrySyncable::syncable_preferences() const {
- return syncable_preferences_;
-}
-
void PrefRegistrySyncable::SetSyncableRegistrationCallback(
const SyncableRegistrationCallback& cb) {
callback_ = cb;
@@ -29,95 +24,96 @@ void PrefRegistrySyncable::SetSyncableRegistrationCallback(
void PrefRegistrySyncable::RegisterBooleanPref(const char* path,
bool default_value,
- PrefSyncStatus sync_status) {
+ uint32 flags) {
RegisterSyncablePreference(
- path, new base::FundamentalValue(default_value), sync_status);
+ path, new base::FundamentalValue(default_value), flags);
}
void PrefRegistrySyncable::RegisterIntegerPref(const char* path,
int default_value,
- PrefSyncStatus sync_status) {
+ uint32 flags) {
RegisterSyncablePreference(
- path, new base::FundamentalValue(default_value), sync_status);
+ path, new base::FundamentalValue(default_value), flags);
}
void PrefRegistrySyncable::RegisterDoublePref(const char* path,
double default_value,
- PrefSyncStatus sync_status) {
+ uint32 flags) {
RegisterSyncablePreference(
- path, new base::FundamentalValue(default_value), sync_status);
+ path, new base::FundamentalValue(default_value), flags);
}
void PrefRegistrySyncable::RegisterStringPref(const char* path,
const std::string& default_value,
- PrefSyncStatus sync_status) {
+ uint32 flags) {
RegisterSyncablePreference(
- path, new base::StringValue(default_value), sync_status);
+ path, new base::StringValue(default_value), flags);
}
void PrefRegistrySyncable::RegisterFilePathPref(
const char* path,
const base::FilePath& default_value,
- PrefSyncStatus sync_status) {
+ uint32 flags) {
RegisterSyncablePreference(
- path, new base::StringValue(default_value.value()), sync_status);
+ path, new base::StringValue(default_value.value()), flags);
}
-void PrefRegistrySyncable::RegisterListPref(const char* path,
- PrefSyncStatus sync_status) {
- RegisterSyncablePreference(path, new base::ListValue(), sync_status);
+void PrefRegistrySyncable::RegisterListPref(const char* path, uint32 flags) {
+ RegisterSyncablePreference(path, new base::ListValue(), flags);
}
void PrefRegistrySyncable::RegisterListPref(const char* path,
base::ListValue* default_value,
- PrefSyncStatus sync_status) {
- RegisterSyncablePreference(path, default_value, sync_status);
+ uint32 flags) {
+ RegisterSyncablePreference(path, default_value, flags);
}
void PrefRegistrySyncable::RegisterDictionaryPref(const char* path,
- PrefSyncStatus sync_status) {
- RegisterSyncablePreference(path, new base::DictionaryValue(), sync_status);
+ uint32 flags) {
+ RegisterSyncablePreference(path, new base::DictionaryValue(), flags);
}
void PrefRegistrySyncable::RegisterDictionaryPref(
const char* path,
base::DictionaryValue* default_value,
- PrefSyncStatus sync_status) {
- RegisterSyncablePreference(path, default_value, sync_status);
+ uint32 flags) {
+ RegisterSyncablePreference(path, default_value, flags);
}
void PrefRegistrySyncable::RegisterInt64Pref(
const char* path,
int64 default_value,
- PrefSyncStatus sync_status) {
+ uint32 flags) {
RegisterSyncablePreference(
path,
new base::StringValue(base::Int64ToString(default_value)),
- sync_status);
+ flags);
}
void PrefRegistrySyncable::RegisterUint64Pref(
const char* path,
uint64 default_value,
- PrefSyncStatus sync_status) {
+ uint32 flags) {
RegisterSyncablePreference(
path,
new base::StringValue(base::Uint64ToString(default_value)),
- sync_status);
+ flags);
}
void PrefRegistrySyncable::RegisterSyncablePreference(
const char* path,
base::Value* default_value,
- PrefSyncStatus sync_status) {
- PrefRegistry::RegisterPreference(path, default_value);
-
- if (sync_status == PrefRegistrySyncable::SYNCABLE_PREF ||
- sync_status == PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF) {
- syncable_preferences_[path] = sync_status;
-
+ uint32 flags) {
+ // Tests that |flags| does not contain both SYNCABLE_PREF and
+ // SYNCABLE_PRIORITY_PREF flags at the same time.
+ DCHECK(!(flags & PrefRegistrySyncable::SYNCABLE_PREF) ||
+ !(flags & PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF));
+ PrefRegistry::RegisterPreference(path, default_value, flags);
+
+ if (flags & PrefRegistrySyncable::SYNCABLE_PREF ||
+ flags & PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF) {
if (!callback_.is_null())
- callback_.Run(path, sync_status);
+ callback_.Run(path, flags);
}
}
diff --git a/components/pref_registry/pref_registry_syncable.h b/components/pref_registry/pref_registry_syncable.h
index 561101c..7ce3718 100644
--- a/components/pref_registry/pref_registry_syncable.h
+++ b/components/pref_registry/pref_registry_syncable.h
@@ -5,11 +5,9 @@
#ifndef COMPONENTS_PREF_REGISTRY_PREF_REGISTRY_SYNCABLE_H_
#define COMPONENTS_PREF_REGISTRY_PREF_REGISTRY_SYNCABLE_H_
-#include <set>
#include <string>
#include "base/callback.h"
-#include "base/containers/hash_tables.h"
#include "base/prefs/pref_registry.h"
#include "components/pref_registry/pref_registry_export.h"
@@ -35,28 +33,30 @@ namespace user_prefs {
// does this for Chrome.
class PREF_REGISTRY_EXPORT PrefRegistrySyncable : public PrefRegistry {
public:
- // Enum used when registering preferences to determine if it should
- // be synced or not. Syncable priority preferences are preferences that are
- // never encrypted and are synced before other datatypes. Because they're
- // never encrypted, on first sync, they can be synced down before the user
- // is prompted for a passphrase.
- enum PrefSyncStatus {
- UNSYNCABLE_PREF,
- SYNCABLE_PREF,
- SYNCABLE_PRIORITY_PREF,
+ // Enum of flags used when registering preferences to determine if it should
+ // be synced or not. These flags are mutually exclusive, only one of them
+ // should ever be specified.
+ //
+ // Note: These must NOT overlap with PrefRegistry::PrefRegistrationFlags.
+ enum PrefRegistrationFlags {
+ // The pref will not be synced.
+ UNSYNCABLE_PREF = PrefRegistry::NO_REGISTRATION_FLAGS,
+
+ // The pref will be synced.
+ SYNCABLE_PREF = 1 << 1,
+
+ // The pref will be synced. The pref will never be encrypted and will be
+ // synced before other datatypes. Because they're never encrypted, on first
+ // sync, they can be synced down before the user is prompted for a
+ // passphrase.
+ SYNCABLE_PRIORITY_PREF = 1 << 2,
};
- typedef
- base::Callback<void(const char* path, const PrefSyncStatus sync_status)>
- SyncableRegistrationCallback;
+ typedef base::Callback<void(const char* path, uint32 flags)>
+ SyncableRegistrationCallback;
PrefRegistrySyncable();
- typedef base::hash_map<std::string, PrefSyncStatus> PrefToStatus;
-
- // Retrieve the set of syncable preferences currently registered.
- const PrefToStatus& syncable_preferences() const;
-
// Exactly one callback can be set for the event of a syncable
// preference being registered. It will be fired after the
// registration has occurred.
@@ -66,37 +66,32 @@ class PREF_REGISTRY_EXPORT PrefRegistrySyncable : public PrefRegistry {
// instead.
void SetSyncableRegistrationCallback(const SyncableRegistrationCallback& cb);
+ // |flags| is a bitmask of PrefRegistrationFlags.
void RegisterBooleanPref(const char* path,
bool default_value,
- PrefSyncStatus sync_status);
- void RegisterIntegerPref(const char* path,
- int default_value,
- PrefSyncStatus sync_status);
+ uint32 flags);
+ void RegisterIntegerPref(const char* path, int default_value, uint32 flags);
void RegisterDoublePref(const char* path,
double default_value,
- PrefSyncStatus sync_status);
+ uint32 flags);
void RegisterStringPref(const char* path,
const std::string& default_value,
- PrefSyncStatus sync_status);
+ uint32 flags);
void RegisterFilePathPref(const char* path,
const base::FilePath& default_value,
- PrefSyncStatus sync_status);
- void RegisterListPref(const char* path,
- PrefSyncStatus sync_status);
- void RegisterDictionaryPref(const char* path,
- PrefSyncStatus sync_status);
+ uint32 flags);
+ void RegisterListPref(const char* path, uint32 flags);
+ void RegisterDictionaryPref(const char* path, uint32 flags);
void RegisterListPref(const char* path,
base::ListValue* default_value,
- PrefSyncStatus sync_status);
+ uint32 flags);
void RegisterDictionaryPref(const char* path,
base::DictionaryValue* default_value,
- PrefSyncStatus sync_status);
- void RegisterInt64Pref(const char* path,
- int64 default_value,
- PrefSyncStatus sync_status);
+ uint32 flags);
+ void RegisterInt64Pref(const char* path, int64 default_value, uint32 flags);
void RegisterUint64Pref(const char* path,
uint64 default_value,
- PrefSyncStatus sync_status);
+ uint32 flags);
// Returns a new PrefRegistrySyncable that uses the same defaults
// store.
@@ -105,15 +100,13 @@ class PREF_REGISTRY_EXPORT PrefRegistrySyncable : public PrefRegistry {
private:
~PrefRegistrySyncable() override;
+ // |flags| is a bitmask of PrefRegistrationFlags.
void RegisterSyncablePreference(const char* path,
base::Value* default_value,
- PrefSyncStatus sync_status);
+ uint32 flags);
SyncableRegistrationCallback callback_;
- // Contains the names of all registered preferences that are syncable.
- PrefToStatus syncable_preferences_;
-
DISALLOW_COPY_AND_ASSIGN(PrefRegistrySyncable);
};