This source file includes following definitions.
- CreateLocaleDefaultValue
- syncable_preferences
- SetSyncableRegistrationCallback
- RegisterBooleanPref
- RegisterIntegerPref
- RegisterDoublePref
- RegisterStringPref
- RegisterFilePathPref
- RegisterListPref
- RegisterListPref
- RegisterDictionaryPref
- RegisterDictionaryPref
- RegisterLocalizedBooleanPref
- RegisterLocalizedIntegerPref
- RegisterLocalizedDoublePref
- RegisterLocalizedStringPref
- RegisterInt64Pref
- RegisterUint64Pref
- RegisterSyncablePreference
- ForkForIncognito
#include "components/user_prefs/pref_registry_syncable.h"
#include "base/files/file_path.h"
#include "base/prefs/default_pref_store.h"
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
#include "ui/base/l10n/l10n_util.h"
namespace user_prefs {
namespace {
base::Value* CreateLocaleDefaultValue(base::Value::Type type,
int message_id) {
const std::string resource_string = l10n_util::GetStringUTF8(message_id);
DCHECK(!resource_string.empty());
switch (type) {
case base::Value::TYPE_BOOLEAN: {
if ("true" == resource_string)
return base::Value::CreateBooleanValue(true);
if ("false" == resource_string)
return base::Value::CreateBooleanValue(false);
break;
}
case base::Value::TYPE_INTEGER: {
int val;
base::StringToInt(resource_string, &val);
return base::Value::CreateIntegerValue(val);
}
case base::Value::TYPE_DOUBLE: {
double val;
base::StringToDouble(resource_string, &val);
return base::Value::CreateDoubleValue(val);
}
case base::Value::TYPE_STRING: {
return base::Value::CreateStringValue(resource_string);
}
default: {
NOTREACHED() <<
"list and dictionary types cannot have default locale values";
}
}
NOTREACHED();
return base::Value::CreateNullValue();
}
}
PrefRegistrySyncable::PrefRegistrySyncable() {
}
PrefRegistrySyncable::~PrefRegistrySyncable() {
}
const PrefRegistrySyncable::PrefToStatus&
PrefRegistrySyncable::syncable_preferences() const {
return syncable_preferences_;
}
void PrefRegistrySyncable::SetSyncableRegistrationCallback(
const SyncableRegistrationCallback& cb) {
callback_ = cb;
}
void PrefRegistrySyncable::RegisterBooleanPref(const char* path,
bool default_value,
PrefSyncStatus sync_status) {
RegisterSyncablePreference(path,
base::Value::CreateBooleanValue(default_value),
sync_status);
}
void PrefRegistrySyncable::RegisterIntegerPref(const char* path,
int default_value,
PrefSyncStatus sync_status) {
RegisterSyncablePreference(path,
base::Value::CreateIntegerValue(default_value),
sync_status);
}
void PrefRegistrySyncable::RegisterDoublePref(const char* path,
double default_value,
PrefSyncStatus sync_status) {
RegisterSyncablePreference(path,
base::Value::CreateDoubleValue(default_value),
sync_status);
}
void PrefRegistrySyncable::RegisterStringPref(const char* path,
const std::string& default_value,
PrefSyncStatus sync_status) {
RegisterSyncablePreference(path,
base::Value::CreateStringValue(default_value),
sync_status);
}
void PrefRegistrySyncable::RegisterFilePathPref(
const char* path,
const base::FilePath& default_value,
PrefSyncStatus sync_status) {
RegisterSyncablePreference(path,
base::Value::CreateStringValue(
default_value.value()),
sync_status);
}
void PrefRegistrySyncable::RegisterListPref(const char* path,
PrefSyncStatus sync_status) {
RegisterSyncablePreference(path, new base::ListValue(), sync_status);
}
void PrefRegistrySyncable::RegisterListPref(const char* path,
base::ListValue* default_value,
PrefSyncStatus sync_status) {
RegisterSyncablePreference(path, default_value, sync_status);
}
void PrefRegistrySyncable::RegisterDictionaryPref(const char* path,
PrefSyncStatus sync_status) {
RegisterSyncablePreference(path, new base::DictionaryValue(), sync_status);
}
void PrefRegistrySyncable::RegisterDictionaryPref(
const char* path,
base::DictionaryValue* default_value,
PrefSyncStatus sync_status) {
RegisterSyncablePreference(path, default_value, sync_status);
}
void PrefRegistrySyncable::RegisterLocalizedBooleanPref(
const char* path,
int locale_default_message_id,
PrefSyncStatus sync_status) {
RegisterSyncablePreference(
path,
CreateLocaleDefaultValue(base::Value::TYPE_BOOLEAN,
locale_default_message_id),
sync_status);
}
void PrefRegistrySyncable::RegisterLocalizedIntegerPref(
const char* path,
int locale_default_message_id,
PrefSyncStatus sync_status) {
RegisterSyncablePreference(
path,
CreateLocaleDefaultValue(base::Value::TYPE_INTEGER,
locale_default_message_id),
sync_status);
}
void PrefRegistrySyncable::RegisterLocalizedDoublePref(
const char* path,
int locale_default_message_id,
PrefSyncStatus sync_status) {
RegisterSyncablePreference(
path,
CreateLocaleDefaultValue(base::Value::TYPE_DOUBLE,
locale_default_message_id),
sync_status);
}
void PrefRegistrySyncable::RegisterLocalizedStringPref(
const char* path,
int locale_default_message_id,
PrefSyncStatus sync_status) {
RegisterSyncablePreference(
path,
CreateLocaleDefaultValue(base::Value::TYPE_STRING,
locale_default_message_id),
sync_status);
}
void PrefRegistrySyncable::RegisterInt64Pref(
const char* path,
int64 default_value,
PrefSyncStatus sync_status) {
RegisterSyncablePreference(
path,
base::Value::CreateStringValue(base::Int64ToString(default_value)),
sync_status);
}
void PrefRegistrySyncable::RegisterUint64Pref(
const char* path,
uint64 default_value,
PrefSyncStatus sync_status) {
RegisterSyncablePreference(
path,
base::Value::CreateStringValue(base::Uint64ToString(default_value)),
sync_status);
}
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;
if (!callback_.is_null())
callback_.Run(path, sync_status);
}
}
scoped_refptr<PrefRegistrySyncable> PrefRegistrySyncable::ForkForIncognito() {
scoped_refptr<PrefRegistrySyncable> registry(new PrefRegistrySyncable());
registry->defaults_ = defaults_;
return registry;
}
}