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
mPaymentUIsManager.getShippingAddressesSection().setErrorMessage(details.error);
}
mPaymentUIsManager.enableUserInterfaceAfterPaymentRequestUpdateEvent();
boolean providedInformationToPaymentRequestUI =
mPaymentUIsManager.enableAndUpdatePaymentRequestUIWithPaymentInfo();
if (providedInformationToPaymentRequestUI) recordShowEventAndTransactionAmount();
}
private void initializeWithUpdatedDetails(PaymentDetails details) {
......@@ -1343,7 +1345,9 @@ public class PaymentRequestImpl
triggerPaymentAppUiSkipIfApplicable(chromeActivity);
if (mIsFinishedQueryingPaymentApps && !mShouldSkipShowingPaymentRequestUi) {
mPaymentUIsManager.enableUserInterfaceAfterPaymentRequestUpdateEvent();
boolean providedInformationToPaymentRequestUI =
mPaymentUIsManager.enableAndUpdatePaymentRequestUIWithPaymentInfo();
if (providedInformationToPaymentRequestUI) recordShowEventAndTransactionAmount();
}
}
......@@ -1367,7 +1371,9 @@ public class PaymentRequestImpl
return;
}
mPaymentUIsManager.enableUserInterfaceAfterPaymentRequestUpdateEvent();
boolean providedInformationToPaymentRequestUI =
mPaymentUIsManager.enableAndUpdatePaymentRequestUIWithPaymentInfo();
if (providedInformationToPaymentRequestUI) recordShowEventAndTransactionAmount();
}
/**
......@@ -1457,27 +1463,15 @@ public class PaymentRequestImpl
if (mWaitForUpdatedDetails) return;
mHandler.post(() -> {
if (mPaymentUIsManager.getPaymentRequestUI() != null) providePaymentInformation();
if (mPaymentUIsManager.getPaymentRequestUI() != null) {
mPaymentUIsManager.providePaymentInformationToPaymentRequestUI();
recordShowEventAndTransactionAmount();
}
});
}
// Implement PaymentUIsManager.Delegate:
@Override
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) {
private void recordShowEventAndTransactionAmount() {
if (mDidRecordShowEvent) return;
mDidRecordShowEvent = true;
mJourneyLogger.setEventOccurred(Event.SHOWN);
// Record the triggered transaction amount only when the total amount in details is
......@@ -1489,7 +1483,6 @@ public class PaymentRequestImpl
mRawTotal.amount.currency, mRawTotal.amount.value, false /*completed*/);
}
}
}
@Override
public void getShoppingCart(final Callback<ShoppingCart> callback) {
......@@ -1676,7 +1669,8 @@ public class PaymentRequestImpl
// information when cancelled).
mPaymentUIsManager.getShippingAddressesSection().setSelectedItemIndex(
SectionInformation.NO_SELECTION);
providePaymentInformation();
mPaymentUIsManager.providePaymentInformationToPaymentRequestUI();
recordShowEventAndTransactionAmount();
} else {
if (toEdit == null) {
// Address is complete and user was in the "Add flow": add an item to
......@@ -1699,7 +1693,8 @@ public class PaymentRequestImpl
startShippingAddressChangeNormalization(editedAddress);
}
} else {
providePaymentInformation();
mPaymentUIsManager.providePaymentInformationToPaymentRequestUI();
recordShowEventAndTransactionAmount();
}
if (!mRetryQueue.isEmpty()) mHandler.post(mRetryQueue.remove());
......
......@@ -77,8 +77,6 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
/** The delegate of this class. */
public interface Delegate {
/** Provide payment information to the Payment Request UI. */
void providePaymentInformation();
}
/**
......@@ -278,11 +276,6 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
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
* information is retrieved.
......@@ -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
* interface is disabled with a "↻" spinner being displayed and the user is unable to interact
* with the user interface until this "enableUserInterface" method is called).
* Update Payment Request UI with the update event's information and enable the UI. This method
* should be called when the user interface is disabled with a "↻" spinner being displayed. The
* 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) {
mDelegate.providePaymentInformation();
providePaymentInformationToPaymentRequestUI();
isFirstUpdate = true;
} else {
mPaymentRequestUI.updateOrderSummarySection(mUiShoppingCart);
if (shouldShowShippingSection()) {
......@@ -579,6 +576,7 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
PaymentRequestUI.DataType.SHIPPING_OPTIONS, mUiShippingOptions);
}
}
return isFirstUpdate;
}
/** Implements {@link PaymentRequestUI.Client.shouldShowShippingSection}. */
......@@ -667,4 +665,16 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
mPaymentHandlerUi.clickSecurityIconForTest();
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