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

[WebLayer] Clean up mPaymentRequestService in CPRService

* Null-check mPaymentRequestService for its uses in the
  non-BrowserPRSservice interface implementation methods. This is in
  case other interfaces might use mPaymentRequestService after its
  closing.
* Removed the unnecessary mPaymentRequestService null-checks when it is
  not used in the method.

Bug: 1025619

Change-Id: Ic4fddfcb7279db09dfbfdc35f89c9c836dfaf420
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2543375
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarNick Burris <nburris@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828473}
parent 4c1cd7be
...@@ -119,16 +119,15 @@ public class ChromePaymentRequestService ...@@ -119,16 +119,15 @@ public class ChromePaymentRequestService
mPaymentRequestService = paymentRequestService; mPaymentRequestService = paymentRequestService;
mRenderFrameHost = paymentRequestService.getRenderFrameHost(); mRenderFrameHost = paymentRequestService.getRenderFrameHost();
assert mRenderFrameHost != null; assert mRenderFrameHost != null;
String topLevelOrigin = paymentRequestService.getTopLevelOrigin();
assert topLevelOrigin != null;
mDelegate = delegate; mDelegate = delegate;
mWebContents = paymentRequestService.getWebContents(); mWebContents = paymentRequestService.getWebContents();
mJourneyLogger = paymentRequestService.getJourneyLogger(); mJourneyLogger = paymentRequestService.getJourneyLogger();
String topLevelOrigin = paymentRequestService.getTopLevelOrigin();
mPaymentRequestService = paymentRequestService; assert topLevelOrigin != null;
mPaymentUiService = new PaymentUiService(/*delegate=*/this, mPaymentUiService = new PaymentUiService(/*delegate=*/this,
/*params=*/mPaymentRequestService, mWebContents, /*params=*/paymentRequestService, mWebContents,
paymentRequestService.isOffTheRecord(), mJourneyLogger, topLevelOrigin); paymentRequestService.isOffTheRecord(), mJourneyLogger, topLevelOrigin);
mPaymentRequestService = paymentRequestService;
if (PaymentRequestService.getNativeObserverForTest() != null) { if (PaymentRequestService.getNativeObserverForTest() != null) {
PaymentRequestService.getNativeObserverForTest().onPaymentUiServiceCreated( PaymentRequestService.getNativeObserverForTest().onPaymentUiServiceCreated(
mPaymentUiService); mPaymentUiService);
...@@ -155,7 +154,6 @@ public class ChromePaymentRequestService ...@@ -155,7 +154,6 @@ public class ChromePaymentRequestService
public boolean disconnectIfExtraValidationFails(WebContents webContents, public boolean disconnectIfExtraValidationFails(WebContents webContents,
Map<String, PaymentMethodData> methodData, PaymentDetails details, Map<String, PaymentMethodData> methodData, PaymentDetails details,
PaymentOptions options) { PaymentOptions options) {
assert mPaymentRequestService != null;
assert methodData != null; assert methodData != null;
assert details != null; assert details != null;
...@@ -219,8 +217,6 @@ public class ChromePaymentRequestService ...@@ -219,8 +217,6 @@ public class ChromePaymentRequestService
@Override @Override
public String showAppSelector(boolean isShowWaitingForUpdatedDetails, PaymentItem total, public String showAppSelector(boolean isShowWaitingForUpdatedDetails, PaymentItem total,
PaymentOptions paymentOptions, boolean isUserGestureShow) { PaymentOptions paymentOptions, boolean isUserGestureShow) {
assert mPaymentRequestService
!= null : "This method is only supposed to be called by mPaymentRequestService.";
// Send AppListReady signal when all apps are created and request.show() is called. // Send AppListReady signal when all apps are created and request.show() is called.
if (PaymentRequestService.getNativeObserverForTest() != null) { if (PaymentRequestService.getNativeObserverForTest() != null) {
PaymentRequestService.getNativeObserverForTest().onAppListReady( PaymentRequestService.getNativeObserverForTest().onAppListReady(
...@@ -295,7 +291,6 @@ public class ChromePaymentRequestService ...@@ -295,7 +291,6 @@ public class ChromePaymentRequestService
assert mSpec.getRawTotal() != null; assert mSpec.getRawTotal() != null;
// The total amount in details should be finalized at this point. So it is safe to // The total amount in details should be finalized at this point. So it is safe to
// record the triggered transaction amount. // record the triggered transaction amount.
assert !mPaymentRequestService.isShowWaitingForUpdatedDetails();
mJourneyLogger.recordTransactionAmount(mSpec.getRawTotal().amount.currency, mJourneyLogger.recordTransactionAmount(mSpec.getRawTotal().amount.currency,
mSpec.getRawTotal().amount.value, false /*completed*/); mSpec.getRawTotal().amount.value, false /*completed*/);
invokePaymentApp(null /* selectedShippingAddress */, null /* selectedShippingOption */, invokePaymentApp(null /* selectedShippingAddress */, null /* selectedShippingOption */,
...@@ -379,13 +374,10 @@ public class ChromePaymentRequestService ...@@ -379,13 +374,10 @@ public class ChromePaymentRequestService
return paymentHandlerWebContents; return paymentHandlerWebContents;
} }
// Implement BrowserPaymentRequest: // Implements BrowserPaymentRequest:
@Override @Override
public void onPaymentDetailsUpdated( public void onPaymentDetailsUpdated(
PaymentDetails details, boolean hasNotifiedInvokedPaymentApp) { PaymentDetails details, boolean hasNotifiedInvokedPaymentApp) {
// This method is only called from mPaymentRequestService.
assert mPaymentRequestService != null;
mPaymentUiService.updateDetailsOnPaymentRequestUI(details); mPaymentUiService.updateDetailsOnPaymentRequestUI(details);
if (hasNotifiedInvokedPaymentApp) return; if (hasNotifiedInvokedPaymentApp) return;
...@@ -441,12 +433,9 @@ public class ChromePaymentRequestService ...@@ -441,12 +433,9 @@ public class ChromePaymentRequestService
return null; return null;
} }
// Implement BrowserPaymentRequest: // Implements BrowserPaymentRequest:
@Override @Override
public void onPaymentDetailsNotUpdated(@Nullable String selectedShippingOptionError) { public void onPaymentDetailsNotUpdated(@Nullable String selectedShippingOptionError) {
// This method is only supposed to be called by mPaymentRequestService.
assert mPaymentRequestService != null;
if (mPaymentUiService.shouldShowShippingSection() if (mPaymentUiService.shouldShowShippingSection()
&& (mPaymentUiService.getUiShippingOptions().isEmpty() && (mPaymentUiService.getUiShippingOptions().isEmpty()
|| !TextUtils.isEmpty(mSpec.selectedShippingOptionError())) || !TextUtils.isEmpty(mSpec.selectedShippingOptionError()))
...@@ -478,7 +467,8 @@ public class ChromePaymentRequestService ...@@ -478,7 +467,8 @@ public class ChromePaymentRequestService
// Record the triggered transaction amount only when the total amount in details is // Record the triggered transaction amount only when the total amount in details is
// finalized (i.e. mPaymentRequestService.isShowWaitingForUpdatedDetails() == false). // finalized (i.e. mPaymentRequestService.isShowWaitingForUpdatedDetails() == false).
// Otherwise it will get recorded when the updated details become available. // Otherwise it will get recorded when the updated details become available.
if (!mPaymentRequestService.isShowWaitingForUpdatedDetails()) { if (mPaymentRequestService != null
&& !mPaymentRequestService.isShowWaitingForUpdatedDetails()) {
assert mSpec.getRawTotal() != null; assert mSpec.getRawTotal() != null;
mJourneyLogger.recordTransactionAmount(mSpec.getRawTotal().amount.currency, mJourneyLogger.recordTransactionAmount(mSpec.getRawTotal().amount.currency,
mSpec.getRawTotal().amount.value, false /*completed*/); mSpec.getRawTotal().amount.value, false /*completed*/);
...@@ -501,7 +491,7 @@ public class ChromePaymentRequestService ...@@ -501,7 +491,7 @@ public class ChromePaymentRequestService
@Override @Override
public boolean invokePaymentApp(EditableOption selectedShippingAddress, public boolean invokePaymentApp(EditableOption selectedShippingAddress,
EditableOption selectedShippingOption, PaymentApp selectedPaymentApp) { EditableOption selectedShippingOption, PaymentApp selectedPaymentApp) {
if (mSpec == null || mSpec.isDestroyed()) return false; if (mPaymentRequestService == null || mSpec == null || mSpec.isDestroyed()) return false;
EditableOption selectedContact = mPaymentUiService.getContactSection() != null EditableOption selectedContact = mPaymentUiService.getContactSection() != null
? mPaymentUiService.getContactSection().getSelectedItem() ? mPaymentUiService.getContactSection().getSelectedItem()
: null; : null;
...@@ -552,12 +542,9 @@ public class ChromePaymentRequestService ...@@ -552,12 +542,9 @@ public class ChromePaymentRequestService
assert mHasClosed; assert mHasClosed;
} }
// Implement BrowserPaymentRequest: // Implements BrowserPaymentRequest:
@Override @Override
public void complete(int result, Runnable onCompleteHandled) { public void complete(int result, Runnable onCompleteHandled) {
// This method is only supposed to be called by mPaymentRequestService.
assert mPaymentRequestService != null;
if (result != PaymentComplete.FAIL && !PaymentPreferencesUtil.isPaymentCompleteOnce()) { if (result != PaymentComplete.FAIL && !PaymentPreferencesUtil.isPaymentCompleteOnce()) {
PaymentPreferencesUtil.setPaymentCompleteOnce(); PaymentPreferencesUtil.setPaymentCompleteOnce();
} }
...@@ -566,14 +553,14 @@ public class ChromePaymentRequestService ...@@ -566,14 +553,14 @@ public class ChromePaymentRequestService
/*onMinimalUiErroredAndClosed=*/this::close, onCompleteHandled); /*onMinimalUiErroredAndClosed=*/this::close, onCompleteHandled);
} }
// Implement BrowserPaymentRequest: // Implements BrowserPaymentRequest:
@Override @Override
public void retry(PaymentValidationErrors errors) { public void retry(PaymentValidationErrors errors) {
mWasRetryCalled = true; mWasRetryCalled = true;
mPaymentUiService.onRetry(errors); mPaymentUiService.onRetry(errors);
} }
// Implement BrowserPaymentRequest: // Implements BrowserPaymentRequest:
@Override @Override
public void close() { public void close() {
if (mHasClosed) return; if (mHasClosed) return;
...@@ -749,7 +736,6 @@ public class ChromePaymentRequestService ...@@ -749,7 +736,6 @@ public class ChromePaymentRequestService
// Implement PaymentUiService.Delegate: // Implement PaymentUiService.Delegate:
@Override @Override
public void onLeavingCurrentTab(String reason) { public void onLeavingCurrentTab(String reason) {
if (mPaymentRequestService == null) return;
mJourneyLogger.setAborted(AbortReason.ABORTED_BY_USER); mJourneyLogger.setAborted(AbortReason.ABORTED_BY_USER);
disconnectFromClientWithDebugMessage(reason); disconnectFromClientWithDebugMessage(reason);
} }
......
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