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

[PRImpl] Move ProvidePaymentInformation into UIsManager

Change:
* Separate ProvidePaymentInformation into two parts -
the business logic goes into recordShowEventAndTransactionAmount and
remains in PRImpl, the UI logic remains in providePaymentInformation
(renamed into providePaymentInformationToPaymentRequestUI for clarity)
and gets moved into PaymentUIsManager.
* For the sake of decoupling UI and the business logic in
enableUserInterfaceAfterPaymentRequestUpdateEvent(), the inline
business logic is moved out of the method.

Bug: 1102522

Change-Id: Ifb639c31bf0f3abcd56e415c8cce1d933a4fdd54
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2324571
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794231}
parent dc288e91
...@@ -1299,7 +1299,9 @@ public class PaymentRequestImpl ...@@ -1299,7 +1299,9 @@ public class PaymentRequestImpl
mPaymentUIsManager.getShippingAddressesSection().setErrorMessage(details.error); mPaymentUIsManager.getShippingAddressesSection().setErrorMessage(details.error);
} }
mPaymentUIsManager.enableUserInterfaceAfterPaymentRequestUpdateEvent(); boolean providedInformationToPaymentRequestUI =
mPaymentUIsManager.enableAndUpdatePaymentRequestUIWithPaymentInfo();
if (providedInformationToPaymentRequestUI) recordShowEventAndTransactionAmount();
} }
private void initializeWithUpdatedDetails(PaymentDetails details) { private void initializeWithUpdatedDetails(PaymentDetails details) {
...@@ -1343,7 +1345,9 @@ public class PaymentRequestImpl ...@@ -1343,7 +1345,9 @@ public class PaymentRequestImpl
triggerPaymentAppUiSkipIfApplicable(chromeActivity); triggerPaymentAppUiSkipIfApplicable(chromeActivity);
if (mIsFinishedQueryingPaymentApps && !mShouldSkipShowingPaymentRequestUi) { if (mIsFinishedQueryingPaymentApps && !mShouldSkipShowingPaymentRequestUi) {
mPaymentUIsManager.enableUserInterfaceAfterPaymentRequestUpdateEvent(); boolean providedInformationToPaymentRequestUI =
mPaymentUIsManager.enableAndUpdatePaymentRequestUIWithPaymentInfo();
if (providedInformationToPaymentRequestUI) recordShowEventAndTransactionAmount();
} }
} }
...@@ -1367,7 +1371,9 @@ public class PaymentRequestImpl ...@@ -1367,7 +1371,9 @@ public class PaymentRequestImpl
return; return;
} }
mPaymentUIsManager.enableUserInterfaceAfterPaymentRequestUpdateEvent(); boolean providedInformationToPaymentRequestUI =
mPaymentUIsManager.enableAndUpdatePaymentRequestUIWithPaymentInfo();
if (providedInformationToPaymentRequestUI) recordShowEventAndTransactionAmount();
} }
/** /**
...@@ -1457,27 +1463,15 @@ public class PaymentRequestImpl ...@@ -1457,27 +1463,15 @@ public class PaymentRequestImpl
if (mWaitForUpdatedDetails) return; if (mWaitForUpdatedDetails) return;
mHandler.post(() -> { mHandler.post(() -> {
if (mPaymentUIsManager.getPaymentRequestUI() != null) providePaymentInformation(); if (mPaymentUIsManager.getPaymentRequestUI() != null) {
mPaymentUIsManager.providePaymentInformationToPaymentRequestUI();
recordShowEventAndTransactionAmount();
}
}); });
} }
// Implement PaymentUIsManager.Delegate: private void recordShowEventAndTransactionAmount() {
@Override if (mDidRecordShowEvent) return;
public void providePaymentInformation() {
// Do not display service worker payment apps summary in single line so as to display its
// origin completely.
mPaymentUIsManager.getPaymentMethodsSection()
.setDisplaySelectedItemSummaryInSingleLineInNormalMode(
mPaymentUIsManager.getSelectedPaymentAppType()
!= PaymentAppType.SERVICE_WORKER_APP);
mPaymentUIsManager.getPaymentInformationCallback().onResult(new PaymentInformation(
mPaymentUIsManager.getUiShoppingCart(),
mPaymentUIsManager.getShippingAddressesSection(),
mPaymentUIsManager.getUiShippingOptions(), mPaymentUIsManager.getContactSection(),
mPaymentUIsManager.getPaymentMethodsSection()));
mPaymentUIsManager.setPaymentInformationCallback(null);
if (!mDidRecordShowEvent) {
mDidRecordShowEvent = true; mDidRecordShowEvent = true;
mJourneyLogger.setEventOccurred(Event.SHOWN); mJourneyLogger.setEventOccurred(Event.SHOWN);
// 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
...@@ -1489,7 +1483,6 @@ public class PaymentRequestImpl ...@@ -1489,7 +1483,6 @@ public class PaymentRequestImpl
mRawTotal.amount.currency, mRawTotal.amount.value, false /*completed*/); mRawTotal.amount.currency, mRawTotal.amount.value, false /*completed*/);
} }
} }
}
@Override @Override
public void getShoppingCart(final Callback<ShoppingCart> callback) { public void getShoppingCart(final Callback<ShoppingCart> callback) {
...@@ -1676,7 +1669,8 @@ public class PaymentRequestImpl ...@@ -1676,7 +1669,8 @@ public class PaymentRequestImpl
// information when cancelled). // information when cancelled).
mPaymentUIsManager.getShippingAddressesSection().setSelectedItemIndex( mPaymentUIsManager.getShippingAddressesSection().setSelectedItemIndex(
SectionInformation.NO_SELECTION); SectionInformation.NO_SELECTION);
providePaymentInformation(); mPaymentUIsManager.providePaymentInformationToPaymentRequestUI();
recordShowEventAndTransactionAmount();
} else { } else {
if (toEdit == null) { if (toEdit == null) {
// Address is complete and user was in the "Add flow": add an item to // Address is complete and user was in the "Add flow": add an item to
...@@ -1699,7 +1693,8 @@ public class PaymentRequestImpl ...@@ -1699,7 +1693,8 @@ public class PaymentRequestImpl
startShippingAddressChangeNormalization(editedAddress); startShippingAddressChangeNormalization(editedAddress);
} }
} else { } else {
providePaymentInformation(); mPaymentUIsManager.providePaymentInformationToPaymentRequestUI();
recordShowEventAndTransactionAmount();
} }
if (!mRetryQueue.isEmpty()) mHandler.post(mRetryQueue.remove()); if (!mRetryQueue.isEmpty()) mHandler.post(mRetryQueue.remove());
......
...@@ -77,8 +77,6 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob ...@@ -77,8 +77,6 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
/** The delegate of this class. */ /** The delegate of this class. */
public interface Delegate { public interface Delegate {
/** Provide payment information to the Payment Request UI. */
void providePaymentInformation();
} }
/** /**
...@@ -278,11 +276,6 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob ...@@ -278,11 +276,6 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
mUiShippingOptions = uiShippingOptions; mUiShippingOptions = uiShippingOptions;
} }
/** Get the PaymentInformation callback. */
public Callback<PaymentInformation> getPaymentInformationCallback() {
return mPaymentInformationCallback;
}
/** /**
* Set the call back of PaymentInformation. This callback would be invoked when the payment * Set the call back of PaymentInformation. This callback would be invoked when the payment
* information is retrieved. * information is retrieved.
...@@ -565,13 +558,17 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob ...@@ -565,13 +558,17 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
} }
/** /**
* Update Payment Request UI with the update event's information and enable the UI (The user * Update Payment Request UI with the update event's information and enable the UI. This method
* interface is disabled with a "↻" spinner being displayed and the user is unable to interact * should be called when the user interface is disabled with a "↻" spinner being displayed. The
* with the user interface until this "enableUserInterface" method is called). * user is unable to interact with the user interface until this method is called.
* @return Whether this is the first time that payment information has been provided to the user
* interface, which indicates that the "UI shown" event should be recorded now.
*/ */
public void enableUserInterfaceAfterPaymentRequestUpdateEvent() { public boolean enableAndUpdatePaymentRequestUIWithPaymentInfo() {
boolean isFirstUpdate = false;
if (mPaymentInformationCallback != null && mPaymentMethodsSection != null) { if (mPaymentInformationCallback != null && mPaymentMethodsSection != null) {
mDelegate.providePaymentInformation(); providePaymentInformationToPaymentRequestUI();
isFirstUpdate = true;
} else { } else {
mPaymentRequestUI.updateOrderSummarySection(mUiShoppingCart); mPaymentRequestUI.updateOrderSummarySection(mUiShoppingCart);
if (shouldShowShippingSection()) { if (shouldShowShippingSection()) {
...@@ -579,6 +576,7 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob ...@@ -579,6 +576,7 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
PaymentRequestUI.DataType.SHIPPING_OPTIONS, mUiShippingOptions); PaymentRequestUI.DataType.SHIPPING_OPTIONS, mUiShippingOptions);
} }
} }
return isFirstUpdate;
} }
/** Implements {@link PaymentRequestUI.Client.shouldShowShippingSection}. */ /** Implements {@link PaymentRequestUI.Client.shouldShowShippingSection}. */
...@@ -667,4 +665,16 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob ...@@ -667,4 +665,16 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
mPaymentHandlerUi.clickSecurityIconForTest(); mPaymentHandlerUi.clickSecurityIconForTest();
return true; return true;
} }
/** Provide PaymentInformation to the PaymentRequest UI. */
public void providePaymentInformationToPaymentRequestUI() {
// Do not display service worker payment apps summary in single line so as to display its
// origin completely.
mPaymentMethodsSection.setDisplaySelectedItemSummaryInSingleLineInNormalMode(
getSelectedPaymentAppType() != PaymentAppType.SERVICE_WORKER_APP);
mPaymentInformationCallback.onResult(
new PaymentInformation(mUiShoppingCart, mShippingAddressesSection,
mUiShippingOptions, mContactSection, mPaymentMethodsSection));
mPaymentInformationCallback = null;
}
} }
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