OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/autofill/browser/personal_data_manager.h" | 5 #include "components/autofill/browser/personal_data_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <iterator> | 9 #include <iterator> |
10 | 10 |
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 base::string16 zip = profile.GetRawInfo(ADDRESS_HOME_ZIP); | 718 base::string16 zip = profile.GetRawInfo(ADDRESS_HOME_ZIP); |
719 if (profile.GetRawInfo(ADDRESS_HOME_COUNTRY) == ASCIIToUTF16("US") && | 719 if (profile.GetRawInfo(ADDRESS_HOME_COUNTRY) == ASCIIToUTF16("US") && |
720 !zip.empty() && !autofill::IsValidZip(zip)) | 720 !zip.empty() && !autofill::IsValidZip(zip)) |
721 return false; | 721 return false; |
722 | 722 |
723 return true; | 723 return true; |
724 } | 724 } |
725 | 725 |
726 // static | 726 // static |
727 bool PersonalDataManager::MergeProfile( | 727 bool PersonalDataManager::MergeProfile( |
728 const AutofillProfile& profile, | 728 const AutofillProfile& new_profile, |
729 const std::vector<AutofillProfile*>& existing_profiles, | 729 const std::vector<AutofillProfile*>& existing_profiles, |
730 const std::string& app_locale, | 730 const std::string& app_locale, |
731 std::vector<AutofillProfile>* merged_profiles) { | 731 std::vector<AutofillProfile>* merged_profiles) { |
732 merged_profiles->clear(); | 732 merged_profiles->clear(); |
733 | 733 |
734 // Set to true if |profile| is merged into |existing_profiles|. | 734 // Set to true if |existing_profiles| already contains an equivalent profile. |
735 bool merged = false; | 735 bool matching_profile_found = false; |
736 | 736 |
737 // If we have already saved this address, merge in any missing values. | 737 // If we have already saved this address, merge in any missing values. |
738 // Only merge with the first match. | 738 // Only merge with the first match. |
739 for (std::vector<AutofillProfile*>::const_iterator iter = | 739 for (std::vector<AutofillProfile*>::const_iterator iter = |
740 existing_profiles.begin(); | 740 existing_profiles.begin(); |
741 iter != existing_profiles.end(); ++iter) { | 741 iter != existing_profiles.end(); ++iter) { |
742 if (!merged) { | 742 AutofillProfile* existing_profile = *iter; |
743 if (!profile.PrimaryValue().empty() && | 743 if (!matching_profile_found && |
744 StringToLowerASCII((*iter)->PrimaryValue()) == | 744 !new_profile.PrimaryValue().empty() && |
745 StringToLowerASCII(profile.PrimaryValue())) { | 745 StringToLowerASCII(existing_profile->PrimaryValue()) == |
746 merged = true; | 746 StringToLowerASCII(new_profile.PrimaryValue())) { |
747 | 747 // Unverified profiles should always be updated with the newer data, |
748 // Automatically aggregated profiles should never overwrite explicitly | 748 // whereas verified profiles should only ever be overwritten by verified |
749 // user-entered ones. If one would, just drop it. | 749 // data. If an automatically aggregated profile would overwrite a |
750 DCHECK(!profile.IsVerified()); | 750 // verified profile, just drop it. |
751 if (!(*iter)->IsVerified()) | 751 matching_profile_found = true; |
752 (*iter)->OverwriteWithOrAddTo(profile, app_locale); | 752 if (!existing_profile->IsVerified() || new_profile.IsVerified()) |
753 } | 753 existing_profile->OverwriteWithOrAddTo(new_profile, app_locale); |
754 } | 754 } |
755 merged_profiles->push_back(**iter); | 755 merged_profiles->push_back(*existing_profile); |
756 } | 756 } |
757 | 757 |
758 // If the new profile was not merged with an existing one, add it to the list. | 758 // If the new profile was not merged with an existing one, add it to the list. |
759 if (!merged) | 759 if (!matching_profile_found) |
760 merged_profiles->push_back(profile); | 760 merged_profiles->push_back(new_profile); |
761 | 761 |
762 return merged; | 762 return matching_profile_found; |
763 } | 763 } |
764 | 764 |
765 void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) { | 765 void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) { |
766 if (browser_context_->IsOffTheRecord()) | 766 if (browser_context_->IsOffTheRecord()) |
767 return; | 767 return; |
768 | 768 |
769 // Remove empty profiles from input. | 769 // Remove empty profiles from input. |
770 for (std::vector<AutofillProfile>::iterator it = profiles->begin(); | 770 for (std::vector<AutofillProfile>::iterator it = profiles->begin(); |
771 it != profiles->end();) { | 771 it != profiles->end();) { |
772 if (it->IsEmpty(app_locale_)) | 772 if (it->IsEmpty(app_locale_)) |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1022 const AutofillMetrics* metric_logger) { | 1022 const AutofillMetrics* metric_logger) { |
1023 metric_logger_.reset(metric_logger); | 1023 metric_logger_.reset(metric_logger); |
1024 } | 1024 } |
1025 | 1025 |
1026 void PersonalDataManager::set_browser_context( | 1026 void PersonalDataManager::set_browser_context( |
1027 content::BrowserContext* context) { | 1027 content::BrowserContext* context) { |
1028 browser_context_ = context; | 1028 browser_context_ = context; |
1029 } | 1029 } |
1030 | 1030 |
1031 } // namespace autofill | 1031 } // namespace autofill |
OLD | NEW |