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

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: Now with sync support. 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
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..7dba18ed6ea17d2d736acbafb7510d2b6231622c 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()));
@@ -179,18 +181,25 @@ 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.
+ sync_pref_name = prefs::kURLsToRestoreOnStartup;
Nicolas Zea 2013/10/04 17:45:01 Maybe mention that we'll be merging any difference
MAD 2013/10/04 19:31:22 Done.
+ } 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 it's datatype (therefore having
grt (UTC plus 2) 2013/10/04 18:24:07 it's -> its
MAD 2013/10/04 19:31:22 Done.
+ // 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 +234,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 +398,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 +521,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') | chrome/browser/prefs/session_startup_pref.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698