Skip to content

Commit

Permalink
[basic-card] Remove autofill apps from PaymentApp::SortApps
Browse files Browse the repository at this point in the history
Basic card is now fully deprecated and disabled, and we are starting to
remove its code from the codebase. This CL removes the handling of
AutofillPaymentApps from PaymentApp::SortApps, which is a necessary
pre-requisite to removing AutofillPaymentApp itself.

Bug: 1209835
Change-Id: Iaeadfb8ae82b4add9c7740b5b03e407b06d8ae1c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3787136
Reviewed-by: Nick Burris <nburris@chromium.org>
Auto-Submit: Stephen McGruer <smcgruer@chromium.org>
Commit-Queue: Nick Burris <nburris@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1028298}
  • Loading branch information
stephenmcgruer authored and Chromium LUCI CQ committed Jul 26, 2022
1 parent 1082232 commit f480d00
Show file tree
Hide file tree
Showing 18 changed files with 8 additions and 333 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class MockApp : public PaymentApp {
// PaymentApp implementation:
MOCK_METHOD1(InvokePaymentApp, void(base::WeakPtr<Delegate> delegate));
MOCK_CONST_METHOD0(IsCompleteForPayment, bool());
MOCK_CONST_METHOD0(GetCompletenessScore, uint32_t());
MOCK_CONST_METHOD0(CanPreselect, bool());
MOCK_CONST_METHOD0(GetMissingInfoLabel, std::u16string());
MOCK_CONST_METHOD0(HasEnrolledInstrument, bool());
Expand Down
4 changes: 0 additions & 4 deletions components/payments/content/android_payment_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ bool AndroidPaymentApp::IsCompleteForPayment() const {
return true;
}

uint32_t AndroidPaymentApp::GetCompletenessScore() const {
return 0;
}

bool AndroidPaymentApp::CanPreselect() const {
return true;
}
Expand Down
1 change: 0 additions & 1 deletion components/payments/content/android_payment_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class AndroidPaymentApp : public PaymentApp {
// PaymentApp implementation.
void InvokePaymentApp(base::WeakPtr<Delegate> delegate) override;
bool IsCompleteForPayment() const override;
uint32_t GetCompletenessScore() const override;
bool CanPreselect() const override;
std::u16string GetMissingInfoLabel() const override;
bool HasEnrolledInstrument() const override;
Expand Down
5 changes: 0 additions & 5 deletions components/payments/content/autofill_payment_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ bool AutofillPaymentApp::IsCompleteForPayment() const {
billing_profiles_) <= CREDIT_CARD_EXPIRED;
}

uint32_t AutofillPaymentApp::GetCompletenessScore() const {
return ::payments::GetCompletenessScore(credit_card_, app_locale_,
billing_profiles_);
}

bool AutofillPaymentApp::CanPreselect() const {
return IsCompleteForPayment();
}
Expand Down
1 change: 0 additions & 1 deletion components/payments/content/autofill_payment_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class AutofillPaymentApp
// PaymentApp:
void InvokePaymentApp(base::WeakPtr<Delegate> delegate) override;
bool IsCompleteForPayment() const override;
uint32_t GetCompletenessScore() const override;
bool CanPreselect() const override;
std::u16string GetMissingInfoLabel() const override;
bool HasEnrolledInstrument() const override;
Expand Down
45 changes: 6 additions & 39 deletions components/payments/content/payment_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,25 @@

#include "base/callback.h"
#include "base/containers/contains.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/payments/content/autofill_payment_app.h"
#include "components/payments/core/features.h"
#include "components/payments/core/payments_experimental_features.h"

namespace payments {
namespace {

// Returns the sorting group of a payment app. This is used to order payment
// apps in the order of:
// 1. Built-in 1st-party payment handlers.
// 2. Installed 3rd-party payment handlers
// 3. Complete autofill instruments
// 4. Just-in-time installable payment handlers that is not yet installed.
// 5. Incomplete autofill instruments
// 1. Built-in available 1st-party payment handlers.
// 2. Installed or just-in-time installable payment handlers.
int GetSortingGroup(const PaymentApp& app) {
switch (app.type()) {
case PaymentApp::Type::INTERNAL:
return 1;
case PaymentApp::Type::SERVICE_WORKER_APP:
case PaymentApp::Type::NATIVE_MOBILE_APP:
// If the experimental feature is enabled, sort 3rd-party payment handlers
// that needs installation below autofill instruments.
if (app.NeedsInstallation() &&
PaymentsExperimentalFeatures::IsEnabled(
features::kDownRankJustInTimePaymentApp)) {
return 4;
}
return 2;
case PaymentApp::Type::AUTOFILL:
if (app.IsCompleteForPayment()) {
return 3;
}
return 5;
// TODO(https://crbug.com/1209835): Remove PaymentApp::Type::AUTOFILL.
NOTREACHED() << "Autofill payment app is no longer supported";
return 99;
case PaymentApp::Type::UNDEFINED:
NOTREACHED();
return 99;
Expand Down Expand Up @@ -124,23 +109,6 @@ bool PaymentApp::operator<(const PaymentApp& other) const {
return sorting_group < other_sorting_group;
}

// Within a group, compare by completeness.
// Non-autofill apps have max completeness score. Autofill cards are sorted
// based on completeness. (Each autofill card is considered an app.)
int completeness = GetCompletenessScore() - other.GetCompletenessScore();
if (completeness != 0)
return completeness > 0;

// Sort autofill cards using their ranking scores as tie breaker.
if (type_ == Type::AUTOFILL) {
DCHECK_EQ(other.type(), Type::AUTOFILL);
return static_cast<const AutofillPaymentApp*>(this)
->credit_card()
->HasGreaterRankingThan(
static_cast<const AutofillPaymentApp*>(&other)->credit_card(),
autofill::AutofillClock::Now());
}

// SW based payment apps are sorted based on whether they will handle shipping
// delegation or not (i.e. shipping address is requested and the app supports
// the delegation.).
Expand Down Expand Up @@ -172,8 +140,7 @@ bool PaymentApp::operator<(const PaymentApp& other) const {
return contact_delegations_diff > 0;

// SW based payment apps are sorted based on whether they can be pre-selected
// or not. Note that autofill cards are already sorted by CanPreselect() since
// they are sorted by completeness and type matching.
// or not.
if (CanPreselect() != other.CanPreselect())
return CanPreselect();
return false;
Expand Down
3 changes: 0 additions & 3 deletions components/payments/content/payment_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ class PaymentApp {
// Returns whether the app is complete to be used for payment without further
// editing.
virtual bool IsCompleteForPayment() const = 0;
// Returns the calculated completeness score. Used to sort the list of
// available apps.
virtual uint32_t GetCompletenessScore() const = 0;
// Returns whether the app can be preselected in the payment sheet. If none of
// the apps can be preselected, the user must explicitly select an app from a
// list.
Expand Down

0 comments on commit f480d00

Please sign in to comment.