OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/core/browser/personal_data_manager.h" | 5 #include "components/autofill/core/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 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 return false; | 719 return false; |
720 | 720 |
721 // Reject profiles with invalid US zip information. | 721 // Reject profiles with invalid US zip information. |
722 if (profile.IsPresentButInvalid(ADDRESS_HOME_ZIP)) | 722 if (profile.IsPresentButInvalid(ADDRESS_HOME_ZIP)) |
723 return false; | 723 return false; |
724 | 724 |
725 return true; | 725 return true; |
726 } | 726 } |
727 | 727 |
728 // static | 728 // static |
729 bool PersonalDataManager::MergeProfile( | 729 std::string PersonalDataManager::MergeProfile( |
730 const AutofillProfile& new_profile, | 730 const AutofillProfile& new_profile, |
731 const std::vector<AutofillProfile*>& existing_profiles, | 731 const std::vector<AutofillProfile*>& existing_profiles, |
732 const std::string& app_locale, | 732 const std::string& app_locale, |
733 std::vector<AutofillProfile>* merged_profiles) { | 733 std::vector<AutofillProfile>* merged_profiles) { |
734 merged_profiles->clear(); | 734 merged_profiles->clear(); |
735 | 735 |
736 // Set to true if |existing_profiles| already contains an equivalent profile. | |
737 bool matching_profile_found = false; | 736 bool matching_profile_found = false; |
| 737 std::string guid = new_profile.guid(); |
738 | 738 |
739 // If we have already saved this address, merge in any missing values. | 739 // If we have already saved this address, merge in any missing values. |
740 // Only merge with the first match. | 740 // Only merge with the first match. |
741 for (std::vector<AutofillProfile*>::const_iterator iter = | 741 for (std::vector<AutofillProfile*>::const_iterator iter = |
742 existing_profiles.begin(); | 742 existing_profiles.begin(); |
743 iter != existing_profiles.end(); ++iter) { | 743 iter != existing_profiles.end(); ++iter) { |
744 AutofillProfile* existing_profile = *iter; | 744 AutofillProfile* existing_profile = *iter; |
745 if (!matching_profile_found && | 745 if (!matching_profile_found && |
746 !new_profile.PrimaryValue().empty() && | 746 !new_profile.PrimaryValue().empty() && |
747 StringToLowerASCII(existing_profile->PrimaryValue()) == | 747 StringToLowerASCII(existing_profile->PrimaryValue()) == |
748 StringToLowerASCII(new_profile.PrimaryValue())) { | 748 StringToLowerASCII(new_profile.PrimaryValue())) { |
749 // Unverified profiles should always be updated with the newer data, | 749 // Unverified profiles should always be updated with the newer data, |
750 // whereas verified profiles should only ever be overwritten by verified | 750 // whereas verified profiles should only ever be overwritten by verified |
751 // data. If an automatically aggregated profile would overwrite a | 751 // data. If an automatically aggregated profile would overwrite a |
752 // verified profile, just drop it. | 752 // verified profile, just drop it. |
753 matching_profile_found = true; | 753 guid = existing_profile->guid(); |
754 if (!existing_profile->IsVerified() || new_profile.IsVerified()) | 754 if (!existing_profile->IsVerified() || new_profile.IsVerified()) |
755 existing_profile->OverwriteWithOrAddTo(new_profile, app_locale); | 755 existing_profile->OverwriteWithOrAddTo(new_profile, app_locale); |
756 } | 756 } |
757 merged_profiles->push_back(*existing_profile); | 757 merged_profiles->push_back(*existing_profile); |
758 } | 758 } |
759 | 759 |
760 // If the new profile was not merged with an existing one, add it to the list. | 760 // If the new profile was not merged with an existing one, add it to the list. |
761 if (!matching_profile_found) | 761 if (!matching_profile_found) |
762 merged_profiles->push_back(new_profile); | 762 merged_profiles->push_back(new_profile); |
763 | 763 |
764 return matching_profile_found; | 764 return guid; |
765 } | 765 } |
766 | 766 |
767 void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) { | 767 void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) { |
768 if (browser_context_->IsOffTheRecord()) | 768 if (browser_context_->IsOffTheRecord()) |
769 return; | 769 return; |
770 | 770 |
771 // Remove empty profiles from input. | 771 // Remove empty profiles from input. |
772 for (std::vector<AutofillProfile>::iterator it = profiles->begin(); | 772 for (std::vector<AutofillProfile>::iterator it = profiles->begin(); |
773 it != profiles->end();) { | 773 it != profiles->end();) { |
774 if (it->IsEmpty(app_locale_)) | 774 if (it->IsEmpty(app_locale_)) |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 AutofillWebDataService::FromBrowserContext(browser_context_)); | 955 AutofillWebDataService::FromBrowserContext(browser_context_)); |
956 if (!autofill_data.get()) { | 956 if (!autofill_data.get()) { |
957 NOTREACHED(); | 957 NOTREACHED(); |
958 return; | 958 return; |
959 } | 959 } |
960 autofill_data->CancelRequest(*handle); | 960 autofill_data->CancelRequest(*handle); |
961 } | 961 } |
962 *handle = 0; | 962 *handle = 0; |
963 } | 963 } |
964 | 964 |
965 void PersonalDataManager::SaveImportedProfile( | 965 std::string PersonalDataManager::SaveImportedProfile( |
966 const AutofillProfile& imported_profile) { | 966 const AutofillProfile& imported_profile) { |
967 if (browser_context_->IsOffTheRecord()) | 967 if (browser_context_->IsOffTheRecord()) |
968 return; | 968 return std::string(); |
969 | 969 |
970 // Don't save a web profile if the data in the profile is a subset of an | 970 // Don't save a web profile if the data in the profile is a subset of an |
971 // auxiliary profile. | 971 // auxiliary profile. |
972 for (std::vector<AutofillProfile*>::const_iterator iter = | 972 for (std::vector<AutofillProfile*>::const_iterator iter = |
973 auxiliary_profiles_.begin(); | 973 auxiliary_profiles_.begin(); |
974 iter != auxiliary_profiles_.end(); ++iter) { | 974 iter != auxiliary_profiles_.end(); ++iter) { |
975 if (imported_profile.IsSubsetOf(**iter, app_locale_)) | 975 if (imported_profile.IsSubsetOf(**iter, app_locale_)) |
976 return; | 976 return (*iter)->guid(); |
977 } | 977 } |
978 | 978 |
979 std::vector<AutofillProfile> profiles; | 979 std::vector<AutofillProfile> profiles; |
980 MergeProfile(imported_profile, web_profiles_.get(), app_locale_, &profiles); | 980 std::string guid = |
| 981 MergeProfile(imported_profile, web_profiles_.get(), app_locale_, |
| 982 &profiles); |
981 SetProfiles(&profiles); | 983 SetProfiles(&profiles); |
| 984 return guid; |
982 } | 985 } |
983 | 986 |
984 | 987 |
985 void PersonalDataManager::SaveImportedCreditCard( | 988 std::string PersonalDataManager::SaveImportedCreditCard( |
986 const CreditCard& imported_card) { | 989 const CreditCard& imported_card) { |
987 DCHECK(!imported_card.number().empty()); | 990 DCHECK(!imported_card.number().empty()); |
988 if (browser_context_->IsOffTheRecord()) | 991 if (browser_context_->IsOffTheRecord()) |
989 return; | 992 return std::string(); |
990 | 993 |
991 // Set to true if |imported_card| is merged into the credit card list. | 994 // Set to true if |imported_card| is merged into the credit card list. |
992 bool merged = false; | 995 bool merged = false; |
993 | 996 |
| 997 std::string guid = imported_card.guid(); |
994 std::vector<CreditCard> credit_cards; | 998 std::vector<CreditCard> credit_cards; |
995 for (std::vector<CreditCard*>::const_iterator card = credit_cards_.begin(); | 999 for (std::vector<CreditCard*>::const_iterator card = credit_cards_.begin(); |
996 card != credit_cards_.end(); | 1000 card != credit_cards_.end(); |
997 ++card) { | 1001 ++card) { |
998 // If |imported_card| has not yet been merged, check whether it should be | 1002 // If |imported_card| has not yet been merged, check whether it should be |
999 // with the current |card|. | 1003 // with the current |card|. |
1000 if (!merged && (*card)->UpdateFromImportedCard(imported_card, app_locale_)) | 1004 if (!merged && |
| 1005 (*card)->UpdateFromImportedCard(imported_card, app_locale_)) { |
| 1006 guid = (*card)->guid(); |
1001 merged = true; | 1007 merged = true; |
| 1008 } |
1002 | 1009 |
1003 credit_cards.push_back(**card); | 1010 credit_cards.push_back(**card); |
1004 } | 1011 } |
1005 | 1012 |
1006 if (!merged) | 1013 if (!merged) |
1007 credit_cards.push_back(imported_card); | 1014 credit_cards.push_back(imported_card); |
1008 | 1015 |
1009 SetCreditCards(&credit_cards); | 1016 SetCreditCards(&credit_cards); |
| 1017 return guid; |
1010 } | 1018 } |
1011 | 1019 |
1012 void PersonalDataManager::LogProfileCount() const { | 1020 void PersonalDataManager::LogProfileCount() const { |
1013 if (!has_logged_profile_count_) { | 1021 if (!has_logged_profile_count_) { |
1014 metric_logger_->LogStoredProfileCount(web_profiles_.size()); | 1022 metric_logger_->LogStoredProfileCount(web_profiles_.size()); |
1015 has_logged_profile_count_ = true; | 1023 has_logged_profile_count_ = true; |
1016 } | 1024 } |
1017 } | 1025 } |
1018 | 1026 |
1019 const AutofillMetrics* PersonalDataManager::metric_logger() const { | 1027 const AutofillMetrics* PersonalDataManager::metric_logger() const { |
1020 return metric_logger_.get(); | 1028 return metric_logger_.get(); |
1021 } | 1029 } |
1022 | 1030 |
1023 void PersonalDataManager::set_metric_logger( | 1031 void PersonalDataManager::set_metric_logger( |
1024 const AutofillMetrics* metric_logger) { | 1032 const AutofillMetrics* metric_logger) { |
1025 metric_logger_.reset(metric_logger); | 1033 metric_logger_.reset(metric_logger); |
1026 } | 1034 } |
1027 | 1035 |
1028 void PersonalDataManager::set_browser_context( | 1036 void PersonalDataManager::set_browser_context( |
1029 content::BrowserContext* context) { | 1037 content::BrowserContext* context) { |
1030 browser_context_ = context; | 1038 browser_context_ = context; |
1031 } | 1039 } |
1032 | 1040 |
1033 } // namespace autofill | 1041 } // namespace autofill |
OLD | NEW |