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

[WebLayer] Compute isUrlPaymentMethodIdentifiersSupported on demand

Currently, mIsUrlPaymentMethodIdentifiersSupported is computed whether
it's used or not. This CL is to turn the computation into a method, and
compute it only when it's needed.

This change will also help moving
JourneyLogger.setRequestedPaymentMethodTypes into PRService.

Bug: 1131059

Change-Id: I405631119a6bf6d6dce467335ea1c53dcb37ba1c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2537138
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827816}
parent 66495856
......@@ -18,7 +18,6 @@ import org.chromium.chrome.browser.payments.ui.PaymentRequestUI;
import org.chromium.chrome.browser.payments.ui.PaymentUiService;
import org.chromium.chrome.browser.payments.ui.SectionInformation;
import org.chromium.components.autofill.EditableOption;
import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.components.payments.AbortReason;
import org.chromium.components.payments.BrowserPaymentRequest;
import org.chromium.components.payments.ErrorStrings;
......@@ -89,11 +88,6 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest,
private boolean mHideServerAutofillCards;
private PaymentHandlerHost mPaymentHandlerHost;
/**
* True when at least one url payment method identifier is specified in payment request.
*/
private boolean mURLPaymentMethodIdentifiersSupported;
/**
* There are a few situations were the Payment Request can appear, from a code perspective, to
* be shown more than once. This boolean is used to make sure it is only logged once.
......@@ -164,12 +158,10 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest,
// specified networks are unsupported. mPaymentUiService.merchantSupportsAutofillCards()
// better captures this group of interest than requestedMethodBasicCard.
boolean requestedMethodOther = false;
mURLPaymentMethodIdentifiersSupported = false;
for (String methodName : mSpec.getMethodData().keySet()) {
switch (methodName) {
case MethodStrings.ANDROID_PAY:
case MethodStrings.GOOGLE_PAY:
mURLPaymentMethodIdentifiersSupported = true;
requestedMethodGoogle = true;
break;
case MethodStrings.BASIC_CARD:
......@@ -180,10 +172,6 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest,
// "Other" includes https url, http url(when certificate check is bypassed) and
// the unlisted methods defined in {@link MethodStrings}.
requestedMethodOther = true;
if (methodName.startsWith(UrlConstants.HTTPS_URL_PREFIX)
|| methodName.startsWith(UrlConstants.HTTP_URL_PREFIX)) {
mURLPaymentMethodIdentifiersSupported = true;
}
}
}
mJourneyLogger.setRequestedPaymentMethodTypes(
......@@ -286,8 +274,8 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest,
// Calculate skip ui and build ui only after all payment apps are ready and
// request.show() is called.
mPaymentUiService.calculateWhetherShouldSkipShowingPaymentRequestUi(
mPaymentRequestService.isUserGestureShow(), mURLPaymentMethodIdentifiersSupported,
mDelegate.skipUiForBasicCard(), paymentOptions);
mPaymentRequestService.isUserGestureShow(), mDelegate.skipUiForBasicCard(),
mSpec.getPaymentOptions(), mSpec.getMethodData().keySet());
ChromeActivity chromeActivity = ChromeActivity.fromWebContents(mWebContents);
if (quitShowIfActivityNotFound(chromeActivity)
|| !buildUI(chromeActivity, isShowWaitingForUpdatedDetails)) {
......
......@@ -52,6 +52,7 @@ import org.chromium.chrome.browser.ui.favicon.FaviconHelper;
import org.chromium.components.autofill.Completable;
import org.chromium.components.autofill.EditableOption;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetControllerProvider;
import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.components.payments.AbortReason;
import org.chromium.components.payments.BasicCardUtils;
import org.chromium.components.payments.CurrencyFormatter;
......@@ -1437,21 +1438,38 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
updateAppModifiedTotals();
}
/**
* @param methods The payment methods supported by the payment request.
* @return True when at least one url payment method identifier is specified in payment
* request.
*/
private static boolean isUrlPaymentMethodIdentifiersSupported(Set<String> methods) {
for (String methodName : methods) {
if (methodName.startsWith(UrlConstants.HTTPS_URL_PREFIX)
|| methodName.startsWith(UrlConstants.HTTP_URL_PREFIX)) {
return true;
}
}
return false;
}
/**
* Calculate whether the browser payment sheet should be skipped directly into the payment app.
* @param isUserGestureShow Whether the PaymentRequest.show() is triggered by user gesture.
* @param urlPaymentMethodIdentifiersSupported True when at least one url payment method
* identifier is specified in payment request.
* @param skipUiForNonUrlPaymentMethodIdentifiers True when skip UI is available for non-url
* based payment method identifiers (e.g., basic-card).
* @param options The payment options specified in the payment request.
* @param paymentMethods The payment methods supported by this request.
*/
public void calculateWhetherShouldSkipShowingPaymentRequestUi(boolean isUserGestureShow,
boolean urlPaymentMethodIdentifiersSupported,
boolean skipUiForNonUrlPaymentMethodIdentifiers, PaymentOptions options) {
boolean skipUiForNonUrlPaymentMethodIdentifiers, PaymentOptions options,
Set<String> paymentMethods) {
assert mPaymentMethodsSection != null;
PaymentApp selectedApp = (PaymentApp) mPaymentMethodsSection.getSelectedItem();
boolean urlPaymentMethodIdentifiersSupported =
isUrlPaymentMethodIdentifiersSupported(paymentMethods);
// If there is only a single payment app which can provide all merchant requested
// information, we can safely go directly to the payment app instead of showing Payment
// Request UI.
......
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