Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1778)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java

Issue 2434333005: Introduce method data map in getInstrument (Closed)
Patch Set: Fix compilation Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
index 11123a68fd063c5c0ac93a8897e808d3b4d9c0b5..43bae505f857ec5ccbc8fa02dc5de3cfd48d1cd4 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java
@@ -69,7 +69,7 @@ import java.util.Set;
* third_party/WebKit/public/platform/modules/payments/payment_request.mojom.
*/
public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Client,
- PaymentApp.InstrumentsCallback, PaymentInstrument.DetailsCallback,
+ PaymentApp.InstrumentsCallback, PaymentInstrument.InstrumentDetailsCallback,
NormalizedAddressRequestDelegate {
/**
* Observer to be notified when PaymentRequest UI has been dismissed.
@@ -454,28 +454,41 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
mPendingInstruments = new ArrayList<>();
mPendingAutofillInstruments = new ArrayList<>();
- Map<PaymentApp, JSONObject> queryApps = new HashMap<>();
+ Map<PaymentApp, Map<String, JSONObject>> queryApps = new HashMap<>();
for (int i = 0; i < mApps.size(); i++) {
PaymentApp app = mApps.get(i);
- Set<String> appMethods = app.getSupportedMethodNames();
- appMethods.retainAll(mMethodData.keySet());
- if (appMethods.isEmpty()) {
+ Map<String, JSONObject> appMethods =
+ filterMerchantMethodData(mMethodData, app.getAppMethodNames());
+ if (appMethods == null) {
mPendingApps.remove(app);
} else {
mArePaymentMethodsSupported = true;
mMerchantSupportsAutofillPaymentInstruments |= app instanceof AutofillPaymentApp;
- queryApps.put(app, mMethodData.get(appMethods.iterator().next()));
+ queryApps.put(app, appMethods);
}
}
// Query instruments after mMerchantSupportsAutofillPaymentInstruments has been initialized,
// so a fast response from a non-autofill payment app at the front of the app list does not
// cause NOT_SUPPORTED payment rejection.
- for (Map.Entry<PaymentApp, JSONObject> q : queryApps.entrySet()) {
+ for (Map.Entry<PaymentApp, Map<String, JSONObject>> q : queryApps.entrySet()) {
q.getKey().getInstruments(q.getValue(), this);
}
}
+ /** Filter out merchant method data that's not relevant to a payment app. Can return null. */
+ private static Map<String, JSONObject> filterMerchantMethodData(
+ Map<String, JSONObject> merchantMethodData, Set<String> appMethods) {
+ Map<String, JSONObject> result = null;
+ for (String method : appMethods) {
+ if (merchantMethodData.containsKey(method)) {
+ if (result == null) result = new HashMap<>();
+ result.put(method, merchantMethodData.get(method));
+ }
+ }
+ return result;
+ }
+
/**
* Called by merchant to update the shipping options and line items after the user has selected
* their shipping address or shipping option.
@@ -877,8 +890,8 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
assert selectedPaymentMethod instanceof PaymentInstrument;
PaymentInstrument instrument = (PaymentInstrument) selectedPaymentMethod;
mPaymentAppRunning = true;
- instrument.getDetails(mMerchantName, mOrigin, mRawTotal, mRawLineItems,
- mMethodData.get(instrument.getMethodName()), this);
+ instrument.getInstrumentDetails(mMerchantName, mOrigin, mRawTotal, mRawLineItems,
+ mMethodData.get(instrument.getInstrumentMethodName()), this);
recordSuccessFunnelHistograms("PayClicked");
return !(instrument instanceof AutofillPaymentInstrument);
}
@@ -962,10 +975,10 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
if (instruments != null) {
for (int i = 0; i < instruments.size(); i++) {
PaymentInstrument instrument = instruments.get(i);
- if (mMethodData.containsKey(instrument.getMethodName())) {
+ if (mMethodData.containsKey(instrument.getInstrumentMethodName())) {
addPendingInstrument(instrument);
} else {
- instrument.dismiss();
+ instrument.dismissInstrument();
}
}
}
@@ -1223,7 +1236,7 @@ public class PaymentRequestImpl implements PaymentRequest, PaymentRequestUI.Clie
for (int i = 0; i < mPaymentMethodsSection.getSize(); i++) {
PaymentOption option = mPaymentMethodsSection.getItem(i);
assert option instanceof PaymentInstrument;
- ((PaymentInstrument) option).dismiss();
+ ((PaymentInstrument) option).dismissInstrument();
}
mPaymentMethodsSection = null;
}

Powered by Google App Engine
This is Rietveld 408576698