Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(811)

Unified Diff: chrome/browser/prefs/pref_model_associator.cc

Issue 24930003: Migrate startup URLs pref. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR Comments - 1. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/prefs/session_startup_pref.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 28759a10b6919b681ac7fcea46e5fc8227e7fc00..84d07f81ff730ff3342258673631167f6ef44f13 100644
--- a/chrome/browser/prefs/pref_model_associator.cc
+++ b/chrome/browser/prefs/pref_model_associator.cc
@@ -78,7 +78,9 @@ void PrefModelAssociator::InitPrefAndAssociate(
if (sync_pref.IsValid()) {
const sync_pb::PreferenceSpecifics& preference = GetSpecifics(sync_pref);
- DCHECK_EQ(pref_name, preference.name());
+ DCHECK(pref_name == preference.name() ||
+ (pref_name == prefs::kURLsToRestoreOnStartup &&
+ preference.name() == prefs::kURLsToRestoreOnStartupOld));
base::JSONReader reader;
scoped_ptr<Value> sync_value(reader.ReadToValue(preference.value()));
@@ -119,6 +121,21 @@ void PrefModelAssociator::InitPrefAndAssociate(
syncer::SyncChange(FROM_HERE,
syncer::SyncChange::ACTION_UPDATE,
sync_data));
+ // This preference has been migrated from an old version that must be
+ // kept in sync on older versions of Chrome.
+ if (pref_name == prefs::kURLsToRestoreOnStartup) {
+ syncer::SyncData sync_data;
Nicolas Zea 2013/10/04 19:37:36 nit: CreatePrefSyncData will overwrite a SyncData
+ if (!CreatePrefSyncData(prefs::kURLsToRestoreOnStartupOld,
+ *new_value,
+ &sync_data)) {
+ LOG(ERROR) << "Failed to update preference.";
+ return;
+ }
+ sync_changes->push_back(
+ syncer::SyncChange(FROM_HERE,
+ syncer::SyncChange::ACTION_UPDATE,
+ sync_data));
+ }
}
} else if (!sync_value->IsType(Value::TYPE_NULL)) {
// Only a server value exists. Just set the local user value.
@@ -179,18 +196,26 @@ syncer::SyncMergeResult PrefModelAssociator::MergeDataAndStartSyncing(
DCHECK_EQ(type_, sync_iter->GetDataType());
const sync_pb::PreferenceSpecifics& preference = GetSpecifics(*sync_iter);
- const std::string& sync_pref_name = preference.name();
+ std::string sync_pref_name = preference.name();
if (remaining_preferences.count(sync_pref_name) == 0) {
- // We're not syncing this preference locally, ignore the sync data.
- // TODO(zea): Eventually we want to be able to have the syncable service
- // reconstruct all sync data for it's datatype (therefore having
- // GetAllSyncData be a complete representation). We should store this data
- // somewhere, even if we don't use it.
- continue;
+ if (sync_pref_name == prefs::kURLsToRestoreOnStartupOld) {
+ // This old pref name is not syncable locally anymore but we accept
+ // changes from other Chrome installs of previous versions and migrate
+ // them to the new name. Note that we will be merging any differences
+ // between the new and old values and sync'ing them back.
+ sync_pref_name = prefs::kURLsToRestoreOnStartup;
+ } else {
+ // We're not syncing this preference locally, ignore the sync data.
+ // TODO(zea): Eventually we want to be able to have the syncable service
+ // reconstruct all sync data for its datatype (therefore having
+ // GetAllSyncData be a complete representation). We should store this
+ // data somewhere, even if we don't use it.
+ continue;
+ }
+ } else {
+ remaining_preferences.erase(sync_pref_name);
}
-
- remaining_preferences.erase(sync_pref_name);
InitPrefAndAssociate(*sync_iter, sync_pref_name, &new_changes);
}
@@ -225,7 +250,8 @@ scoped_ptr<Value> PrefModelAssociator::MergePreference(
const std::string& name,
const Value& local_value,
const Value& server_value) {
- if (name == prefs::kURLsToRestoreOnStartup) {
+ if (name == prefs::kURLsToRestoreOnStartup ||
+ name == prefs::kURLsToRestoreOnStartupOld) {
return scoped_ptr<Value>(MergeListValues(local_value, server_value)).Pass();
}
@@ -388,7 +414,10 @@ syncer::SyncError PrefModelAssociator::ProcessSyncChanges(
// Windows client, the Windows client does not support
// kConfirmToQuitEnabled. Ignore updates from these preferences.
const char* pref_name = name.c_str();
- if (!IsPrefRegistered(pref_name))
+ // We migrated this preference name, so do as if the name had not changed.
+ if (name == prefs::kURLsToRestoreOnStartupOld)
+ pref_name = prefs::kURLsToRestoreOnStartup;
+ else if (!IsPrefRegistered(pref_name))
continue;
const PrefService::Preference* pref =
@@ -508,6 +537,22 @@ void PrefModelAssociator::ProcessPrefChange(const std::string& name) {
syncer::SyncChange(FROM_HERE,
syncer::SyncChange::ACTION_UPDATE,
sync_data));
+ // This preference has been migrated from an old version that must be kept
+ // in sync on older versions of Chrome.
+ if (name == prefs::kURLsToRestoreOnStartup) {
+ syncer::SyncData sync_data;
+ if (!CreatePrefSyncData(prefs::kURLsToRestoreOnStartupOld,
+ *preference->GetValue(),
+ &sync_data)) {
+ LOG(ERROR) << "Failed to update preference.";
+ return;
+ }
+
+ changes.push_back(
+ syncer::SyncChange(FROM_HERE,
+ syncer::SyncChange::ACTION_UPDATE,
+ sync_data));
+ }
}
syncer::SyncError error =
« no previous file with comments | « no previous file | chrome/browser/prefs/session_startup_pref.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698