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

[WebLayer] Simplify updateDetailsOnPaymentRequestUI

Before the CL, the method "updateDetailsOnPaymentRequestUI" took
"details", "rawTotal" and "rawLineItems". However, "rawTotal" and
"rawLineItems" can be extracted from "details" directly. So this CL
changes the method to provide only details.

Also, these variables were provided by
PaymentRequestSpec#getRawLineItems(), PaymentRequestSpec#getRawTotal(),
and PaymentRequestSpec#getPaymentDetails() which are all expensive
computation. This CL can help reducing the usage.

Change-Id: I742e8493f1a3cb9b746882ff561badc656b4318d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2533143
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826540}
parent 21fca649
......@@ -162,8 +162,7 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest,
@Override
public void onSpecValidated(PaymentRequestSpec spec) {
mSpec = spec;
mPaymentUiService.initialize(
mSpec.getPaymentDetails(), mSpec.getRawTotal(), mSpec.getRawLineItems());
mPaymentUiService.initialize(mSpec.getPaymentDetails());
// Log the various types of payment methods that were requested by the merchant.
boolean requestedMethodGoogle = false;
......@@ -482,8 +481,7 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest,
// mSpec.updateWith() can be used only when mSpec has not been destroyed.
assert !mSpec.isDestroyed();
mPaymentUiService.updateDetailsOnPaymentRequestUI(
mSpec.getPaymentDetails(), mSpec.getRawTotal(), mSpec.getRawLineItems());
mPaymentUiService.updateDetailsOnPaymentRequestUI(mSpec.getPaymentDetails());
if (hasNotifiedInvokedPaymentApp) return;
......@@ -512,8 +510,7 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest,
return;
}
mPaymentUiService.updateDetailsOnPaymentRequestUI(
mSpec.getPaymentDetails(), mSpec.getRawTotal(), mSpec.getRawLineItems());
mPaymentUiService.updateDetailsOnPaymentRequestUI(mSpec.getPaymentDetails());
// Do not create shipping section When UI is not built yet. This happens when the show
// promise gets resolved before all apps are ready.
......
......@@ -539,14 +539,10 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
/**
* Initializes the payment UI service.
* @param details The PaymentDetails provided by the merchant.
* @param rawTotal The raw total amount being charged.
* @param rawLineItems The raw items in the shopping cart, as they were received from the
* merchant page.
*/
public void initialize(
PaymentDetails details, PaymentItem rawTotal, List<PaymentItem> rawLineItems) {
public void initialize(PaymentDetails details) {
assert !mParams.hasClosed();
updateDetailsOnPaymentRequestUI(details, rawTotal, rawLineItems);
updateDetailsOnPaymentRequestUI(details);
for (PaymentMethodData method : mParams.getMethodData().values()) {
mCardEditor.addAcceptedPaymentMethodIfRecognized(method);
}
......@@ -1417,18 +1413,18 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
/**
* Update the details related fields on the PaymentRequest UI.
* @param details The details whose information is used for the update.
* @param rawTotal The raw total parsed from the details to be used for the update.
* @param rawLineItems The raw line items parsed from the details to be used for the update.
*/
public void updateDetailsOnPaymentRequestUI(
PaymentDetails details, PaymentItem rawTotal, List<PaymentItem> rawLineItems) {
public void updateDetailsOnPaymentRequestUI(PaymentDetails details) {
loadCurrencyFormattersForPaymentDetails(details);
// Total is never pending.
CurrencyFormatter formatter = getOrCreateCurrencyFormatter(rawTotal.amount);
LineItem uiTotal = new LineItem(rawTotal.label, formatter.getFormattedCurrencyCode(),
formatter.format(rawTotal.amount.value), /*isPending=*/false);
List<LineItem> uiLineItems = getLineItems(rawLineItems);
CurrencyFormatter formatter = getOrCreateCurrencyFormatter(details.total.amount);
LineItem uiTotal = new LineItem(details.total.label, formatter.getFormattedCurrencyCode(),
formatter.format(details.total.amount.value), /*isPending=*/false);
List<PaymentItem> itemList = details.displayItems == null
? new ArrayList<>()
: Arrays.asList(details.displayItems);
List<LineItem> uiLineItems = getLineItems(itemList);
mUiShoppingCart = new ShoppingCart(uiTotal, uiLineItems);
......
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