Chromium Code Reviews| Index: chrome/browser/prefs/pref_model_associator.cc |
| diff --git a/chrome/browser/prefs/pref_model_associator.cc b/chrome/browser/prefs/pref_model_associator.cc |
| index ad7729b6d3a6f52a8f7009ebdfdd7c06bec34fbb..024bce07120cec3283dd1b6dd2248aeda0284288 100644 |
| --- a/chrome/browser/prefs/pref_model_associator.cc |
| +++ b/chrome/browser/prefs/pref_model_associator.cc |
| @@ -13,10 +13,8 @@ |
| #include "base/stl_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/values.h" |
| +#include "chrome/browser/prefs/pref_model_associator_client.h" |
| #include "chrome/browser/prefs/pref_service_syncable.h" |
| -#include "chrome/common/pref_names.h" |
| -#include "components/content_settings/core/browser/website_settings_info.h" |
| -#include "components/content_settings/core/browser/website_settings_registry.h" |
| #include "sync/api/sync_change.h" |
| #include "sync/api/sync_error_factory.h" |
| #include "sync/protocol/preference_specifics.pb.h" |
| @@ -55,7 +53,8 @@ PrefModelAssociator::PrefModelAssociator(syncer::ModelType type) |
| : models_associated_(false), |
| processing_syncer_changes_(false), |
| pref_service_(NULL), |
| - type_(type) { |
| + type_(type), |
| + pref_model_associator_client_(NULL) { |
| DCHECK(CalledOnValidThread()); |
| DCHECK(type_ == PREFERENCES || type_ == PRIORITY_PREFERENCES); |
| } |
| @@ -73,8 +72,8 @@ void PrefModelAssociator::InitPrefAndAssociate( |
| const syncer::SyncData& sync_pref, |
| const std::string& pref_name, |
| syncer::SyncChangeList* sync_changes) { |
| - const base::Value* user_pref_value = pref_service_->GetUserPrefValue( |
| - pref_name.c_str()); |
| + const base::Value* user_pref_value = |
| + pref_service_->GetUserPrefValue(pref_name.c_str()); |
| VLOG(1) << "Associating preference " << pref_name; |
| if (sync_pref.IsValid()) { |
| @@ -92,7 +91,8 @@ void PrefModelAssociator::InitPrefAndAssociate( |
| DVLOG(1) << "Found user pref value for " << pref_name; |
| // We have both server and local values. Merge them. |
| scoped_ptr<base::Value> new_value( |
| - MergePreference(pref_name, *user_pref_value, *sync_value)); |
| + MergePreference(pref_name, *user_pref_value, *sync_value, |
| + pref_model_associator_client_)); |
| // Update the local preference based on what we got from the |
| // sync server. Note: this only updates the user value store, which is |
| @@ -217,20 +217,24 @@ void PrefModelAssociator::StopSyncing(syncer::ModelType type) { |
| pref_service_->OnIsSyncingChanged(); |
| } |
| +// static |
| scoped_ptr<base::Value> PrefModelAssociator::MergePreference( |
| const std::string& name, |
| const base::Value& local_value, |
| - const base::Value& server_value) { |
| + const base::Value& server_value, |
| + PrefModelAssociatorClient* pref_model_associator_client) { |
|
gab
2015/09/10 14:15:09
Can we make this a member method and have it use |
|
| // This function special cases preferences individually, so don't attempt |
| // to merge for all migrated values. |
| - if (name == prefs::kURLsToRestoreOnStartup) |
| - return make_scoped_ptr(MergeListValues(local_value, server_value)); |
| - |
| - content_settings::WebsiteSettingsRegistry* registry = |
| - content_settings::WebsiteSettingsRegistry::GetInstance(); |
| - for (const content_settings::WebsiteSettingsInfo* info : *registry) { |
| - if (info->pref_name() == name) |
| - return make_scoped_ptr(MergeDictionaryValues(local_value, server_value)); |
| + PrefModelAssociatorPreferenceType pref_type; |
| + if (pref_model_associator_client && |
| + pref_model_associator_client->IsPreferenceMerged(name, &pref_type)) { |
| + switch (pref_type) { |
| + case PREF_MODEL_PREFERENCE_TYPE_LIST: |
| + return make_scoped_ptr(MergeListValues(local_value, server_value)); |
| + case PREF_MODEL_PREFERENCE_TYPE_DICT: |
| + return make_scoped_ptr( |
| + MergeDictionaryValues(local_value, server_value)); |
| + } |
| } |
| // If this is not a specially handled preference, server wins. |
| @@ -329,8 +333,7 @@ base::Value* PrefModelAssociator::MergeDictionaryValues( |
| // not registered locally as syncable and do not inform the syncer of |
| // non-user controlled preferences. |
| syncer::SyncDataList PrefModelAssociator::GetAllSyncData( |
| - syncer::ModelType type) |
| - const { |
| + syncer::ModelType type) const { |
| DCHECK_EQ(type_, type); |
| syncer::SyncDataList current_data; |
| for (PreferenceSet::const_iterator iter = synced_preferences_.begin(); |
| @@ -338,7 +341,7 @@ syncer::SyncDataList PrefModelAssociator::GetAllSyncData( |
| ++iter) { |
| std::string name = *iter; |
| const PrefService::Preference* pref = |
| - pref_service_->FindPreference(name.c_str()); |
| + pref_service_->FindPreference(name.c_str()); |
| DCHECK(pref); |
| if (!pref->IsUserControlled() || pref->IsDefaultValue()) |
| continue; // This is not data we care about. |
| @@ -411,8 +414,8 @@ base::Value* PrefModelAssociator::ReadPreferenceSpecifics( |
| base::JSONReader reader; |
| scoped_ptr<base::Value> value(reader.ReadToValue(preference.value())); |
| if (!value.get()) { |
| - std::string err = "Failed to deserialize preference value: " + |
| - reader.GetErrorMessage(); |
| + std::string err = |
| + "Failed to deserialize preference value: " + reader.GetErrorMessage(); |
| LOG(ERROR) << err; |
| return NULL; |
| } |
| @@ -424,7 +427,7 @@ bool PrefModelAssociator::IsPrefSynced(const std::string& name) const { |
| } |
| void PrefModelAssociator::AddSyncedPrefObserver(const std::string& name, |
| - SyncedPrefObserver* observer) { |
| + SyncedPrefObserver* observer) { |
| SyncedPrefObserverList* observers = synced_pref_observers_[name]; |
| if (observers == NULL) { |
| observers = new SyncedPrefObserverList; |
| @@ -433,7 +436,8 @@ void PrefModelAssociator::AddSyncedPrefObserver(const std::string& name, |
| observers->AddObserver(observer); |
| } |
| -void PrefModelAssociator::RemoveSyncedPrefObserver(const std::string& name, |
| +void PrefModelAssociator::RemoveSyncedPrefObserver( |
| + const std::string& name, |
| SyncedPrefObserver* observer) { |
| SyncedPrefObserverMap::iterator observer_iter = |
| synced_pref_observers_.find(name); |