Commit 25fb8e7f authored by raymes's avatar raymes Committed by Commit bot

Move pref registration functions into PrefRegistrySimple

This moves all pref registration functions from PrefRegistrySyncable
into PrefRegistrySimple and changes PrefRegistrySyncable to derive
from PrefRegistrySyncable. This is done to consolidate the registration
functions in a single place that can be used by syncable and unsyncable
prefs.

BUG=476800

Review URL: https://codereview.chromium.org/1095673003

Cr-Commit-Position: refs/heads/master@{#326991}
parent 4273094d
...@@ -16,63 +16,146 @@ PrefRegistrySimple::~PrefRegistrySimple() { ...@@ -16,63 +16,146 @@ PrefRegistrySimple::~PrefRegistrySimple() {
void PrefRegistrySimple::RegisterBooleanPref(const std::string& path, void PrefRegistrySimple::RegisterBooleanPref(const std::string& path,
bool default_value) { bool default_value) {
RegisterPreference(path, RegisterPrefAndNotify(path, new base::FundamentalValue(default_value),
new base::FundamentalValue(default_value), NO_REGISTRATION_FLAGS);
NO_REGISTRATION_FLAGS);
} }
void PrefRegistrySimple::RegisterIntegerPref(const std::string& path, void PrefRegistrySimple::RegisterIntegerPref(const std::string& path,
int default_value) { int default_value) {
RegisterPreference(path, RegisterPrefAndNotify(path, new base::FundamentalValue(default_value),
new base::FundamentalValue(default_value), NO_REGISTRATION_FLAGS);
NO_REGISTRATION_FLAGS);
} }
void PrefRegistrySimple::RegisterDoublePref(const std::string& path, void PrefRegistrySimple::RegisterDoublePref(const std::string& path,
double default_value) { double default_value) {
RegisterPreference(path, RegisterPrefAndNotify(path, new base::FundamentalValue(default_value),
new base::FundamentalValue(default_value), NO_REGISTRATION_FLAGS);
NO_REGISTRATION_FLAGS);
} }
void PrefRegistrySimple::RegisterStringPref(const std::string& path, void PrefRegistrySimple::RegisterStringPref(const std::string& path,
const std::string& default_value) { const std::string& default_value) {
RegisterPreference(path, RegisterPrefAndNotify(path, new base::StringValue(default_value),
new base::StringValue(default_value), NO_REGISTRATION_FLAGS);
NO_REGISTRATION_FLAGS);
} }
void PrefRegistrySimple::RegisterFilePathPref( void PrefRegistrySimple::RegisterFilePathPref(
const std::string& path, const std::string& path,
const base::FilePath& default_value) { const base::FilePath& default_value) {
RegisterPreference(path, RegisterPrefAndNotify(path, new base::StringValue(default_value.value()),
new base::StringValue(default_value.value()), NO_REGISTRATION_FLAGS);
NO_REGISTRATION_FLAGS);
} }
void PrefRegistrySimple::RegisterListPref(const std::string& path) { void PrefRegistrySimple::RegisterListPref(const std::string& path) {
RegisterPreference(path, new base::ListValue(), NO_REGISTRATION_FLAGS); RegisterPrefAndNotify(path, new base::ListValue(), NO_REGISTRATION_FLAGS);
} }
void PrefRegistrySimple::RegisterListPref(const std::string& path, void PrefRegistrySimple::RegisterListPref(const std::string& path,
base::ListValue* default_value) { base::ListValue* default_value) {
RegisterPreference(path, default_value, NO_REGISTRATION_FLAGS); RegisterPrefAndNotify(path, default_value, NO_REGISTRATION_FLAGS);
} }
void PrefRegistrySimple::RegisterDictionaryPref(const std::string& path) { void PrefRegistrySimple::RegisterDictionaryPref(const std::string& path) {
RegisterPreference(path, new base::DictionaryValue(), NO_REGISTRATION_FLAGS); RegisterPrefAndNotify(path, new base::DictionaryValue(),
NO_REGISTRATION_FLAGS);
} }
void PrefRegistrySimple::RegisterDictionaryPref( void PrefRegistrySimple::RegisterDictionaryPref(
const std::string& path, const std::string& path,
base::DictionaryValue* default_value) { base::DictionaryValue* default_value) {
RegisterPreference(path, default_value, NO_REGISTRATION_FLAGS); RegisterPrefAndNotify(path, default_value, NO_REGISTRATION_FLAGS);
} }
void PrefRegistrySimple::RegisterInt64Pref(const std::string& path, void PrefRegistrySimple::RegisterInt64Pref(const std::string& path,
int64 default_value) { int64 default_value) {
RegisterPreference( RegisterPrefAndNotify(
path, path, new base::StringValue(base::Int64ToString(default_value)),
new base::StringValue(base::Int64ToString(default_value)),
NO_REGISTRATION_FLAGS); NO_REGISTRATION_FLAGS);
} }
void PrefRegistrySimple::RegisterUint64Pref(const std::string& path,
uint64 default_value) {
RegisterPrefAndNotify(
path, new base::StringValue(base::Uint64ToString(default_value)),
NO_REGISTRATION_FLAGS);
}
void PrefRegistrySimple::RegisterBooleanPref(const std::string& path,
bool default_value,
uint32 flags) {
RegisterPrefAndNotify(path, new base::FundamentalValue(default_value), flags);
}
void PrefRegistrySimple::RegisterIntegerPref(const std::string& path,
int default_value,
uint32 flags) {
RegisterPrefAndNotify(path, new base::FundamentalValue(default_value), flags);
}
void PrefRegistrySimple::RegisterDoublePref(const std::string& path,
double default_value,
uint32 flags) {
RegisterPrefAndNotify(path, new base::FundamentalValue(default_value), flags);
}
void PrefRegistrySimple::RegisterStringPref(const std::string& path,
const std::string& default_value,
uint32 flags) {
RegisterPrefAndNotify(path, new base::StringValue(default_value), flags);
}
void PrefRegistrySimple::RegisterFilePathPref(
const std::string& path,
const base::FilePath& default_value,
uint32 flags) {
RegisterPrefAndNotify(path, new base::StringValue(default_value.value()),
flags);
}
void PrefRegistrySimple::RegisterListPref(const std::string& path,
uint32 flags) {
RegisterPrefAndNotify(path, new base::ListValue(), flags);
}
void PrefRegistrySimple::RegisterListPref(const std::string& path,
base::ListValue* default_value,
uint32 flags) {
RegisterPrefAndNotify(path, default_value, flags);
}
void PrefRegistrySimple::RegisterDictionaryPref(const std::string& path,
uint32 flags) {
RegisterPrefAndNotify(path, new base::DictionaryValue(), flags);
}
void PrefRegistrySimple::RegisterDictionaryPref(
const std::string& path,
base::DictionaryValue* default_value,
uint32 flags) {
RegisterPrefAndNotify(path, default_value, flags);
}
void PrefRegistrySimple::RegisterInt64Pref(const std::string& path,
int64 default_value,
uint32 flags) {
RegisterPrefAndNotify(
path, new base::StringValue(base::Int64ToString(default_value)), flags);
}
void PrefRegistrySimple::RegisterUint64Pref(const std::string& path,
uint64 default_value,
uint32 flags) {
RegisterPrefAndNotify(
path, new base::StringValue(base::Uint64ToString(default_value)), flags);
}
void PrefRegistrySimple::OnPrefRegistered(const std::string& path,
base::Value* default_value,
uint32 flags) {
}
void PrefRegistrySimple::RegisterPrefAndNotify(const std::string& path,
base::Value* default_value,
uint32 flags) {
RegisterPreference(path, default_value, flags);
OnPrefRegistered(path, default_value, flags);
}
...@@ -35,10 +35,49 @@ class BASE_PREFS_EXPORT PrefRegistrySimple : public PrefRegistry { ...@@ -35,10 +35,49 @@ class BASE_PREFS_EXPORT PrefRegistrySimple : public PrefRegistry {
void RegisterDictionaryPref(const std::string& path, void RegisterDictionaryPref(const std::string& path,
base::DictionaryValue* default_value); base::DictionaryValue* default_value);
void RegisterInt64Pref(const std::string& path, int64 default_value); void RegisterInt64Pref(const std::string& path, int64 default_value);
void RegisterUint64Pref(const std::string&, uint64 default_value);
private: // Versions of registration functions that accept PrefRegistrationFlags.
// |flags| is a bitmask of PrefRegistrationFlags.
void RegisterBooleanPref(const std::string&,
bool default_value,
uint32 flags);
void RegisterIntegerPref(const std::string&, int default_value, uint32 flags);
void RegisterDoublePref(const std::string&,
double default_value,
uint32 flags);
void RegisterStringPref(const std::string&,
const std::string& default_value,
uint32 flags);
void RegisterFilePathPref(const std::string&,
const base::FilePath& default_value,
uint32 flags);
void RegisterListPref(const std::string&, uint32 flags);
void RegisterDictionaryPref(const std::string&, uint32 flags);
void RegisterListPref(const std::string&,
base::ListValue* default_value,
uint32 flags);
void RegisterDictionaryPref(const std::string&,
base::DictionaryValue* default_value,
uint32 flags);
void RegisterInt64Pref(const std::string&, int64 default_value, uint32 flags);
void RegisterUint64Pref(const std::string&,
uint64 default_value,
uint32 flags);
protected:
~PrefRegistrySimple() override; ~PrefRegistrySimple() override;
// Allows subclasses to hook into pref registration.
virtual void OnPrefRegistered(const std::string&,
base::Value* default_value,
uint32 flags);
private:
void RegisterPrefAndNotify(const std::string&,
base::Value* default_value,
uint32 flags);
DISALLOW_COPY_AND_ASSIGN(PrefRegistrySimple); DISALLOW_COPY_AND_ASSIGN(PrefRegistrySimple);
}; };
......
...@@ -58,8 +58,8 @@ PrefServiceSyncable::PrefServiceSyncable( ...@@ -58,8 +58,8 @@ PrefServiceSyncable::PrefServiceSyncable(
for (PrefRegistry::const_iterator it = pref_registry->begin(); for (PrefRegistry::const_iterator it = pref_registry->begin();
it != pref_registry->end(); ++it) { it != pref_registry->end(); ++it) {
const std::string& path = it->first; const std::string& path = it->first;
AddRegisteredSyncablePreference( AddRegisteredSyncablePreference(path,
path.c_str(), pref_registry_->GetRegistrationFlags(path)); pref_registry_->GetRegistrationFlags(path));
} }
// Watch for syncable preferences registered after this point. // Watch for syncable preferences registered after this point.
...@@ -160,14 +160,15 @@ void PrefServiceSyncable::RemoveSyncedPrefObserver( ...@@ -160,14 +160,15 @@ void PrefServiceSyncable::RemoveSyncedPrefObserver(
priority_pref_sync_associator_.RemoveSyncedPrefObserver(name, observer); priority_pref_sync_associator_.RemoveSyncedPrefObserver(name, observer);
} }
void PrefServiceSyncable::AddRegisteredSyncablePreference(const char* path, void PrefServiceSyncable::AddRegisteredSyncablePreference(
uint32 flags) { const std::string& path,
uint32 flags) {
DCHECK(FindPreference(path)); DCHECK(FindPreference(path));
if (flags & user_prefs::PrefRegistrySyncable::SYNCABLE_PREF) { if (flags & user_prefs::PrefRegistrySyncable::SYNCABLE_PREF) {
pref_sync_associator_.RegisterPref(path); pref_sync_associator_.RegisterPref(path.c_str());
} else if (flags & } else if (flags &
user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF) { user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF) {
priority_pref_sync_associator_.RegisterPref(path); priority_pref_sync_associator_.RegisterPref(path.c_str());
} }
} }
......
...@@ -89,7 +89,7 @@ class PrefServiceSyncable : public PrefService { ...@@ -89,7 +89,7 @@ class PrefServiceSyncable : public PrefService {
private: private:
friend class PrefModelAssociator; friend class PrefModelAssociator;
void AddRegisteredSyncablePreference(const char* path, uint32 flags); void AddRegisteredSyncablePreference(const std::string& path, uint32 flags);
// Invoked internally when the IsSyncing() state changes. // Invoked internally when the IsSyncing() state changes.
void OnIsSyncingChanged(); void OnIsSyncingChanged();
......
...@@ -22,93 +22,13 @@ void PrefRegistrySyncable::SetSyncableRegistrationCallback( ...@@ -22,93 +22,13 @@ void PrefRegistrySyncable::SetSyncableRegistrationCallback(
callback_ = cb; callback_ = cb;
} }
void PrefRegistrySyncable::RegisterBooleanPref(const char* path, void PrefRegistrySyncable::OnPrefRegistered(const std::string& path,
bool default_value, base::Value* default_value,
uint32 flags) {
RegisterSyncablePreference(
path, new base::FundamentalValue(default_value), flags);
}
void PrefRegistrySyncable::RegisterIntegerPref(const char* path,
int default_value,
uint32 flags) {
RegisterSyncablePreference(
path, new base::FundamentalValue(default_value), flags);
}
void PrefRegistrySyncable::RegisterDoublePref(const char* path,
double default_value,
uint32 flags) {
RegisterSyncablePreference(
path, new base::FundamentalValue(default_value), flags);
}
void PrefRegistrySyncable::RegisterStringPref(const char* path,
const std::string& default_value,
uint32 flags) {
RegisterSyncablePreference(
path, new base::StringValue(default_value), flags);
}
void PrefRegistrySyncable::RegisterFilePathPref(
const char* path,
const base::FilePath& default_value,
uint32 flags) {
RegisterSyncablePreference(
path, new base::StringValue(default_value.value()), flags);
}
void PrefRegistrySyncable::RegisterListPref(const char* path, uint32 flags) {
RegisterSyncablePreference(path, new base::ListValue(), flags);
}
void PrefRegistrySyncable::RegisterListPref(const char* path,
base::ListValue* default_value,
uint32 flags) { uint32 flags) {
RegisterSyncablePreference(path, default_value, flags);
}
void PrefRegistrySyncable::RegisterDictionaryPref(const char* path,
uint32 flags) {
RegisterSyncablePreference(path, new base::DictionaryValue(), flags);
}
void PrefRegistrySyncable::RegisterDictionaryPref(
const char* path,
base::DictionaryValue* default_value,
uint32 flags) {
RegisterSyncablePreference(path, default_value, flags);
}
void PrefRegistrySyncable::RegisterInt64Pref(
const char* path,
int64 default_value,
uint32 flags) {
RegisterSyncablePreference(
path,
new base::StringValue(base::Int64ToString(default_value)),
flags);
}
void PrefRegistrySyncable::RegisterUint64Pref(
const char* path,
uint64 default_value,
uint32 flags) {
RegisterSyncablePreference(
path,
new base::StringValue(base::Uint64ToString(default_value)),
flags);
}
void PrefRegistrySyncable::RegisterSyncablePreference(
const char* path,
base::Value* default_value,
uint32 flags) {
// Tests that |flags| does not contain both SYNCABLE_PREF and // Tests that |flags| does not contain both SYNCABLE_PREF and
// SYNCABLE_PRIORITY_PREF flags at the same time. // SYNCABLE_PRIORITY_PREF flags at the same time.
DCHECK(!(flags & PrefRegistrySyncable::SYNCABLE_PREF) || DCHECK(!(flags & PrefRegistrySyncable::SYNCABLE_PREF) ||
!(flags & PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF)); !(flags & PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF));
PrefRegistry::RegisterPreference(path, default_value, flags);
if (flags & PrefRegistrySyncable::SYNCABLE_PREF || if (flags & PrefRegistrySyncable::SYNCABLE_PREF ||
flags & PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF) { flags & PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF) {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <string> #include <string>
#include "base/callback.h" #include "base/callback.h"
#include "base/prefs/pref_registry.h" #include "base/prefs/pref_registry_simple.h"
#include "components/pref_registry/pref_registry_export.h" #include "components/pref_registry/pref_registry_export.h"
namespace base { namespace base {
...@@ -31,7 +31,12 @@ namespace user_prefs { ...@@ -31,7 +31,12 @@ namespace user_prefs {
// appropriate time before the PrefService for these preferences is // appropriate time before the PrefService for these preferences is
// constructed. See e.g. chrome/browser/prefs/browser_prefs.cc which // constructed. See e.g. chrome/browser/prefs/browser_prefs.cc which
// does this for Chrome. // does this for Chrome.
class PREF_REGISTRY_EXPORT PrefRegistrySyncable : public PrefRegistry { //
// TODO(raymes): This class only exists to support SyncableRegistrationCallback
// logic which is only required to support pref registration after the
// PrefService has been created which is only used by tests. We can remove this
// entire class and those tests with some work.
class PREF_REGISTRY_EXPORT PrefRegistrySyncable : public PrefRegistrySimple {
public: public:
// Enum of flags used when registering preferences to determine if it should // 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 // be synced or not. These flags are mutually exclusive, only one of them
...@@ -52,7 +57,7 @@ class PREF_REGISTRY_EXPORT PrefRegistrySyncable : public PrefRegistry { ...@@ -52,7 +57,7 @@ class PREF_REGISTRY_EXPORT PrefRegistrySyncable : public PrefRegistry {
SYNCABLE_PRIORITY_PREF = 1 << 2, SYNCABLE_PRIORITY_PREF = 1 << 2,
}; };
typedef base::Callback<void(const char* path, uint32 flags)> typedef base::Callback<void(const std::string& path, uint32 flags)>
SyncableRegistrationCallback; SyncableRegistrationCallback;
PrefRegistrySyncable(); PrefRegistrySyncable();
...@@ -66,33 +71,6 @@ class PREF_REGISTRY_EXPORT PrefRegistrySyncable : public PrefRegistry { ...@@ -66,33 +71,6 @@ class PREF_REGISTRY_EXPORT PrefRegistrySyncable : public PrefRegistry {
// instead. // instead.
void SetSyncableRegistrationCallback(const SyncableRegistrationCallback& cb); void SetSyncableRegistrationCallback(const SyncableRegistrationCallback& cb);
// |flags| is a bitmask of PrefRegistrationFlags.
void RegisterBooleanPref(const char* path,
bool default_value,
uint32 flags);
void RegisterIntegerPref(const char* path, int default_value, uint32 flags);
void RegisterDoublePref(const char* path,
double default_value,
uint32 flags);
void RegisterStringPref(const char* path,
const std::string& default_value,
uint32 flags);
void RegisterFilePathPref(const char* path,
const base::FilePath& default_value,
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,
uint32 flags);
void RegisterDictionaryPref(const char* path,
base::DictionaryValue* default_value,
uint32 flags);
void RegisterInt64Pref(const char* path, int64 default_value, uint32 flags);
void RegisterUint64Pref(const char* path,
uint64 default_value,
uint32 flags);
// Returns a new PrefRegistrySyncable that uses the same defaults // Returns a new PrefRegistrySyncable that uses the same defaults
// store. // store.
scoped_refptr<PrefRegistrySyncable> ForkForIncognito(); scoped_refptr<PrefRegistrySyncable> ForkForIncognito();
...@@ -100,10 +78,10 @@ class PREF_REGISTRY_EXPORT PrefRegistrySyncable : public PrefRegistry { ...@@ -100,10 +78,10 @@ class PREF_REGISTRY_EXPORT PrefRegistrySyncable : public PrefRegistry {
private: private:
~PrefRegistrySyncable() override; ~PrefRegistrySyncable() override;
// |flags| is a bitmask of PrefRegistrationFlags. // PrefRegistrySimple overrides.
void RegisterSyncablePreference(const char* path, void OnPrefRegistered(const std::string& path,
base::Value* default_value, base::Value* default_value,
uint32 flags); uint32 flags) override;
SyncableRegistrationCallback callback_; SyncableRegistrationCallback callback_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment