Commit 55901150 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

[WebLayer] notifyPaymentUiOfPendingApps

Refactor CPRService#OnCreatingPaymentApps to extract the UI logic
into notifyPaymentUiOfPendingApps().

Bug: 1144527

Change-Id: Id4539e13e2096d361b430cbab8c81a634e639709
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2515564
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823858}
parent 487bd02a
......@@ -1382,56 +1382,63 @@ public class ChromePaymentRequestService
mPaymentRequestService.getHasEnrolledInstrument()
&& mDelegate.prefsCanMakePayment());
if (mIsCanMakePaymentResponsePending) {
respondCanMakePaymentQuery();
}
if (mIsHasEnrolledInstrumentResponsePending) {
respondHasEnrolledInstrumentQuery(mPaymentRequestService.getHasEnrolledInstrument());
}
notifyPaymentUiOfPendingApps(mPendingApps);
if (mIsCurrentPaymentRequestShowing && !showAppSelector()) return;
triggerPaymentAppUiSkipIfApplicable();
}
private void notifyPaymentUiOfPendingApps(List<PaymentApp> pendingApps) {
if (mHideServerAutofillCards) {
List<PaymentApp> nonServerAutofillCards = new ArrayList<>();
int numberOfPendingApps = mPendingApps.size();
int numberOfPendingApps = pendingApps.size();
for (int i = 0; i < numberOfPendingApps; i++) {
if (!mPendingApps.get(i).isServerAutofillInstrument()) {
nonServerAutofillCards.add(mPendingApps.get(i));
if (!pendingApps.get(i).isServerAutofillInstrument()) {
nonServerAutofillCards.add(pendingApps.get(i));
}
}
mPendingApps = nonServerAutofillCards;
pendingApps = nonServerAutofillCards;
}
// Load the validation rules for each unique region code in the credit card billing
// addresses and check for validity.
Set<String> uniqueCountryCodes = new HashSet<>();
for (int i = 0; i < mPendingApps.size(); ++i) {
for (int i = 0; i < pendingApps.size(); ++i) {
@Nullable
String countryCode = mPendingApps.get(i).getCountryCode();
String countryCode = pendingApps.get(i).getCountryCode();
if (countryCode != null && !uniqueCountryCodes.contains(countryCode)) {
uniqueCountryCodes.add(countryCode);
PersonalDataManager.getInstance().loadRulesForAddressNormalization(countryCode);
}
}
mPaymentUiService.rankPaymentAppsForPaymentRequestUI(mPendingApps);
mPaymentUiService.rankPaymentAppsForPaymentRequestUI(pendingApps);
// Possibly pre-select the first app on the list.
int selection = !mPendingApps.isEmpty() && mPendingApps.get(0).canPreselect()
int selection = !pendingApps.isEmpty() && pendingApps.get(0).canPreselect()
? 0
: SectionInformation.NO_SELECTION;
if (mIsCanMakePaymentResponsePending) {
respondCanMakePaymentQuery();
}
if (mIsHasEnrolledInstrumentResponsePending) {
respondHasEnrolledInstrumentQuery(mPaymentRequestService.getHasEnrolledInstrument());
}
// The list of payment apps is ready to display.
mPaymentUiService.setPaymentMethodsSection(
new SectionInformation(PaymentRequestUI.DataType.PAYMENT_METHODS, selection,
new ArrayList<>(mPendingApps)));
new ArrayList<>(pendingApps)));
// Record the number suggested payment methods and whether at least one of them was
// complete.
mJourneyLogger.setNumberOfSuggestionsShown(Section.PAYMENT_METHOD, mPendingApps.size(),
!mPendingApps.isEmpty() && mPendingApps.get(0).isComplete());
mJourneyLogger.setNumberOfSuggestionsShown(Section.PAYMENT_METHOD, pendingApps.size(),
!pendingApps.isEmpty() && pendingApps.get(0).isComplete());
int missingFields = 0;
if (mPendingApps.isEmpty()) {
if (pendingApps.isEmpty()) {
if (mPaymentUiService.merchantSupportsAutofillCards()) {
// Record all fields if basic-card is supported but no card exists.
missingFields = AutofillPaymentInstrument.CompletionStatus.CREDIT_CARD_EXPIRED
......@@ -1439,22 +1446,19 @@ public class ChromePaymentRequestService
| AutofillPaymentInstrument.CompletionStatus.CREDIT_CARD_NO_NUMBER
| AutofillPaymentInstrument.CompletionStatus.CREDIT_CARD_NO_BILLING_ADDRESS;
}
} else if (mPendingApps.get(0).isAutofillInstrument()) {
missingFields = ((AutofillPaymentInstrument) (mPendingApps.get(0))).getMissingFields();
} else if (pendingApps.get(0).isAutofillInstrument()) {
missingFields = ((AutofillPaymentInstrument) (pendingApps.get(0))).getMissingFields();
}
if (missingFields != 0) {
RecordHistogram.recordSparseHistogram(
"PaymentRequest.MissingPaymentFields", missingFields);
}
mPendingApps.clear();
pendingApps.clear();
mPaymentUiService.updateAppModifiedTotals();
SettingsAutofillAndPaymentsObserver.getInstance().registerObserver(mPaymentUiService);
if (mIsCurrentPaymentRequestShowing && !showAppSelector()) return;
triggerPaymentAppUiSkipIfApplicable();
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment