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, ...@@ -162,8 +162,7 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest,
@Override @Override
public void onSpecValidated(PaymentRequestSpec spec) { public void onSpecValidated(PaymentRequestSpec spec) {
mSpec = spec; mSpec = spec;
mPaymentUiService.initialize( mPaymentUiService.initialize(mSpec.getPaymentDetails());
mSpec.getPaymentDetails(), mSpec.getRawTotal(), mSpec.getRawLineItems());
// Log the various types of payment methods that were requested by the merchant. // Log the various types of payment methods that were requested by the merchant.
boolean requestedMethodGoogle = false; boolean requestedMethodGoogle = false;
...@@ -482,8 +481,7 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest, ...@@ -482,8 +481,7 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest,
// mSpec.updateWith() can be used only when mSpec has not been destroyed. // mSpec.updateWith() can be used only when mSpec has not been destroyed.
assert !mSpec.isDestroyed(); assert !mSpec.isDestroyed();
mPaymentUiService.updateDetailsOnPaymentRequestUI( mPaymentUiService.updateDetailsOnPaymentRequestUI(mSpec.getPaymentDetails());
mSpec.getPaymentDetails(), mSpec.getRawTotal(), mSpec.getRawLineItems());
if (hasNotifiedInvokedPaymentApp) return; if (hasNotifiedInvokedPaymentApp) return;
...@@ -512,8 +510,7 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest, ...@@ -512,8 +510,7 @@ public class ChromePaymentRequestService implements BrowserPaymentRequest,
return; return;
} }
mPaymentUiService.updateDetailsOnPaymentRequestUI( mPaymentUiService.updateDetailsOnPaymentRequestUI(mSpec.getPaymentDetails());
mSpec.getPaymentDetails(), mSpec.getRawTotal(), mSpec.getRawLineItems());
// Do not create shipping section When UI is not built yet. This happens when the show // Do not create shipping section When UI is not built yet. This happens when the show
// promise gets resolved before all apps are ready. // promise gets resolved before all apps are ready.
......
...@@ -539,14 +539,10 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -539,14 +539,10 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
/** /**
* Initializes the payment UI service. * Initializes the payment UI service.
* @param details The PaymentDetails provided by the merchant. * @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( public void initialize(PaymentDetails details) {
PaymentDetails details, PaymentItem rawTotal, List<PaymentItem> rawLineItems) {
assert !mParams.hasClosed(); assert !mParams.hasClosed();
updateDetailsOnPaymentRequestUI(details, rawTotal, rawLineItems); updateDetailsOnPaymentRequestUI(details);
for (PaymentMethodData method : mParams.getMethodData().values()) { for (PaymentMethodData method : mParams.getMethodData().values()) {
mCardEditor.addAcceptedPaymentMethodIfRecognized(method); mCardEditor.addAcceptedPaymentMethodIfRecognized(method);
} }
...@@ -1417,18 +1413,18 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -1417,18 +1413,18 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
/** /**
* Update the details related fields on the PaymentRequest UI. * Update the details related fields on the PaymentRequest UI.
* @param details The details whose information is used for the update. * @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( public void updateDetailsOnPaymentRequestUI(PaymentDetails details) {
PaymentDetails details, PaymentItem rawTotal, List<PaymentItem> rawLineItems) {
loadCurrencyFormattersForPaymentDetails(details); loadCurrencyFormattersForPaymentDetails(details);
// Total is never pending. // Total is never pending.
CurrencyFormatter formatter = getOrCreateCurrencyFormatter(rawTotal.amount); CurrencyFormatter formatter = getOrCreateCurrencyFormatter(details.total.amount);
LineItem uiTotal = new LineItem(rawTotal.label, formatter.getFormattedCurrencyCode(), LineItem uiTotal = new LineItem(details.total.label, formatter.getFormattedCurrencyCode(),
formatter.format(rawTotal.amount.value), /*isPending=*/false); formatter.format(details.total.amount.value), /*isPending=*/false);
List<LineItem> uiLineItems = getLineItems(rawLineItems); List<PaymentItem> itemList = details.displayItems == null
? new ArrayList<>()
: Arrays.asList(details.displayItems);
List<LineItem> uiLineItems = getLineItems(itemList);
mUiShoppingCart = new ShoppingCart(uiTotal, uiLineItems); 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