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

[WebLayer] Move error handling out of showAppSelector()

Before the CL, the error handling logic lives in
CPRService#showAppSelector().

After the CL, CPRService#showAppSelector() returns the error to
PRService, and PRService handles the error.

Bug: 1148902

Change-Id: I992b449eb5d406db6c110ce9d300c6b68afd5528
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2536996Reviewed-by: default avatarNick Burris <nburris@chromium.org>
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828019}
parent 467c11b8
......@@ -216,7 +216,7 @@ public class ChromePaymentRequestService
// Implements BrowserPaymentRequest:
@Override
public boolean showAppSelector(boolean isShowWaitingForUpdatedDetails, PaymentItem total,
public String showAppSelector(boolean isShowWaitingForUpdatedDetails, PaymentItem total,
PaymentOptions paymentOptions) {
assert mPaymentRequestService
!= null : "This method is only supposed to be called by mPaymentRequestService.";
......@@ -231,23 +231,16 @@ public class ChromePaymentRequestService
mPaymentRequestService.isUserGestureShow(), mDelegate.skipUiForBasicCard(),
mSpec.getPaymentOptions(), mSpec.getMethodData().keySet());
ChromeActivity chromeActivity = ChromeActivity.fromWebContents(mWebContents);
if (quitShowIfActivityNotFound(chromeActivity)) return false;
if (chromeActivity == null) return ErrorStrings.ACTIVITY_NOT_FOUND;
String error = mPaymentUiService.buildPaymentRequestUI(chromeActivity,
/*isWebContentsActive=*/
PaymentRequestServiceUtil.isWebContentsActive(mRenderFrameHost),
/*isShowWaitingForUpdatedDetails=*/isShowWaitingForUpdatedDetails);
if (error != null) {
mJourneyLogger.setNotShown(NotShownReason.OTHER);
disconnectFromClientWithDebugMessage(error);
if (PaymentRequestService.getObserverForTest() != null) {
PaymentRequestService.getObserverForTest().onPaymentRequestServiceShowFailed();
}
return false;
}
if (error != null) return error;
if (!mPaymentUiService.shouldSkipShowingPaymentRequestUi() && mSkipToGPayHelper == null) {
mPaymentUiService.getPaymentRequestUI().show(isShowWaitingForUpdatedDetails);
}
return true;
return null;
}
private void dimBackgroundIfNotBottomSheetPaymentHandler(PaymentApp selectedApp) {
......@@ -266,19 +259,6 @@ public class ChromePaymentRequestService
mPaymentUiService.getPaymentRequestUI().dimBackground();
}
/** @return True if show() is quited. */
private boolean quitShowIfActivityNotFound(@Nullable ChromeActivity chromeActivity) {
if (chromeActivity == null) {
mJourneyLogger.setNotShown(NotShownReason.OTHER);
disconnectFromClientWithDebugMessage(ErrorStrings.ACTIVITY_NOT_FOUND);
if (PaymentRequestService.getObserverForTest() != null) {
PaymentRequestService.getObserverForTest().onPaymentRequestServiceShowFailed();
}
return true;
}
return false;
}
// Implements BrowserPaymentRequest:
@Override
public void triggerPaymentAppUiSkipIfApplicable() {
......@@ -293,7 +273,15 @@ public class ChromePaymentRequestService
if (isMinimalUiApplicable()) {
ChromeActivity chromeActivity = ChromeActivity.fromWebContents(mWebContents);
if (quitShowIfActivityNotFound(chromeActivity)) return;
if (chromeActivity == null) {
mJourneyLogger.setNotShown(NotShownReason.OTHER);
disconnectFromClientWithDebugMessage(ErrorStrings.ACTIVITY_NOT_FOUND);
if (PaymentRequestService.getObserverForTest() != null) {
PaymentRequestService.getObserverForTest()
.onPaymentRequestServiceShowFailed();
}
return;
}
if (mPaymentUiService.triggerMinimalUI(chromeActivity, mSpec.getRawTotal(),
this::onMinimalUIReady, this::onMinimalUiConfirmed,
/*dismissObserver=*/
......
......@@ -127,13 +127,15 @@ public interface BrowserPaymentRequest {
/**
* Shows the payment apps selector.
* @param isShowWaitingForUpdatedDetails Whether {@link PaymentRequest#show} is waiting for the
* updated details.
* @param total The total amount specified in the payment request.
* @param paymentOptions The payment options specified in the payment request.
* @return Whether the showing is successful.
* @return The error of the showing if any; null if success.
*/
default boolean showAppSelector(boolean isShowWaitingForUpdatedDetails, PaymentItem total,
@Nullable
default String showAppSelector(boolean isShowWaitingForUpdatedDetails, PaymentItem total,
PaymentOptions paymentOptions) {
return false;
return null;
}
/**
......
......@@ -666,10 +666,15 @@ public class PaymentRequestService
mBrowserPaymentRequest.notifyPaymentUiOfPendingApps(mPendingApps);
mPendingApps.clear();
if (isCurrentPaymentRequestShowing()
&& !mBrowserPaymentRequest.showAppSelector(mIsShowWaitingForUpdatedDetails,
mSpec.getRawTotal(), mSpec.getPaymentOptions())) {
return;
if (isCurrentPaymentRequestShowing()) {
String error = mBrowserPaymentRequest.showAppSelector(mIsShowWaitingForUpdatedDetails,
mSpec.getRawTotal(), mSpec.getPaymentOptions());
if (error != null) {
mJourneyLogger.setNotShown(NotShownReason.OTHER);
disconnectFromClientWithDebugMessage(error, PaymentErrorReason.USER_CANCEL);
if (sObserverForTest != null) sObserverForTest.onPaymentRequestServiceShowFailed();
return;
}
}
mBrowserPaymentRequest.triggerPaymentAppUiSkipIfApplicable();
......@@ -936,10 +941,15 @@ public class PaymentRequestService
if (disconnectIfNoPaymentMethodsSupported(mBrowserPaymentRequest.hasAvailableApps())) {
return;
}
if (isFinishedQueryingPaymentApps()
&& !mBrowserPaymentRequest.showAppSelector(mIsShowWaitingForUpdatedDetails,
mSpec.getRawTotal(), mSpec.getPaymentOptions())) {
return;
if (isFinishedQueryingPaymentApps()) {
String error = mBrowserPaymentRequest.showAppSelector(mIsShowWaitingForUpdatedDetails,
mSpec.getRawTotal(), mSpec.getPaymentOptions());
if (error != null) {
mJourneyLogger.setNotShown(NotShownReason.OTHER);
disconnectFromClientWithDebugMessage(error, PaymentErrorReason.USER_CANCEL);
if (sObserverForTest != null) sObserverForTest.onPaymentRequestServiceShowFailed();
return;
}
}
mBrowserPaymentRequest.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