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

Unified Diff: chrome/browser/webdata/autofill_profile_syncable_service.cc

Issue 16024018: [Autofill] Sync Autofill profiles' origins. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Hyphens? We don't need no stinkin' hyphens. Created 7 years, 6 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/webdata/autofill_profile_syncable_service.cc
diff --git a/chrome/browser/webdata/autofill_profile_syncable_service.cc b/chrome/browser/webdata/autofill_profile_syncable_service.cc
index 60b73b5b522327ea3c75dc94d6e64c98279188f4..9e573745b7da75e7897701fb51ea03b5858c7282 100644
--- a/chrome/browser/webdata/autofill_profile_syncable_service.cc
+++ b/chrome/browser/webdata/autofill_profile_syncable_service.cc
@@ -319,6 +319,15 @@ bool AutofillProfileSyncableService::OverwriteProfileWithServerData(
AutofillProfile* profile,
const std::string& app_locale) {
bool diff = false;
+ if (profile->origin() != specifics.origin()) {
+ bool was_verified = profile->IsVerified();
+ profile->set_origin(specifics.origin());
+ diff = true;
+
+ // Verified profiles should never be overwritten by unverified ones.
+ DCHECK(!was_verified || profile->IsVerified());
+ }
+
diff = UpdateMultivaluedField(autofill::NAME_FIRST,
specifics.name_first(), profile) || diff;
diff = UpdateMultivaluedField(autofill::NAME_MIDDLE,
@@ -368,6 +377,8 @@ void AutofillProfileSyncableService::WriteAutofillProfile(
specifics->clear_phone_home_whole_number();
specifics->set_guid(profile.guid());
+ specifics->set_origin(profile.origin());
+
std::vector<string16> values;
profile.GetRawMultiInfo(autofill::NAME_FIRST, &values);
for (size_t i = 0; i < values.size(); ++i) {
@@ -445,16 +456,23 @@ AutofillProfileSyncableService::CreateOrUpdateProfile(
}
} else {
// New profile synced.
- // TODO(isherman): Read the origin from |autofill_specifics|.
- AutofillProfile* new_profile(
- new AutofillProfile(autofill_specifics.guid(), std::string()));
+ AutofillProfile* new_profile = new AutofillProfile(
+ autofill_specifics.guid(), autofill_specifics.origin());
OverwriteProfileWithServerData(
autofill_specifics, new_profile, app_locale_);
// Check if profile appears under a different guid.
+ // Unverified profiles should never overwrite verified ones.
for (GUIDToProfileMap::iterator i = profile_map->begin();
i != profile_map->end(); ++i) {
Evan Stade 2013/06/12 22:12:24 nit: more readable if you create a local variable
Ilya Sherman 2013/06/13 04:19:32 Done.
if (i->second->Compare(*new_profile) == 0) {
+ // Ensure that a verified profile can never revert back to an unverified
+ // one.
+ if (i->second->IsVerified() && !new_profile->IsVerified()) {
+ new_profile->set_origin(i->second->origin());
+ bundle->profiles_to_sync_back.push_back(new_profile);
+ }
+
bundle->profiles_to_delete.push_back(i->second->guid());
DVLOG(2) << "[AUTOFILL SYNC]"
<< "Found in sync db but with a different guid: "
@@ -464,7 +482,9 @@ AutofillProfileSyncableService::CreateOrUpdateProfile(
<< ". Profile to be deleted " << i->second->guid();
profile_map->erase(i);
break;
- } else if (!i->second->PrimaryValue().empty() &&
+ } else if (!i->second->IsVerified() &&
+ !new_profile->IsVerified() &&
+ !i->second->PrimaryValue().empty() &&
i->second->PrimaryValue() == new_profile->PrimaryValue()) {
// Add it to candidates for merge - if there is no profile with this
// guid we will merge them.
@@ -581,8 +601,11 @@ bool AutofillProfileSyncableService::MergeProfile(
const AutofillProfile& merge_from,
AutofillProfile* merge_into,
const std::string& app_locale) {
+ DCHECK(!merge_into->IsVerified() || merge_from.IsVerified());
+ merge_into->set_origin(merge_from.origin());
merge_into->OverwriteWithOrAddTo(merge_from, app_locale);
- return (merge_into->Compare(merge_from) != 0);
+ return (merge_into->Compare(merge_from) != 0 ||
+ merge_into->origin() != merge_from.origin());
}
AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const {

Powered by Google App Engine
This is Rietveld 408576698