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 ...@@ -1382,56 +1382,63 @@ public class ChromePaymentRequestService
mPaymentRequestService.getHasEnrolledInstrument() mPaymentRequestService.getHasEnrolledInstrument()
&& mDelegate.prefsCanMakePayment()); && 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) { if (mHideServerAutofillCards) {
List<PaymentApp> nonServerAutofillCards = new ArrayList<>(); List<PaymentApp> nonServerAutofillCards = new ArrayList<>();
int numberOfPendingApps = mPendingApps.size(); int numberOfPendingApps = pendingApps.size();
for (int i = 0; i < numberOfPendingApps; i++) { for (int i = 0; i < numberOfPendingApps; i++) {
if (!mPendingApps.get(i).isServerAutofillInstrument()) { if (!pendingApps.get(i).isServerAutofillInstrument()) {
nonServerAutofillCards.add(mPendingApps.get(i)); nonServerAutofillCards.add(pendingApps.get(i));
} }
} }
mPendingApps = nonServerAutofillCards; pendingApps = nonServerAutofillCards;
} }
// Load the validation rules for each unique region code in the credit card billing // Load the validation rules for each unique region code in the credit card billing
// addresses and check for validity. // addresses and check for validity.
Set<String> uniqueCountryCodes = new HashSet<>(); Set<String> uniqueCountryCodes = new HashSet<>();
for (int i = 0; i < mPendingApps.size(); ++i) { for (int i = 0; i < pendingApps.size(); ++i) {
@Nullable @Nullable
String countryCode = mPendingApps.get(i).getCountryCode(); String countryCode = pendingApps.get(i).getCountryCode();
if (countryCode != null && !uniqueCountryCodes.contains(countryCode)) { if (countryCode != null && !uniqueCountryCodes.contains(countryCode)) {
uniqueCountryCodes.add(countryCode); uniqueCountryCodes.add(countryCode);
PersonalDataManager.getInstance().loadRulesForAddressNormalization(countryCode); PersonalDataManager.getInstance().loadRulesForAddressNormalization(countryCode);
} }
} }
mPaymentUiService.rankPaymentAppsForPaymentRequestUI(mPendingApps); mPaymentUiService.rankPaymentAppsForPaymentRequestUI(pendingApps);
// Possibly pre-select the first app on the list. // 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 ? 0
: SectionInformation.NO_SELECTION; : SectionInformation.NO_SELECTION;
if (mIsCanMakePaymentResponsePending) {
respondCanMakePaymentQuery();
}
if (mIsHasEnrolledInstrumentResponsePending) {
respondHasEnrolledInstrumentQuery(mPaymentRequestService.getHasEnrolledInstrument());
}
// The list of payment apps is ready to display. // The list of payment apps is ready to display.
mPaymentUiService.setPaymentMethodsSection( mPaymentUiService.setPaymentMethodsSection(
new SectionInformation(PaymentRequestUI.DataType.PAYMENT_METHODS, selection, 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 // Record the number suggested payment methods and whether at least one of them was
// complete. // complete.
mJourneyLogger.setNumberOfSuggestionsShown(Section.PAYMENT_METHOD, mPendingApps.size(), mJourneyLogger.setNumberOfSuggestionsShown(Section.PAYMENT_METHOD, pendingApps.size(),
!mPendingApps.isEmpty() && mPendingApps.get(0).isComplete()); !pendingApps.isEmpty() && pendingApps.get(0).isComplete());
int missingFields = 0; int missingFields = 0;
if (mPendingApps.isEmpty()) { if (pendingApps.isEmpty()) {
if (mPaymentUiService.merchantSupportsAutofillCards()) { if (mPaymentUiService.merchantSupportsAutofillCards()) {
// Record all fields if basic-card is supported but no card exists. // Record all fields if basic-card is supported but no card exists.
missingFields = AutofillPaymentInstrument.CompletionStatus.CREDIT_CARD_EXPIRED missingFields = AutofillPaymentInstrument.CompletionStatus.CREDIT_CARD_EXPIRED
...@@ -1439,22 +1446,19 @@ public class ChromePaymentRequestService ...@@ -1439,22 +1446,19 @@ public class ChromePaymentRequestService
| AutofillPaymentInstrument.CompletionStatus.CREDIT_CARD_NO_NUMBER | AutofillPaymentInstrument.CompletionStatus.CREDIT_CARD_NO_NUMBER
| AutofillPaymentInstrument.CompletionStatus.CREDIT_CARD_NO_BILLING_ADDRESS; | AutofillPaymentInstrument.CompletionStatus.CREDIT_CARD_NO_BILLING_ADDRESS;
} }
} else if (mPendingApps.get(0).isAutofillInstrument()) { } else if (pendingApps.get(0).isAutofillInstrument()) {
missingFields = ((AutofillPaymentInstrument) (mPendingApps.get(0))).getMissingFields(); missingFields = ((AutofillPaymentInstrument) (pendingApps.get(0))).getMissingFields();
} }
if (missingFields != 0) { if (missingFields != 0) {
RecordHistogram.recordSparseHistogram( RecordHistogram.recordSparseHistogram(
"PaymentRequest.MissingPaymentFields", missingFields); "PaymentRequest.MissingPaymentFields", missingFields);
} }
mPendingApps.clear(); pendingApps.clear();
mPaymentUiService.updateAppModifiedTotals(); mPaymentUiService.updateAppModifiedTotals();
SettingsAutofillAndPaymentsObserver.getInstance().registerObserver(mPaymentUiService); 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