| Index: chrome/browser/prefs/pref_service.cc
|
| diff --git a/chrome/browser/prefs/pref_service.cc b/chrome/browser/prefs/pref_service.cc
|
| index 8ea2d2a4b1997736dab09a7a440877ba16c05e14..5096d1d73cfcc8bee6fc8da7e0f69ea919a37fc0 100644
|
| --- a/chrome/browser/prefs/pref_service.cc
|
| +++ b/chrome/browser/prefs/pref_service.cc
|
| @@ -18,11 +18,13 @@
|
| #include "base/string_util.h"
|
| #include "base/value_conversions.h"
|
| #include "build/build_config.h"
|
| +#include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/extensions/extension_pref_store.h"
|
| #include "chrome/browser/policy/configuration_policy_pref_store.h"
|
| #include "chrome/browser/prefs/command_line_pref_store.h"
|
| #include "chrome/browser/prefs/default_pref_store.h"
|
| #include "chrome/browser/prefs/overlay_persistent_pref_store.h"
|
| +#include "chrome/browser/prefs/pref_model_associator.h"
|
| #include "chrome/browser/prefs/pref_notifier_impl.h"
|
| #include "chrome/browser/prefs/pref_value_store.h"
|
| #include "chrome/browser/ui/profile_error_dialog.h"
|
| @@ -149,6 +151,7 @@ PrefService::PrefService(PrefStore* managed_platform_prefs,
|
| : user_pref_store_(user_prefs),
|
| default_store_(default_store),
|
| delegate_(delegate) {
|
| + pref_sync_associator_.reset(new PrefModelAssociator(this));
|
| pref_notifier_.reset(new PrefNotifierImpl(this));
|
| pref_value_store_.reset(
|
| new PrefValueStore(managed_platform_prefs,
|
| @@ -159,6 +162,7 @@ PrefService::PrefService(PrefStore* managed_platform_prefs,
|
| recommended_platform_prefs,
|
| recommended_cloud_prefs,
|
| default_store,
|
| + pref_sync_associator_.get(),
|
| pref_notifier_.get()));
|
| InitFromStorage();
|
| }
|
| @@ -169,6 +173,7 @@ PrefService::PrefService(const PrefService& original,
|
| new OverlayPersistentPrefStore(original.user_pref_store_.get())),
|
| default_store_(original.default_store_.get()),
|
| delegate_(NULL) {
|
| + // Incognito mode doesn't sync, so no need to create PrefModelAssociator.
|
| pref_notifier_.reset(new PrefNotifierImpl(this));
|
| pref_value_store_.reset(original.pref_value_store_->CloneAndSpecialize(
|
| NULL, // managed_platform_prefs
|
| @@ -179,6 +184,7 @@ PrefService::PrefService(const PrefService& original,
|
| NULL, // recommended_platform_prefs
|
| NULL, // recommended_cloud_prefs
|
| default_store_.get(),
|
| + NULL, // pref_sync_associator_
|
| pref_notifier_.get()));
|
| InitFromStorage();
|
| }
|
| @@ -192,6 +198,9 @@ PrefService::~PrefService() {
|
| pref_value_store_.reset();
|
| user_pref_store_ = NULL;
|
| default_store_ = NULL;
|
| + if (pref_sync_associator_.get())
|
| + pref_sync_associator_->DisassociateModels();
|
| + pref_sync_associator_.reset();
|
| }
|
|
|
| void PrefService::OnPrefsRead(PersistentPrefStore::PrefReadError error,
|
| @@ -258,72 +267,286 @@ void PrefService::CommitPendingWrite() {
|
| user_pref_store_->CommitPendingWrite();
|
| }
|
|
|
| +namespace {
|
| +
|
| +// If there's no g_browser_process or no local state, return true (for testing).
|
| +bool IsLocalStatePrefService(PrefService* prefs){
|
| + return (!g_browser_process ||
|
| + !g_browser_process->local_state() ||
|
| + g_browser_process->local_state() == prefs);
|
| +}
|
| +
|
| +// If there's no g_browser_process, return true (for testing).
|
| +bool IsProfilePrefService(PrefService* prefs){
|
| + // TODO(zea): uncomment this once all preferences are only ever registered
|
| + // with either the local_state's pref service or the profile's pref service.
|
| + // return (!g_browser_process || g_browser_process->local_state() != prefs);
|
| + return true;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +
|
| +// Local State prefs.
|
| void PrefService::RegisterBooleanPref(const char* path,
|
| bool default_value) {
|
| - RegisterPreference(path, Value::CreateBooleanValue(default_value));
|
| + // If this fails, the pref service in use is a profile pref service, so the
|
| + // sync status must be provided (see profile pref registration calls below).
|
| + DCHECK(IsLocalStatePrefService(this));
|
| + RegisterPreference(path,
|
| + Value::CreateBooleanValue(default_value),
|
| + UNSYNCABLE_PREF);
|
| }
|
|
|
| void PrefService::RegisterIntegerPref(const char* path, int default_value) {
|
| - RegisterPreference(path, Value::CreateIntegerValue(default_value));
|
| + // If this fails, the pref service in use is a profile pref service, so the
|
| + // sync status must be provided (see profile pref registration calls below).
|
| + DCHECK(IsLocalStatePrefService(this));
|
| + RegisterPreference(path,
|
| + Value::CreateIntegerValue(default_value),
|
| + UNSYNCABLE_PREF);
|
| }
|
|
|
| void PrefService::RegisterDoublePref(const char* path, double default_value) {
|
| - RegisterPreference(path, Value::CreateDoubleValue(default_value));
|
| + // If this fails, the pref service in use is a profile pref service, so the
|
| + // sync status must be provided (see profile pref registration calls below).
|
| + DCHECK(IsLocalStatePrefService(this));
|
| + RegisterPreference(path,
|
| + Value::CreateDoubleValue(default_value),
|
| + UNSYNCABLE_PREF);
|
| }
|
|
|
| void PrefService::RegisterStringPref(const char* path,
|
| const std::string& default_value) {
|
| - RegisterPreference(path, Value::CreateStringValue(default_value));
|
| + // If this fails, the pref service in use is a profile pref service, so the
|
| + // sync status must be provided (see profile pref registration calls below).
|
| + DCHECK(IsLocalStatePrefService(this));
|
| + RegisterPreference(path,
|
| + Value::CreateStringValue(default_value),
|
| + UNSYNCABLE_PREF);
|
| }
|
|
|
| void PrefService::RegisterFilePathPref(const char* path,
|
| const FilePath& default_value) {
|
| - RegisterPreference(path, Value::CreateStringValue(default_value.value()));
|
| + // If this fails, the pref service in use is a profile pref service, so the
|
| + // sync status must be provided (see profile pref registration calls below).
|
| + DCHECK(IsLocalStatePrefService(this));
|
| + RegisterPreference(path,
|
| + Value::CreateStringValue(default_value.value()),
|
| + UNSYNCABLE_PREF);
|
| }
|
|
|
| void PrefService::RegisterListPref(const char* path) {
|
| - RegisterPreference(path, new ListValue());
|
| + // If this fails, the pref service in use is a profile pref service, so the
|
| + // sync status must be provided (see profile pref registration calls below).
|
| + DCHECK(IsLocalStatePrefService(this));
|
| + RegisterPreference(path,
|
| + new ListValue(),
|
| + UNSYNCABLE_PREF);
|
| }
|
|
|
| void PrefService::RegisterListPref(const char* path, ListValue* default_value) {
|
| - RegisterPreference(path, default_value);
|
| + // If this fails, the pref service in use is a profile pref service, so the
|
| + // sync status must be provided (see profile pref registration calls below).
|
| + DCHECK(IsLocalStatePrefService(this));
|
| + RegisterPreference(path,
|
| + default_value,
|
| + UNSYNCABLE_PREF);
|
| }
|
|
|
| void PrefService::RegisterDictionaryPref(const char* path) {
|
| - RegisterPreference(path, new DictionaryValue());
|
| + // If this fails, the pref service in use is a profile pref service, so the
|
| + // sync status must be provided (see profile pref registration calls below).
|
| + DCHECK(IsLocalStatePrefService(this));
|
| + RegisterPreference(path,
|
| + new DictionaryValue(),
|
| + UNSYNCABLE_PREF);
|
| }
|
|
|
| void PrefService::RegisterDictionaryPref(const char* path,
|
| DictionaryValue* default_value) {
|
| - RegisterPreference(path, default_value);
|
| + // If this fails, the pref service in use is a profile pref service, so the
|
| + // sync status must be provided (see profile pref registration calls below).
|
| + DCHECK(IsLocalStatePrefService(this));
|
| + RegisterPreference(path,
|
| + default_value,
|
| + UNSYNCABLE_PREF);
|
| }
|
|
|
| void PrefService::RegisterLocalizedBooleanPref(const char* path,
|
| int locale_default_message_id) {
|
| + // If this fails, the pref service in use is a profile pref service, so the
|
| + // sync status must be provided (see profile pref registration calls below).
|
| + DCHECK(IsLocalStatePrefService(this));
|
| RegisterPreference(
|
| path,
|
| - CreateLocaleDefaultValue(Value::TYPE_BOOLEAN, locale_default_message_id));
|
| + CreateLocaleDefaultValue(Value::TYPE_BOOLEAN, locale_default_message_id),
|
| + UNSYNCABLE_PREF);
|
| }
|
|
|
| void PrefService::RegisterLocalizedIntegerPref(const char* path,
|
| int locale_default_message_id) {
|
| + // If this fails, the pref service in use is a profile pref service, so the
|
| + // sync status must be provided (see profile pref registration calls below).
|
| + DCHECK(IsLocalStatePrefService(this));
|
| RegisterPreference(
|
| path,
|
| - CreateLocaleDefaultValue(Value::TYPE_INTEGER, locale_default_message_id));
|
| + CreateLocaleDefaultValue(Value::TYPE_INTEGER, locale_default_message_id),
|
| + UNSYNCABLE_PREF);
|
| }
|
|
|
| void PrefService::RegisterLocalizedDoublePref(const char* path,
|
| int locale_default_message_id) {
|
| + // If this fails, the pref service in use is a profile pref service, so the
|
| + // sync status must be provided (see profile pref registration calls below).
|
| + DCHECK(IsLocalStatePrefService(this));
|
| RegisterPreference(
|
| path,
|
| - CreateLocaleDefaultValue(Value::TYPE_DOUBLE, locale_default_message_id));
|
| + CreateLocaleDefaultValue(Value::TYPE_DOUBLE, locale_default_message_id),
|
| + UNSYNCABLE_PREF);
|
| }
|
|
|
| void PrefService::RegisterLocalizedStringPref(const char* path,
|
| int locale_default_message_id) {
|
| + // If this fails, the pref service in use is a profile pref service, so the
|
| + // sync status must be provided (see profile pref registration calls below).
|
| + DCHECK(IsLocalStatePrefService(this));
|
| + RegisterPreference(
|
| + path,
|
| + CreateLocaleDefaultValue(Value::TYPE_STRING, locale_default_message_id),
|
| + UNSYNCABLE_PREF);
|
| +}
|
| +
|
| +void PrefService::RegisterInt64Pref(const char* path, int64 default_value) {
|
| + // If this fails, the pref service in use is a profile pref service, so the
|
| + // sync status must be provided (see profile pref registration calls below).
|
| + DCHECK(IsLocalStatePrefService(this));
|
| + RegisterPreference(
|
| + path,
|
| + Value::CreateStringValue(base::Int64ToString(default_value)),
|
| + UNSYNCABLE_PREF);
|
| +}
|
| +
|
| +// Profile prefs (must use the sync_status variable).
|
| +void PrefService::RegisterBooleanPref(const char* path,
|
| + bool default_value,
|
| + PrefSyncStatus sync_status) {
|
| + DCHECK(IsProfilePrefService(this));
|
| + RegisterPreference(path,
|
| + Value::CreateBooleanValue(default_value),
|
| + sync_status);
|
| +}
|
| +
|
| +void PrefService::RegisterIntegerPref(const char* path,
|
| + int default_value,
|
| + PrefSyncStatus sync_status) {
|
| + DCHECK(IsProfilePrefService(this));
|
| + RegisterPreference(path,
|
| + Value::CreateIntegerValue(default_value),
|
| + sync_status);
|
| +}
|
| +
|
| +void PrefService::RegisterDoublePref(const char* path,
|
| + double default_value,
|
| + PrefSyncStatus sync_status) {
|
| + DCHECK(IsProfilePrefService(this));
|
| + RegisterPreference(path,
|
| + Value::CreateDoubleValue(default_value),
|
| + sync_status);
|
| +}
|
| +
|
| +void PrefService::RegisterStringPref(const char* path,
|
| + const std::string& default_value,
|
| + PrefSyncStatus sync_status) {
|
| + DCHECK(IsProfilePrefService(this));
|
| + RegisterPreference(path,
|
| + Value::CreateStringValue(default_value),
|
| + sync_status);
|
| +}
|
| +
|
| +void PrefService::RegisterFilePathPref(const char* path,
|
| + const FilePath& default_value,
|
| + PrefSyncStatus sync_status) {
|
| + DCHECK(IsProfilePrefService(this));
|
| + RegisterPreference(path,
|
| + Value::CreateStringValue(default_value.value()),
|
| + sync_status);
|
| +}
|
| +
|
| +void PrefService::RegisterListPref(const char* path,
|
| + PrefSyncStatus sync_status) {
|
| + DCHECK(IsProfilePrefService(this));
|
| + RegisterPreference(path, new ListValue(), sync_status);
|
| +}
|
| +
|
| +void PrefService::RegisterListPref(const char* path,
|
| + ListValue* default_value,
|
| + PrefSyncStatus sync_status) {
|
| + DCHECK(IsProfilePrefService(this));
|
| + RegisterPreference(path, default_value, sync_status);
|
| +}
|
| +
|
| +void PrefService::RegisterDictionaryPref(const char* path,
|
| + PrefSyncStatus sync_status) {
|
| + DCHECK(IsProfilePrefService(this));
|
| + RegisterPreference(path, new DictionaryValue(), sync_status);
|
| +}
|
| +
|
| +void PrefService::RegisterDictionaryPref(const char* path,
|
| + DictionaryValue* default_value,
|
| + PrefSyncStatus sync_status) {
|
| + DCHECK(IsProfilePrefService(this));
|
| + RegisterPreference(path, default_value, sync_status);
|
| +}
|
| +
|
| +void PrefService::RegisterLocalizedBooleanPref(const char* path,
|
| + int locale_default_message_id,
|
| + PrefSyncStatus sync_status) {
|
| + DCHECK(IsProfilePrefService(this));
|
| + RegisterPreference(
|
| + path,
|
| + CreateLocaleDefaultValue(Value::TYPE_BOOLEAN,locale_default_message_id),
|
| + sync_status);
|
| +}
|
| +
|
| +void PrefService::RegisterLocalizedIntegerPref(const char* path,
|
| + int locale_default_message_id,
|
| + PrefSyncStatus sync_status) {
|
| + DCHECK(IsProfilePrefService(this));
|
| + RegisterPreference(
|
| + path,
|
| + CreateLocaleDefaultValue(Value::TYPE_INTEGER, locale_default_message_id),
|
| + sync_status);
|
| +}
|
| +
|
| +void PrefService::RegisterLocalizedDoublePref(const char* path,
|
| + int locale_default_message_id,
|
| + PrefSyncStatus sync_status) {
|
| + DCHECK(IsProfilePrefService(this));
|
| RegisterPreference(
|
| path,
|
| - CreateLocaleDefaultValue(Value::TYPE_STRING, locale_default_message_id));
|
| + CreateLocaleDefaultValue(Value::TYPE_DOUBLE, locale_default_message_id),
|
| + sync_status);
|
| +}
|
| +
|
| +void PrefService::RegisterLocalizedStringPref(const char* path,
|
| + int locale_default_message_id,
|
| + PrefSyncStatus sync_status) {
|
| + DCHECK(IsProfilePrefService(this));
|
| + RegisterPreference(
|
| + path,
|
| + CreateLocaleDefaultValue(Value::TYPE_STRING, locale_default_message_id),
|
| + sync_status);
|
| +}
|
| +
|
| +void PrefService::RegisterInt64Pref(const char* path,
|
| + int64 default_value,
|
| + PrefSyncStatus sync_status) {
|
| + DCHECK(IsProfilePrefService(this));
|
| + RegisterPreference(
|
| + path,
|
| + Value::CreateStringValue(base::Int64ToString(default_value)),
|
| + sync_status);
|
| }
|
|
|
| bool PrefService::GetBoolean(const char* path) const {
|
| @@ -486,7 +709,9 @@ void PrefService::RemovePrefObserver(const char* path,
|
| pref_notifier_->RemovePrefObserver(path, obs);
|
| }
|
|
|
| -void PrefService::RegisterPreference(const char* path, Value* default_value) {
|
| +void PrefService::RegisterPreference(const char* path,
|
| + Value* default_value,
|
| + PrefSyncStatus sync_status) {
|
| DCHECK(CalledOnValidThread());
|
|
|
| // The main code path takes ownership, but most don't. We'll be safe.
|
| @@ -503,6 +728,10 @@ void PrefService::RegisterPreference(const char* path, Value* default_value) {
|
|
|
| // Hand off ownership.
|
| default_store_->SetDefaultValue(path, scoped_value.release());
|
| +
|
| + // Register with sync if necessary.
|
| + if (sync_status == SYNCABLE_PREF && pref_sync_associator_.get())
|
| + pref_sync_associator_->RegisterPref(path);
|
| }
|
|
|
| void PrefService::ClearPref(const char* path) {
|
| @@ -561,11 +790,6 @@ int64 PrefService::GetInt64(const char* path) const {
|
| return val;
|
| }
|
|
|
| -void PrefService::RegisterInt64Pref(const char* path, int64 default_value) {
|
| - RegisterPreference(
|
| - path, Value::CreateStringValue(base::Int64ToString(default_value)));
|
| -}
|
| -
|
| Value* PrefService::GetMutableUserPref(const char* path,
|
| Value::ValueType type) {
|
| CHECK(type == Value::TYPE_DICTIONARY || type == Value::TYPE_LIST);
|
| @@ -626,6 +850,10 @@ void PrefService::SetUserPrefValue(const char* path, Value* new_value) {
|
| user_pref_store_->SetValue(path, owned_value.release());
|
| }
|
|
|
| +SyncableService* PrefService::GetSyncableService() {
|
| + return pref_sync_associator_.get();
|
| +}
|
| +
|
| ///////////////////////////////////////////////////////////////////////////////
|
| // PrefService::Preference
|
|
|
|
|