Index: components/payments/core/payments_profile_comparator.cc |
diff --git a/components/payments/core/payments_profile_comparator.cc b/components/payments/core/payments_profile_comparator.cc |
index 832e005dd9d2494fcd28cba5033aa4daef1f8d73..7f531e8c0899bc0cbe41a5e3b51f929b52b87b9d 100644 |
--- a/components/payments/core/payments_profile_comparator.cc |
+++ b/components/payments/core/payments_profile_comparator.cc |
@@ -118,9 +118,6 @@ bool PaymentsProfileComparator::IsContactEqualOrSuperset( |
int PaymentsProfileComparator::GetContactCompletenessScore( |
const autofill::AutofillProfile* profile) const { |
- if (!profile) |
- return 0; |
- |
// Create a bitmask of the fields that are both present and required. |
ProfileFields present = |
~GetMissingProfileFields(profile) & GetRequiredProfileFieldsForContact(); |
@@ -149,6 +146,36 @@ base::string16 PaymentsProfileComparator::GetStringForMissingContactFields( |
GetRequiredProfileFieldsForContact()); |
} |
+std::vector<autofill::AutofillProfile*> |
+PaymentsProfileComparator::FilterProfilesForShipping( |
+ const std::vector<autofill::AutofillProfile*>& profiles) const { |
+ // Since we'll be changing the order/contents of the const input vector, |
+ // we make a copy. |
+ std::vector<autofill::AutofillProfile*> processed = profiles; |
+ |
+ std::stable_sort( |
+ processed.begin(), processed.end(), |
+ std::bind(&PaymentsProfileComparator::IsShippingMoreComplete, this, |
+ std::placeholders::_1, std::placeholders::_2)); |
+ |
+ // TODO(tmartino): Remove profiles with no relevant information, or which |
Mathieu
2017/05/16 20:16:51
TODO(crbug.com/xxxxxx) please
tmartino
2017/05/18 20:49:37
Done
|
+ // are subsets of more-complete profiles. |
+ |
+ return processed; |
+} |
+ |
+int PaymentsProfileComparator::GetShippingCompletenessScore( |
+ const autofill::AutofillProfile* profile) const { |
+ // Create a bitmask of the fields that are both present and required. |
+ ProfileFields present = |
+ ~GetMissingProfileFields(profile) & GetRequiredProfileFieldsForShipping(); |
+ |
+ // Count how many are set. The completeness of the address is weighted so as |
+ // to dominate the other fields. |
+ return !!(present & kName) + !!(present & kPhone) + |
+ (10 * !!(present & kAddress)); |
+} |
+ |
bool PaymentsProfileComparator::IsShippingComplete( |
const autofill::AutofillProfile* profile) const { |
// Mask the fields that are missing with those that are requried. If any bits |
@@ -157,6 +184,12 @@ bool PaymentsProfileComparator::IsShippingComplete( |
GetRequiredProfileFieldsForShipping()); |
} |
+bool PaymentsProfileComparator::IsShippingMoreComplete( |
+ const autofill::AutofillProfile* p1, |
+ const autofill::AutofillProfile* p2) const { |
+ return GetShippingCompletenessScore(p1) > GetShippingCompletenessScore(p2); |
+} |
+ |
base::string16 PaymentsProfileComparator::GetStringForMissingShippingFields( |
const autofill::AutofillProfile& profile) const { |
return GetStringForMissingFields(GetMissingProfileFields(&profile) & |