Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.payments; | 5 package org.chromium.chrome.browser.payments; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.graphics.Bitmap; | 8 import android.graphics.Bitmap; |
| 9 import android.os.Handler; | 9 import android.os.Handler; |
| 10 import android.support.v4.util.ArrayMap; | 10 import android.support.v4.util.ArrayMap; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 import org.chromium.payments.mojom.PaymentRequest; | 48 import org.chromium.payments.mojom.PaymentRequest; |
| 49 import org.chromium.payments.mojom.PaymentRequestClient; | 49 import org.chromium.payments.mojom.PaymentRequestClient; |
| 50 import org.chromium.payments.mojom.PaymentResponse; | 50 import org.chromium.payments.mojom.PaymentResponse; |
| 51 import org.chromium.payments.mojom.PaymentShippingOption; | 51 import org.chromium.payments.mojom.PaymentShippingOption; |
| 52 import org.chromium.payments.mojom.PaymentShippingType; | 52 import org.chromium.payments.mojom.PaymentShippingType; |
| 53 | 53 |
| 54 import java.util.ArrayList; | 54 import java.util.ArrayList; |
| 55 import java.util.Arrays; | 55 import java.util.Arrays; |
| 56 import java.util.Collections; | 56 import java.util.Collections; |
| 57 import java.util.Comparator; | 57 import java.util.Comparator; |
| 58 import java.util.HashMap; | |
| 58 import java.util.HashSet; | 59 import java.util.HashSet; |
| 59 import java.util.List; | 60 import java.util.List; |
| 60 import java.util.Locale; | 61 import java.util.Locale; |
| 61 import java.util.Map; | 62 import java.util.Map; |
| 62 import java.util.Set; | 63 import java.util.Set; |
| 63 | 64 |
| 64 /** | 65 /** |
| 65 * Android implementation of the PaymentRequest service defined in | 66 * Android implementation of the PaymentRequest service defined in |
| 66 * components/payments/payment_request.mojom. | 67 * components/payments/payment_request.mojom. |
| 67 */ | 68 */ |
| (...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 900 } else if (toEdit == null) { | 901 } else if (toEdit == null) { |
| 901 mPaymentMethodsSection.addAndSelectItem(completeCard); | 902 mPaymentMethodsSection.addAndSelectItem(completeCard); |
| 902 } | 903 } |
| 903 | 904 |
| 904 mUI.updateSection(PaymentRequestUI.TYPE_PAYMENT_METHODS, mPaymen tMethodsSection); | 905 mUI.updateSection(PaymentRequestUI.TYPE_PAYMENT_METHODS, mPaymen tMethodsSection); |
| 905 } | 906 } |
| 906 }); | 907 }); |
| 907 } | 908 } |
| 908 | 909 |
| 909 @Override | 910 @Override |
| 910 public void loadingInstrumentDetails() { | 911 public void onInstrumentDetailsLoading() { |
| 911 if (mClient == null || mUI == null || mPaymentResponseHelper == null) re turn; | 912 if (mClient == null || mUI == null || mPaymentResponseHelper == null) re turn; |
| 912 | 913 |
| 913 mUI.showProcessingMessage(); | 914 mUI.showProcessingMessage(); |
| 914 mPaymentResponseHelper.onInstrumentsDetailsLoading(); | 915 mPaymentResponseHelper.onInstrumentsDetailsLoading(); |
| 915 } | 916 } |
| 916 | 917 |
| 917 @Override | 918 @Override |
| 918 public boolean onPayClicked(PaymentOption selectedShippingAddress, | 919 public boolean onPayClicked(PaymentOption selectedShippingAddress, |
| 919 PaymentOption selectedShippingOption, PaymentOption selectedPaymentM ethod) { | 920 PaymentOption selectedShippingOption, PaymentOption selectedPaymentM ethod) { |
| 920 assert selectedPaymentMethod instanceof PaymentInstrument; | 921 assert selectedPaymentMethod instanceof PaymentInstrument; |
| 921 PaymentInstrument instrument = (PaymentInstrument) selectedPaymentMethod ; | 922 PaymentInstrument instrument = (PaymentInstrument) selectedPaymentMethod ; |
| 922 mPaymentAppRunning = true; | 923 mPaymentAppRunning = true; |
| 923 | 924 |
| 924 PaymentOption selectedContact = | 925 PaymentOption selectedContact = |
| 925 mContactSection != null ? mContactSection.getSelectedItem() : nu ll; | 926 mContactSection != null ? mContactSection.getSelectedItem() : nu ll; |
| 926 mPaymentResponseHelper = new PaymentResponseHelper( | 927 mPaymentResponseHelper = new PaymentResponseHelper( |
| 927 selectedShippingAddress, selectedShippingOption, selectedContact , this); | 928 selectedShippingAddress, selectedShippingOption, selectedContact , this); |
| 928 | 929 |
| 929 instrument.getInstrumentDetails(mMerchantName, mOrigin, mRawTotal, mRawL ineItems, | 930 // Create a map that is the subset of mMethodData that contains the |
| 930 mMethodData.get(instrument.getInstrumentMethodName()), this); | 931 // payment methods supported by the selected payment instrument. If this |
| 932 // intersection contains more than one payment method, the payment app i s | |
| 933 // at liberty to choose (or have the user choose) one of the methods. | |
| 934 Map<String, PaymentMethodData> methodData = new HashMap<>(); | |
| 935 for (String instrumentMethodName : instrument.getInstrumentMethodNames() ) { | |
| 936 if (mMethodData.containsKey(instrumentMethodName)) { | |
| 937 methodData.put(instrumentMethodName, mMethodData.get(instrumentM ethodName)); | |
| 938 } | |
| 939 } | |
| 940 | |
| 941 instrument.invokePayment(mMerchantName, mOrigin, mRawTotal, mRawLineItem s, | |
| 942 methodData, this); | |
|
please use gerrit instead
2016/11/29 14:17:18
Wrap methodData in Collections.unmodifiableMap().
tommyt
2016/11/30 10:15:50
Done.
| |
| 931 recordSuccessFunnelHistograms("PayClicked"); | 943 recordSuccessFunnelHistograms("PayClicked"); |
| 932 return !(instrument instanceof AutofillPaymentInstrument); | 944 return !(instrument instanceof AutofillPaymentInstrument); |
| 933 } | 945 } |
| 934 | 946 |
| 935 @Override | 947 @Override |
| 936 public void onDismiss() { | 948 public void onDismiss() { |
| 937 disconnectFromClientWithDebugMessage("Dialog dismissed"); | 949 disconnectFromClientWithDebugMessage("Dialog dismissed"); |
| 938 closeUI(true); | 950 closeUI(true); |
| 939 recordAbortReasonHistogram(PaymentRequestMetrics.ABORT_REASON_ABORTED_BY _USER); | 951 recordAbortReasonHistogram(PaymentRequestMetrics.ABORT_REASON_ABORTED_BY _USER); |
| 940 } | 952 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1051 */ | 1063 */ |
| 1052 @Override | 1064 @Override |
| 1053 public void onInstrumentsReady(PaymentApp app, List<PaymentInstrument> instr uments) { | 1065 public void onInstrumentsReady(PaymentApp app, List<PaymentInstrument> instr uments) { |
| 1054 if (mClient == null) return; | 1066 if (mClient == null) return; |
| 1055 mPendingApps.remove(app); | 1067 mPendingApps.remove(app); |
| 1056 | 1068 |
| 1057 // Place the instruments into either "autofill" or "non-autofill" list t o be displayed when | 1069 // Place the instruments into either "autofill" or "non-autofill" list t o be displayed when |
| 1058 // all apps have responded. | 1070 // all apps have responded. |
| 1059 if (instruments != null) { | 1071 if (instruments != null) { |
| 1060 for (int i = 0; i < instruments.size(); i++) { | 1072 for (int i = 0; i < instruments.size(); i++) { |
| 1073 boolean added = false; | |
| 1061 PaymentInstrument instrument = instruments.get(i); | 1074 PaymentInstrument instrument = instruments.get(i); |
| 1062 if (mMethodData.containsKey(instrument.getInstrumentMethodName() )) { | 1075 // If at least one of the payment method names supported by the |
| 1063 addPendingInstrument(instrument); | 1076 // instrument is in mMethodData, add this instrument. |
|
please use gerrit instead
2016/11/29 14:17:18
Your approach is 9 lines long. Here's a shorter wa
tommyt
2016/11/30 10:15:50
Done.
| |
| 1064 } else { | 1077 for (String instrumentMethodName : instrument.getInstrumentMetho dNames()) { |
| 1078 if (mMethodData.containsKey(instrumentMethodName)) { | |
| 1079 addPendingInstrument(instrument); | |
| 1080 added = true; | |
| 1081 break; | |
| 1082 } | |
| 1083 } | |
| 1084 // ... otherwise get rid of it. | |
| 1085 if (!added) { | |
| 1065 instrument.dismissInstrument(); | 1086 instrument.dismissInstrument(); |
| 1066 } | 1087 } |
| 1067 } | 1088 } |
| 1068 } | 1089 } |
| 1069 | 1090 |
| 1070 // Some payment apps still have not responded. Continue waiting for them . | 1091 // Some payment apps still have not responded. Continue waiting for them . |
| 1071 if (!mPendingApps.isEmpty()) return; | 1092 if (!mPendingApps.isEmpty()) return; |
| 1072 | 1093 |
| 1073 if (disconnectIfNoPaymentMethodsSupported()) return; | 1094 if (disconnectIfNoPaymentMethodsSupported()) return; |
| 1074 | 1095 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1294 "PaymentRequest.CheckoutFunnel.Aborted", abortReason, | 1315 "PaymentRequest.CheckoutFunnel.Aborted", abortReason, |
| 1295 PaymentRequestMetrics.ABORT_REASON_MAX); | 1316 PaymentRequestMetrics.ABORT_REASON_MAX); |
| 1296 | 1317 |
| 1297 if (abortReason == PaymentRequestMetrics.ABORT_REASON_ABORTED_BY_USER) { | 1318 if (abortReason == PaymentRequestMetrics.ABORT_REASON_ABORTED_BY_USER) { |
| 1298 mJourneyLogger.recordJourneyStatsHistograms("UserAborted"); | 1319 mJourneyLogger.recordJourneyStatsHistograms("UserAborted"); |
| 1299 } else { | 1320 } else { |
| 1300 mJourneyLogger.recordJourneyStatsHistograms("OtherAborted"); | 1321 mJourneyLogger.recordJourneyStatsHistograms("OtherAborted"); |
| 1301 } | 1322 } |
| 1302 } | 1323 } |
| 1303 } | 1324 } |
| OLD | NEW |