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 |profile| is merged into |existing_profiles|. |
735 bool merged = false; | 735 bool merged = 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 (!merged && |
744 StringToLowerASCII((*iter)->PrimaryValue()) == | 744 !new_profile.PrimaryValue().empty() && |
745 StringToLowerASCII(profile.PrimaryValue())) { | 745 StringToLowerASCII(existing_profile->PrimaryValue()) == |
746 StringToLowerASCII(new_profile.PrimaryValue())) { | |
747 if (!existing_profile->IsVerified()) { | |
748 (*iter)->OverwriteWithOrAddTo(new_profile, app_locale); | |
746 merged = true; | 749 merged = true; |
747 | 750 } else if (!new_profile.IsVerified()) { |
748 // Automatically aggregated profiles should never overwrite explicitly | 751 // Automatically aggregated profiles should never overwrite explicitly |
749 // user-entered ones. If one would, just drop it. | 752 // user-entered ones. If one would, just drop it. |
750 DCHECK(!profile.IsVerified()); | 753 merged = true; |
Evan Stade
2013/06/12 20:40:17
nit: merged = true is a little confusing here, sin
Evan Stade
2013/06/12 20:40:17
So if the old profile is verified, and the new pro
Ilya Sherman
2013/06/13 05:41:37
Is it better now with "merged = true;" outside of
Ilya Sherman
2013/06/13 05:41:37
Done.
Evan Stade
2013/06/13 17:48:29
my suggestion would be:
// Set to true if |existi
Ilya Sherman
2013/06/14 23:58:25
Done.
| |
751 if (!(*iter)->IsVerified()) | |
752 (*iter)->OverwriteWithOrAddTo(profile, app_locale); | |
753 } | 754 } |
754 } | 755 } |
755 merged_profiles->push_back(**iter); | 756 merged_profiles->push_back(**iter); |
756 } | 757 } |
757 | 758 |
758 // If the new profile was not merged with an existing one, add it to the list. | 759 // If the new profile was not merged with an existing one, add it to the list. |
759 if (!merged) | 760 if (!merged) |
760 merged_profiles->push_back(profile); | 761 merged_profiles->push_back(new_profile); |
761 | 762 |
762 return merged; | 763 return merged; |
763 } | 764 } |
764 | 765 |
765 void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) { | 766 void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) { |
766 if (browser_context_->IsOffTheRecord()) | 767 if (browser_context_->IsOffTheRecord()) |
767 return; | 768 return; |
768 | 769 |
769 // Remove empty profiles from input. | 770 // Remove empty profiles from input. |
770 for (std::vector<AutofillProfile>::iterator it = profiles->begin(); | 771 for (std::vector<AutofillProfile>::iterator it = profiles->begin(); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1022 const AutofillMetrics* metric_logger) { | 1023 const AutofillMetrics* metric_logger) { |
1023 metric_logger_.reset(metric_logger); | 1024 metric_logger_.reset(metric_logger); |
1024 } | 1025 } |
1025 | 1026 |
1026 void PersonalDataManager::set_browser_context( | 1027 void PersonalDataManager::set_browser_context( |
1027 content::BrowserContext* context) { | 1028 content::BrowserContext* context) { |
1028 browser_context_ = context; | 1029 browser_context_ = context; |
1029 } | 1030 } |
1030 | 1031 |
1031 } // namespace autofill | 1032 } // namespace autofill |
OLD | NEW |