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

Side by Side Diff: components/autofill/core/browser/personal_data_manager.cc

Issue 23882013: [rAc] Persist selection of newly added cards and addresses. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests, add a test Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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. 736 // Set to true if |existing_profiles| already contains an equivalent profile.
737 bool matching_profile_found = false; 737 bool matching_profile_found = false;
738 std::string guid = new_profile.guid();
738 739
739 // If we have already saved this address, merge in any missing values. 740 // If we have already saved this address, merge in any missing values.
740 // Only merge with the first match. 741 // Only merge with the first match.
741 for (std::vector<AutofillProfile*>::const_iterator iter = 742 for (std::vector<AutofillProfile*>::const_iterator iter =
742 existing_profiles.begin(); 743 existing_profiles.begin();
743 iter != existing_profiles.end(); ++iter) { 744 iter != existing_profiles.end(); ++iter) {
744 AutofillProfile* existing_profile = *iter; 745 AutofillProfile* existing_profile = *iter;
745 if (!matching_profile_found && 746 if (!matching_profile_found &&
746 !new_profile.PrimaryValue().empty() && 747 !new_profile.PrimaryValue().empty() &&
747 StringToLowerASCII(existing_profile->PrimaryValue()) == 748 StringToLowerASCII(existing_profile->PrimaryValue()) ==
748 StringToLowerASCII(new_profile.PrimaryValue())) { 749 StringToLowerASCII(new_profile.PrimaryValue())) {
749 // Unverified profiles should always be updated with the newer data, 750 // Unverified profiles should always be updated with the newer data,
750 // whereas verified profiles should only ever be overwritten by verified 751 // whereas verified profiles should only ever be overwritten by verified
751 // data. If an automatically aggregated profile would overwrite a 752 // data. If an automatically aggregated profile would overwrite a
752 // verified profile, just drop it. 753 // verified profile, just drop it.
753 matching_profile_found = true; 754 matching_profile_found = true;
755 guid = existing_profile->guid();
754 if (!existing_profile->IsVerified() || new_profile.IsVerified()) 756 if (!existing_profile->IsVerified() || new_profile.IsVerified())
755 existing_profile->OverwriteWithOrAddTo(new_profile, app_locale); 757 existing_profile->OverwriteWithOrAddTo(new_profile, app_locale);
756 } 758 }
757 merged_profiles->push_back(*existing_profile); 759 merged_profiles->push_back(*existing_profile);
758 } 760 }
759 761
760 // If the new profile was not merged with an existing one, add it to the list. 762 // If the new profile was not merged with an existing one, add it to the list.
761 if (!matching_profile_found) 763 if (!matching_profile_found)
762 merged_profiles->push_back(new_profile); 764 merged_profiles->push_back(new_profile);
763 765
764 return matching_profile_found; 766 return guid;
765 } 767 }
766 768
767 void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) { 769 void PersonalDataManager::SetProfiles(std::vector<AutofillProfile>* profiles) {
768 if (browser_context_->IsOffTheRecord()) 770 if (browser_context_->IsOffTheRecord())
769 return; 771 return;
770 772
771 // Remove empty profiles from input. 773 // Remove empty profiles from input.
772 for (std::vector<AutofillProfile>::iterator it = profiles->begin(); 774 for (std::vector<AutofillProfile>::iterator it = profiles->begin();
773 it != profiles->end();) { 775 it != profiles->end();) {
774 if (it->IsEmpty(app_locale_)) 776 if (it->IsEmpty(app_locale_))
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 AutofillWebDataService::FromBrowserContext(browser_context_)); 957 AutofillWebDataService::FromBrowserContext(browser_context_));
956 if (!autofill_data.get()) { 958 if (!autofill_data.get()) {
957 NOTREACHED(); 959 NOTREACHED();
958 return; 960 return;
959 } 961 }
960 autofill_data->CancelRequest(*handle); 962 autofill_data->CancelRequest(*handle);
961 } 963 }
962 *handle = 0; 964 *handle = 0;
963 } 965 }
964 966
965 void PersonalDataManager::SaveImportedProfile( 967 std::string PersonalDataManager::SaveImportedProfile(
966 const AutofillProfile& imported_profile) { 968 const AutofillProfile& imported_profile) {
967 if (browser_context_->IsOffTheRecord()) 969 if (browser_context_->IsOffTheRecord())
968 return; 970 return std::string();
969 971
970 // Don't save a web profile if the data in the profile is a subset of an 972 // Don't save a web profile if the data in the profile is a subset of an
971 // auxiliary profile. 973 // auxiliary profile.
972 for (std::vector<AutofillProfile*>::const_iterator iter = 974 for (std::vector<AutofillProfile*>::const_iterator iter =
973 auxiliary_profiles_.begin(); 975 auxiliary_profiles_.begin();
974 iter != auxiliary_profiles_.end(); ++iter) { 976 iter != auxiliary_profiles_.end(); ++iter) {
975 if (imported_profile.IsSubsetOf(**iter, app_locale_)) 977 if (imported_profile.IsSubsetOf(**iter, app_locale_))
976 return; 978 return (*iter)->guid();
977 } 979 }
978 980
979 std::vector<AutofillProfile> profiles; 981 std::vector<AutofillProfile> profiles;
980 MergeProfile(imported_profile, web_profiles_.get(), app_locale_, &profiles); 982 std::string guid =
983 MergeProfile(imported_profile, web_profiles_.get(), app_locale_,
984 &profiles);
981 SetProfiles(&profiles); 985 SetProfiles(&profiles);
986 return guid;
982 } 987 }
983 988
984 989
985 void PersonalDataManager::SaveImportedCreditCard( 990 std::string PersonalDataManager::SaveImportedCreditCard(
986 const CreditCard& imported_card) { 991 const CreditCard& imported_card) {
987 DCHECK(!imported_card.number().empty()); 992 DCHECK(!imported_card.number().empty());
988 if (browser_context_->IsOffTheRecord()) 993 if (browser_context_->IsOffTheRecord())
989 return; 994 return std::string();
990 995
991 // Set to true if |imported_card| is merged into the credit card list. 996 // Set to true if |imported_card| is merged into the credit card list.
992 bool merged = false; 997 bool merged = false;
993 998
999 std::string guid = imported_card.guid();
994 std::vector<CreditCard> credit_cards; 1000 std::vector<CreditCard> credit_cards;
995 for (std::vector<CreditCard*>::const_iterator card = credit_cards_.begin(); 1001 for (std::vector<CreditCard*>::const_iterator card = credit_cards_.begin();
996 card != credit_cards_.end(); 1002 card != credit_cards_.end();
997 ++card) { 1003 ++card) {
998 // If |imported_card| has not yet been merged, check whether it should be 1004 // If |imported_card| has not yet been merged, check whether it should be
999 // with the current |card|. 1005 // with the current |card|.
1000 if (!merged && (*card)->UpdateFromImportedCard(imported_card, app_locale_)) 1006 if (!merged &&
1007 (*card)->UpdateFromImportedCard(imported_card, app_locale_)) {
1008 guid = (*card)->guid();
1001 merged = true; 1009 merged = true;
1010 }
1002 1011
1003 credit_cards.push_back(**card); 1012 credit_cards.push_back(**card);
1004 } 1013 }
1005 1014
1006 if (!merged) 1015 if (!merged)
1007 credit_cards.push_back(imported_card); 1016 credit_cards.push_back(imported_card);
1008 1017
1009 SetCreditCards(&credit_cards); 1018 SetCreditCards(&credit_cards);
1019 return guid;
1010 } 1020 }
1011 1021
1012 void PersonalDataManager::LogProfileCount() const { 1022 void PersonalDataManager::LogProfileCount() const {
1013 if (!has_logged_profile_count_) { 1023 if (!has_logged_profile_count_) {
1014 metric_logger_->LogStoredProfileCount(web_profiles_.size()); 1024 metric_logger_->LogStoredProfileCount(web_profiles_.size());
1015 has_logged_profile_count_ = true; 1025 has_logged_profile_count_ = true;
1016 } 1026 }
1017 } 1027 }
1018 1028
1019 const AutofillMetrics* PersonalDataManager::metric_logger() const { 1029 const AutofillMetrics* PersonalDataManager::metric_logger() const {
1020 return metric_logger_.get(); 1030 return metric_logger_.get();
1021 } 1031 }
1022 1032
1023 void PersonalDataManager::set_metric_logger( 1033 void PersonalDataManager::set_metric_logger(
1024 const AutofillMetrics* metric_logger) { 1034 const AutofillMetrics* metric_logger) {
1025 metric_logger_.reset(metric_logger); 1035 metric_logger_.reset(metric_logger);
1026 } 1036 }
1027 1037
1028 void PersonalDataManager::set_browser_context( 1038 void PersonalDataManager::set_browser_context(
1029 content::BrowserContext* context) { 1039 content::BrowserContext* context) {
1030 browser_context_ = context; 1040 browser_context_ = context;
1031 } 1041 }
1032 1042
1033 } // namespace autofill 1043 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698