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

[PRImpl] Assert mMerchantSupportsAutofillCards != null

After crrev.com/c/2372888, all cases of mMerchantSupportsAutofillCards
are accessed after defined, we can limit that it's used only after it's
not null.

Bug: 1107039

Change-Id: Iea978142c9a9e7d755cb294d9acf3eff80f13d5a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2388561
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarSahel Sharify <sahel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804069}
parent ede900bb
......@@ -1828,11 +1828,7 @@ public class PaymentRequestImpl
int missingFields = 0;
if (mPendingApps.isEmpty()) {
// TODO(crbug.com/1107039): This value could be null when this method is entered from
// PaymentRequest#init. We should turn it into boolean after correcting this bug.
Boolean merchantSupportsAutofillCards =
mPaymentUIsManager.merchantSupportsAutofillCards();
if (merchantSupportsAutofillCards != null && merchantSupportsAutofillCards) {
if (mPaymentUIsManager.merchantSupportsAutofillCards()) {
// Record all fields if basic-card is supported but no card exists.
missingFields = AutofillPaymentInstrument.CompletionStatus.CREDIT_CARD_EXPIRED
| AutofillPaymentInstrument.CompletionStatus.CREDIT_CARD_NO_CARDHOLDER
......
......@@ -111,14 +111,15 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
private PaymentRequestUI mPaymentRequestUI;
private ShoppingCart mUiShoppingCart;
private Boolean mMerchantSupportsAutofillCards;
private boolean mMerchantSupportsAutofillCards;
private boolean mIsPaymentRequestParamsInitiated;
private SectionInformation mPaymentMethodsSection;
private SectionInformation mShippingAddressesSection;
private ContactDetailsSection mContactSection;
private AutofillPaymentAppCreator mAutofillPaymentAppCreator;
private boolean mHaveRequestedAutofillData = true;
private List<AutofillProfile> mAutofillProfiles;
private Boolean mCanUserAddCreditCard;
private boolean mCanUserAddCreditCard;
private final JourneyLogger mJourneyLogger;
private PaymentUIsObserver mObserver;
......@@ -255,11 +256,12 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
return mCardEditor;
}
/** @return Whether the merchant supports autofill cards. */
@Nullable
public Boolean merchantSupportsAutofillCards() {
// TODO(crbug.com/1107039): this value should be asserted not null to avoid being used
// before defined, after this bug is fixed.
/**
* @return Whether the merchant supports autofill cards. It can be used only after
* onPaymentRequestParamsInitiated() is invoked.
*/
public boolean merchantSupportsAutofillCards() {
assert mIsPaymentRequestParamsInitiated;
return mMerchantSupportsAutofillCards;
}
......@@ -293,9 +295,12 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
mAutofillPaymentAppCreator = autofillPaymentAppCreator;
}
/** @return Whether user can add credit card. */
/**
* @return Whether user can add credit card. It can be used only after
* onPaymentRequestParamsInitiated() is invoked.
*/
public boolean canUserAddCreditCard() {
assert mCanUserAddCreditCard != null;
assert mIsPaymentRequestParamsInitiated;
return mCanUserAddCreditCard;
}
......@@ -379,7 +384,7 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
// Implement SettingsAutofillAndPaymentsObserver.Observer:
@Override
public void onCreditCardUpdated(CreditCard card) {
assert mMerchantSupportsAutofillCards != null;
assert mIsPaymentRequestParamsInitiated;
if (!mMerchantSupportsAutofillCards || mPaymentMethodsSection == null
|| mAutofillPaymentAppCreator == null) {
return;
......@@ -405,7 +410,7 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
// Implement SettingsAutofillAndPaymentsObserver.Observer:
@Override
public void onCreditCardDeleted(String guid) {
assert mMerchantSupportsAutofillCards != null;
assert mIsPaymentRequestParamsInitiated;
if (!mMerchantSupportsAutofillCards || mPaymentMethodsSection == null) return;
mPaymentMethodsSection.removeAndUnselectItem(guid);
......@@ -469,6 +474,7 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
}
mHaveRequestedAutofillData &= haveCompleteContactInfo;
}
mIsPaymentRequestParamsInitiated = true;
}
// Implement PaymentRequestLifecycleObserver:
......@@ -944,8 +950,9 @@ public class PaymentUIsManager implements SettingsAutofillAndPaymentsObserver.Ob
* @param activity The ChromeActivity for the payment request.
*/
public void buildPaymentRequestUI(ChromeActivity activity) {
assert mIsPaymentRequestParamsInitiated;
mPaymentRequestUI = new PaymentRequestUI(activity, mDelegate.getPaymentRequestUIClient(),
merchantSupportsAutofillCards(), !PaymentPreferencesUtil.isPaymentCompleteOnce(),
mMerchantSupportsAutofillCards, !PaymentPreferencesUtil.isPaymentCompleteOnce(),
mMerchantName, mTopLevelOriginFormattedForDisplay,
SecurityStateModel.getSecurityLevelForWebContents(mWebContents),
new ShippingStrings(
......
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