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 ...@@ -216,7 +216,7 @@ public class ChromePaymentRequestService
// Implements BrowserPaymentRequest: // Implements BrowserPaymentRequest:
@Override @Override
public boolean showAppSelector(boolean isShowWaitingForUpdatedDetails, PaymentItem total, public String showAppSelector(boolean isShowWaitingForUpdatedDetails, PaymentItem total,
PaymentOptions paymentOptions) { PaymentOptions paymentOptions) {
assert mPaymentRequestService assert mPaymentRequestService
!= null : "This method is only supposed to be called by mPaymentRequestService."; != null : "This method is only supposed to be called by mPaymentRequestService.";
...@@ -231,23 +231,16 @@ public class ChromePaymentRequestService ...@@ -231,23 +231,16 @@ public class ChromePaymentRequestService
mPaymentRequestService.isUserGestureShow(), mDelegate.skipUiForBasicCard(), mPaymentRequestService.isUserGestureShow(), mDelegate.skipUiForBasicCard(),
mSpec.getPaymentOptions(), mSpec.getMethodData().keySet()); mSpec.getPaymentOptions(), mSpec.getMethodData().keySet());
ChromeActivity chromeActivity = ChromeActivity.fromWebContents(mWebContents); ChromeActivity chromeActivity = ChromeActivity.fromWebContents(mWebContents);
if (quitShowIfActivityNotFound(chromeActivity)) return false; if (chromeActivity == null) return ErrorStrings.ACTIVITY_NOT_FOUND;
String error = mPaymentUiService.buildPaymentRequestUI(chromeActivity, String error = mPaymentUiService.buildPaymentRequestUI(chromeActivity,
/*isWebContentsActive=*/ /*isWebContentsActive=*/
PaymentRequestServiceUtil.isWebContentsActive(mRenderFrameHost), PaymentRequestServiceUtil.isWebContentsActive(mRenderFrameHost),
/*isShowWaitingForUpdatedDetails=*/isShowWaitingForUpdatedDetails); /*isShowWaitingForUpdatedDetails=*/isShowWaitingForUpdatedDetails);
if (error != null) { if (error != null) return error;
mJourneyLogger.setNotShown(NotShownReason.OTHER);
disconnectFromClientWithDebugMessage(error);
if (PaymentRequestService.getObserverForTest() != null) {
PaymentRequestService.getObserverForTest().onPaymentRequestServiceShowFailed();
}
return false;
}
if (!mPaymentUiService.shouldSkipShowingPaymentRequestUi() && mSkipToGPayHelper == null) { if (!mPaymentUiService.shouldSkipShowingPaymentRequestUi() && mSkipToGPayHelper == null) {
mPaymentUiService.getPaymentRequestUI().show(isShowWaitingForUpdatedDetails); mPaymentUiService.getPaymentRequestUI().show(isShowWaitingForUpdatedDetails);
} }
return true; return null;
} }
private void dimBackgroundIfNotBottomSheetPaymentHandler(PaymentApp selectedApp) { private void dimBackgroundIfNotBottomSheetPaymentHandler(PaymentApp selectedApp) {
...@@ -266,19 +259,6 @@ public class ChromePaymentRequestService ...@@ -266,19 +259,6 @@ public class ChromePaymentRequestService
mPaymentUiService.getPaymentRequestUI().dimBackground(); 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: // Implements BrowserPaymentRequest:
@Override @Override
public void triggerPaymentAppUiSkipIfApplicable() { public void triggerPaymentAppUiSkipIfApplicable() {
...@@ -293,7 +273,15 @@ public class ChromePaymentRequestService ...@@ -293,7 +273,15 @@ public class ChromePaymentRequestService
if (isMinimalUiApplicable()) { if (isMinimalUiApplicable()) {
ChromeActivity chromeActivity = ChromeActivity.fromWebContents(mWebContents); 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(), if (mPaymentUiService.triggerMinimalUI(chromeActivity, mSpec.getRawTotal(),
this::onMinimalUIReady, this::onMinimalUiConfirmed, this::onMinimalUIReady, this::onMinimalUiConfirmed,
/*dismissObserver=*/ /*dismissObserver=*/
......
...@@ -127,13 +127,15 @@ public interface BrowserPaymentRequest { ...@@ -127,13 +127,15 @@ public interface BrowserPaymentRequest {
/** /**
* Shows the payment apps selector. * Shows the payment apps selector.
* @param isShowWaitingForUpdatedDetails Whether {@link PaymentRequest#show} is waiting for the * @param isShowWaitingForUpdatedDetails Whether {@link PaymentRequest#show} is waiting for the
* updated details.
* @param total The total amount specified in the payment request. * @param total The total amount specified in the payment request.
* @param paymentOptions The payment options 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) { PaymentOptions paymentOptions) {
return false; return null;
} }
/** /**
......
...@@ -666,10 +666,15 @@ public class PaymentRequestService ...@@ -666,10 +666,15 @@ public class PaymentRequestService
mBrowserPaymentRequest.notifyPaymentUiOfPendingApps(mPendingApps); mBrowserPaymentRequest.notifyPaymentUiOfPendingApps(mPendingApps);
mPendingApps.clear(); mPendingApps.clear();
if (isCurrentPaymentRequestShowing() if (isCurrentPaymentRequestShowing()) {
&& !mBrowserPaymentRequest.showAppSelector(mIsShowWaitingForUpdatedDetails, String error = mBrowserPaymentRequest.showAppSelector(mIsShowWaitingForUpdatedDetails,
mSpec.getRawTotal(), mSpec.getPaymentOptions())) { mSpec.getRawTotal(), mSpec.getPaymentOptions());
return; if (error != null) {
mJourneyLogger.setNotShown(NotShownReason.OTHER);
disconnectFromClientWithDebugMessage(error, PaymentErrorReason.USER_CANCEL);
if (sObserverForTest != null) sObserverForTest.onPaymentRequestServiceShowFailed();
return;
}
} }
mBrowserPaymentRequest.triggerPaymentAppUiSkipIfApplicable(); mBrowserPaymentRequest.triggerPaymentAppUiSkipIfApplicable();
...@@ -936,10 +941,15 @@ public class PaymentRequestService ...@@ -936,10 +941,15 @@ public class PaymentRequestService
if (disconnectIfNoPaymentMethodsSupported(mBrowserPaymentRequest.hasAvailableApps())) { if (disconnectIfNoPaymentMethodsSupported(mBrowserPaymentRequest.hasAvailableApps())) {
return; return;
} }
if (isFinishedQueryingPaymentApps() if (isFinishedQueryingPaymentApps()) {
&& !mBrowserPaymentRequest.showAppSelector(mIsShowWaitingForUpdatedDetails, String error = mBrowserPaymentRequest.showAppSelector(mIsShowWaitingForUpdatedDetails,
mSpec.getRawTotal(), mSpec.getPaymentOptions())) { mSpec.getRawTotal(), mSpec.getPaymentOptions());
return; if (error != null) {
mJourneyLogger.setNotShown(NotShownReason.OTHER);
disconnectFromClientWithDebugMessage(error, PaymentErrorReason.USER_CANCEL);
if (sObserverForTest != null) sObserverForTest.onPaymentRequestServiceShowFailed();
return;
}
} }
mBrowserPaymentRequest.triggerPaymentAppUiSkipIfApplicable(); 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