| 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..e29576236aa5f4b7a986e4e464174059018ea043 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();
|
| @@ -137,18 +134,42 @@ bool PaymentsProfileComparator::IsContactInfoComplete(
|
| GetRequiredProfileFieldsForContact());
|
| }
|
|
|
| -bool PaymentsProfileComparator::IsContactMoreComplete(
|
| - const autofill::AutofillProfile* p1,
|
| - const autofill::AutofillProfile* p2) const {
|
| - return GetContactCompletenessScore(p1) > GetContactCompletenessScore(p2);
|
| -}
|
| -
|
| base::string16 PaymentsProfileComparator::GetStringForMissingContactFields(
|
| const autofill::AutofillProfile& profile) const {
|
| return GetStringForMissingFields(GetMissingProfileFields(&profile) &
|
| 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(crbug.com/722949): Remove profiles with no relevant information, or
|
| + // which 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
|
| @@ -248,4 +269,16 @@ bool PaymentsProfileComparator::AreRequiredAddressFieldsPresent(
|
| return autofill::addressinput::HasAllRequiredFields(*data);
|
| }
|
|
|
| +bool PaymentsProfileComparator::IsContactMoreComplete(
|
| + const autofill::AutofillProfile* p1,
|
| + const autofill::AutofillProfile* p2) const {
|
| + return GetContactCompletenessScore(p1) > GetContactCompletenessScore(p2);
|
| +}
|
| +
|
| +bool PaymentsProfileComparator::IsShippingMoreComplete(
|
| + const autofill::AutofillProfile* p1,
|
| + const autofill::AutofillProfile* p2) const {
|
| + return GetShippingCompletenessScore(p1) > GetShippingCompletenessScore(p2);
|
| +}
|
| +
|
| } // namespace payments
|
|
|