Commit 00901f19 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Chromium LUCI CQ

[WebLayer] Clean up getSelectedPaymentApp()

In PaymentUiService, the way to get the selected payment app is through
mPaymentMethodsSection, in spite of the fact that
getSelectedPaymentApp() is available. This CL is to replace these
mPaymentMethodsSection usages with getSelectedPaymentApp(). This will
help moving the payment app management logic out of PaymentUiService.

Bug: 1155614
Change-Id: I870d9b24f3cc78e007817c7b67bf9ca0639ccf34
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2574598
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833850}
parent 35e91505
...@@ -142,7 +142,7 @@ public class ChromePaymentRequestService ...@@ -142,7 +142,7 @@ public class ChromePaymentRequestService
// Implements BrowserPaymentRequest: // Implements BrowserPaymentRequest:
@Override @Override
public PaymentApp getSelectedPaymentApp() { public PaymentApp getSelectedPaymentApp() {
return (PaymentApp) mPaymentUiService.getSelectedPaymentApp(); return mPaymentUiService.getSelectedPaymentApp();
} }
// Implements BrowserPaymentRequest: // Implements BrowserPaymentRequest:
...@@ -300,7 +300,7 @@ public class ChromePaymentRequestService ...@@ -300,7 +300,7 @@ public class ChromePaymentRequestService
} }
assert !mPaymentUiService.getPaymentApps().isEmpty(); assert !mPaymentUiService.getPaymentApps().isEmpty();
PaymentApp selectedApp = (PaymentApp) mPaymentUiService.getSelectedPaymentApp(); PaymentApp selectedApp = mPaymentUiService.getSelectedPaymentApp();
dimBackgroundIfNotBottomSheetPaymentHandler(selectedApp); dimBackgroundIfNotBottomSheetPaymentHandler(selectedApp);
mDidRecordShowEvent = true; mDidRecordShowEvent = true;
mJourneyLogger.setEventOccurred(Event.SKIPPED_SHOW); mJourneyLogger.setEventOccurred(Event.SKIPPED_SHOW);
...@@ -325,7 +325,7 @@ public class ChromePaymentRequestService ...@@ -325,7 +325,7 @@ public class ChromePaymentRequestService
return false; return false;
} }
PaymentApp app = (PaymentApp) mPaymentUiService.getSelectedPaymentApp(); PaymentApp app = mPaymentUiService.getSelectedPaymentApp();
if (app == null || !app.isReadyForMinimalUI() || TextUtils.isEmpty(app.accountBalance())) { if (app == null || !app.isReadyForMinimalUI() || TextUtils.isEmpty(app.accountBalance())) {
return false; return false;
} }
...@@ -648,13 +648,13 @@ public class ChromePaymentRequestService ...@@ -648,13 +648,13 @@ public class ChromePaymentRequestService
// Implements BrowserPaymentRequest: // Implements BrowserPaymentRequest:
@Override @Override
public void onInstrumentDetailsReady() { public void onInstrumentDetailsReady() {
// If the payment method was an Autofill credit card with an identifier, record its use. // If the payment app was an Autofill credit card with an identifier, record its use.
PaymentApp selectedPaymentMethod = (PaymentApp) mPaymentUiService.getSelectedPaymentApp(); PaymentApp selectedPaymentApp = mPaymentUiService.getSelectedPaymentApp();
if (selectedPaymentMethod != null if (selectedPaymentApp != null
&& selectedPaymentMethod.getPaymentAppType() == PaymentAppType.AUTOFILL && selectedPaymentApp.getPaymentAppType() == PaymentAppType.AUTOFILL
&& !selectedPaymentMethod.getIdentifier().isEmpty()) { && !selectedPaymentApp.getIdentifier().isEmpty()) {
PersonalDataManager.getInstance().recordAndLogCreditCardUse( PersonalDataManager.getInstance().recordAndLogCreditCardUse(
selectedPaymentMethod.getIdentifier()); selectedPaymentApp.getIdentifier());
} }
// Showing the app selector UI if we were previously skipping it so the loading // Showing the app selector UI if we were previously skipping it so the loading
......
...@@ -338,6 +338,7 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -338,6 +338,7 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
/** @return The payment apps. */ /** @return The payment apps. */
public List<PaymentApp> getPaymentApps() { public List<PaymentApp> getPaymentApps() {
List<PaymentApp> paymentApps = new ArrayList<>(); List<PaymentApp> paymentApps = new ArrayList<>();
if (mPaymentMethodsSection == null) return paymentApps;
for (EditableOption each : mPaymentMethodsSection.getItems()) { for (EditableOption each : mPaymentMethodsSection.getItems()) {
paymentApps.add((PaymentApp) each); paymentApps.add((PaymentApp) each);
} }
...@@ -349,8 +350,10 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -349,8 +350,10 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
* @return The selected payment app or null if none selected. * @return The selected payment app or null if none selected.
*/ */
@Nullable @Nullable
public EditableOption getSelectedPaymentApp() { public PaymentApp getSelectedPaymentApp() {
return mPaymentMethodsSection.getSelectedItem(); return mPaymentMethodsSection == null
? null
: (PaymentApp) mPaymentMethodsSection.getSelectedItem();
} }
/** /**
...@@ -472,9 +475,9 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -472,9 +475,9 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
// Do not show the Payment Request UI dialog even if the minimal UI is suppressed. // Do not show the Payment Request UI dialog even if the minimal UI is suppressed.
mPaymentUisShowStateReconciler.onBottomSheetShown(); mPaymentUisShowStateReconciler.onBottomSheetShown();
mMinimalUi = new MinimalUICoordinator(); mMinimalUi = new MinimalUICoordinator();
PaymentApp selectedApp = getSelectedPaymentApp();
return mMinimalUi.show(chromeActivity, return mMinimalUi.show(chromeActivity,
BottomSheetControllerProvider.from(chromeActivity.getWindowAndroid()), BottomSheetControllerProvider.from(chromeActivity.getWindowAndroid()), selectedApp,
(PaymentApp) mPaymentMethodsSection.getSelectedItem(),
mCurrencyFormatterMap.get(mRawTotal.amount.currency), mUiShoppingCart.getTotal(), mCurrencyFormatterMap.get(mRawTotal.amount.currency), mUiShoppingCart.getTotal(),
readyObserver, confirmObserver, dismissObserver); readyObserver, confirmObserver, dismissObserver);
} }
...@@ -491,10 +494,12 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -491,10 +494,12 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
MinimalUICoordinator.ErrorAndCloseObserver onMinimalUiErroredAndClosed, MinimalUICoordinator.ErrorAndCloseObserver onMinimalUiErroredAndClosed,
Runnable onUiCompleted) { Runnable onUiCompleted) {
// Update records of the used payment app for sorting payment apps next time. // Update records of the used payment app for sorting payment apps next time.
EditableOption selectedPaymentMethod = mPaymentMethodsSection.getSelectedItem(); PaymentApp paymentApp = getSelectedPaymentApp();
PaymentPreferencesUtil.increasePaymentAppUseCount(selectedPaymentMethod.getIdentifier()); assert paymentApp != null;
String selectedPaymentMethod = paymentApp.getIdentifier();
PaymentPreferencesUtil.increasePaymentAppUseCount(selectedPaymentMethod);
PaymentPreferencesUtil.setPaymentAppLastUseDate( PaymentPreferencesUtil.setPaymentAppLastUseDate(
selectedPaymentMethod.getIdentifier(), System.currentTimeMillis()); selectedPaymentMethod, System.currentTimeMillis());
if (mMinimalUi != null) { if (mMinimalUi != null) {
mMinimalUi.onPaymentRequestComplete(result, mMinimalUi.onPaymentRequestComplete(result,
...@@ -642,7 +647,7 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -642,7 +647,7 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
public void onRetry(PaymentValidationErrors errors) { public void onRetry(PaymentValidationErrors errors) {
// Remove all payment apps except the selected one. // Remove all payment apps except the selected one.
assert mPaymentMethodsSection != null; assert mPaymentMethodsSection != null;
PaymentApp selectedApp = (PaymentApp) mPaymentMethodsSection.getSelectedItem(); PaymentApp selectedApp = getSelectedPaymentApp();
assert selectedApp != null; assert selectedApp != null;
mPaymentMethodsSection = new SectionInformation(PaymentRequestUI.DataType.PAYMENT_METHODS, mPaymentMethodsSection = new SectionInformation(PaymentRequestUI.DataType.PAYMENT_METHODS,
/* selection = */ 0, new ArrayList<>(Arrays.asList(selectedApp))); /* selection = */ 0, new ArrayList<>(Arrays.asList(selectedApp)));
...@@ -698,9 +703,8 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -698,9 +703,8 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
/** @return The selected payment app type. */ /** @return The selected payment app type. */
public @PaymentAppType int getSelectedPaymentAppType() { public @PaymentAppType int getSelectedPaymentAppType() {
return mPaymentMethodsSection != null && mPaymentMethodsSection.getSelectedItem() != null PaymentApp paymentApp = getSelectedPaymentApp();
? ((PaymentApp) mPaymentMethodsSection.getSelectedItem()).getPaymentAppType() return paymentApp == null ? PaymentAppType.UNDEFINED : paymentApp.getPaymentAppType();
: PaymentAppType.UNDEFINED;
} }
/** Sets the modifier for the order summary based on the given app, if any. */ /** Sets the modifier for the order summary based on the given app, if any. */
...@@ -758,7 +762,7 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -758,7 +762,7 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
.format(modifier.total.amount.value)); .format(modifier.total.amount.value));
} }
updateOrderSummary((PaymentApp) mPaymentMethodsSection.getSelectedItem()); updateOrderSummary(getSelectedPaymentApp());
} }
/** /**
...@@ -927,18 +931,14 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -927,18 +931,14 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
public boolean shouldShowShippingSection() { public boolean shouldShowShippingSection() {
if (mParams.hasClosed() || !mParams.getPaymentOptions().requestShipping) return false; if (mParams.hasClosed() || !mParams.getPaymentOptions().requestShipping) return false;
if (mPaymentMethodsSection == null) return true; PaymentApp selectedApp = getSelectedPaymentApp();
PaymentApp selectedApp = (PaymentApp) mPaymentMethodsSection.getSelectedItem();
return selectedApp == null || !selectedApp.handlesShippingAddress(); return selectedApp == null || !selectedApp.handlesShippingAddress();
} }
// Implements PaymentUiService.Delegate: // Implements PaymentUiService.Delegate:
@Override @Override
public boolean shouldShowContactSection() { public boolean shouldShowContactSection() {
PaymentApp selectedApp = (mPaymentMethodsSection == null) PaymentApp selectedApp = getSelectedPaymentApp();
? null
: (PaymentApp) mPaymentMethodsSection.getSelectedItem();
if (mParams.hasClosed()) return false; if (mParams.hasClosed()) return false;
PaymentOptions options = mParams.getPaymentOptions(); PaymentOptions options = mParams.getPaymentOptions();
if (options.requestPayerName && (selectedApp == null || !selectedApp.handlesPayerName())) { if (options.requestPayerName && (selectedApp == null || !selectedApp.handlesPayerName())) {
...@@ -1635,9 +1635,8 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs ...@@ -1635,9 +1635,8 @@ public class PaymentUiService implements SettingsAutofillAndPaymentsObserver.Obs
mPaymentUisShowStateReconciler.onPaymentRequestUiClosed(); mPaymentUisShowStateReconciler.onPaymentRequestUiClosed();
} }
if (mPaymentMethodsSection != null) { if (mPaymentMethodsSection != null) {
for (int i = 0; i < mPaymentMethodsSection.getSize(); i++) { for (PaymentApp app : getPaymentApps()) {
EditableOption option = mPaymentMethodsSection.getItem(i); app.dismissInstrument();
((PaymentApp) option).dismissInstrument();
} }
mPaymentMethodsSection = null; mPaymentMethodsSection = 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