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

Unified Diff: chrome/browser/autofill/personal_data_manager.cc

Issue 6312174: Add a data-driven unit test to validate autofill profile merging during aggregation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename reserialization script Created 9 years, 10 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 | « chrome/browser/autofill/personal_data_manager.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autofill/personal_data_manager.cc
diff --git a/chrome/browser/autofill/personal_data_manager.cc b/chrome/browser/autofill/personal_data_manager.cc
index 73af53e14ed7597bfb7a43ed828c1bbfdf202af3..edef1d92848c0f8c7d13c4bbd2f56ab87b7b6b1e 100644
--- a/chrome/browser/autofill/personal_data_manager.cc
+++ b/chrome/browser/autofill/personal_data_manager.cc
@@ -421,53 +421,8 @@ void PersonalDataManager::AddProfile(const AutoFillProfile& profile) {
return;
}
- // Set to true if |profile| is merged into the profile list.
- bool merged = false;
-
- // First preference is to add missing values to an existing profile.
- // Only merge with the first match.
std::vector<AutoFillProfile> profiles;
- for (std::vector<AutoFillProfile*>::const_iterator iter =
- web_profiles_.begin();
- iter != web_profiles_.end(); ++iter) {
- if (!merged) {
- if (profile.IsSubsetOf(**iter)) {
- // In this case, the existing profile already contains all of the data
- // in |profile|, so consider the profiles already merged.
- merged = true;
- } else if ((*iter)->IntersectionOfTypesHasEqualValues(profile)) {
- // |profile| contains all of the data in this profile, plus more.
- merged = true;
- (*iter)->MergeWith(profile);
- }
- }
- profiles.push_back(**iter);
- }
-
- // The second preference, if not merged above, is to alter non-primary values
- // where the primary values match.
- // Again, only merge with the first match.
- if (!merged) {
- profiles.clear();
- for (std::vector<AutoFillProfile*>::const_iterator iter =
- web_profiles_.begin();
- iter != web_profiles_.end(); ++iter) {
- if (!merged) {
- if (!profile.PrimaryValue().empty() &&
- (*iter)->PrimaryValue() == profile.PrimaryValue()) {
- merged = true;
- (*iter)->OverwriteWith(profile);
- }
- }
- profiles.push_back(**iter);
- }
- }
-
- // Finally, if the new profile was not merged with an existing profile then
- // add the new profile to the list.
- if (!merged)
- profiles.push_back(profile);
-
+ MergeProfile(profile, web_profiles_.get(), &profiles);
SetProfiles(&profiles);
}
@@ -784,6 +739,63 @@ void PersonalDataManager::SaveImportedProfile(
AddProfile(imported_profile);
}
+bool PersonalDataManager::MergeProfile(
+ const AutoFillProfile& profile,
+ const std::vector<AutoFillProfile*>& existing_profiles,
+ std::vector<AutoFillProfile>* merged_profiles) {
+ DCHECK(merged_profiles);
+ merged_profiles->clear();
+
+ // Set to true if |profile| is merged into |existing_profiles|.
+ bool merged = false;
+
+ // First preference is to add missing values to an existing profile.
+ // Only merge with the first match.
+ for (std::vector<AutoFillProfile*>::const_iterator iter =
+ existing_profiles.begin();
+ iter != existing_profiles.end(); ++iter) {
+ if (!merged) {
+ if (profile.IsSubsetOf(**iter)) {
+ // In this case, the existing profile already contains all of the data
+ // in |profile|, so consider the profiles already merged.
+ merged = true;
+ } else if ((*iter)->IntersectionOfTypesHasEqualValues(profile)) {
+ // |profile| contains all of the data in this profile, plus more.
+ merged = true;
+ (*iter)->MergeWith(profile);
+ }
+ }
+ merged_profiles->push_back(**iter);
+ }
+
+ // The second preference, if not merged above, is to alter non-primary values
+ // where the primary values match.
+ // Again, only merge with the first match.
+ if (!merged) {
+ merged_profiles->clear();
+ for (std::vector<AutoFillProfile*>::const_iterator iter =
+ existing_profiles.begin();
+ iter != existing_profiles.end(); ++iter) {
+ if (!merged) {
+ if (!profile.PrimaryValue().empty() &&
+ (*iter)->PrimaryValue() == profile.PrimaryValue()) {
+ merged = true;
+ (*iter)->OverwriteWith(profile);
+ }
+ }
+ merged_profiles->push_back(**iter);
+ }
+ }
+
+ // Finally, if the new profile was not merged with an existing profile then
+ // add the new profile to the list.
+ if (!merged)
+ merged_profiles->push_back(profile);
+
+ return merged;
+}
+
+
void PersonalDataManager::SaveImportedCreditCard(
const CreditCard& imported_credit_card) {
if (profile_->IsOffTheRecord())
« no previous file with comments | « chrome/browser/autofill/personal_data_manager.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698