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.content.Context; | 8 import android.content.Context; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 mMethodData = getValidatedMethodData(methodData, mCardEditor); | 414 mMethodData = getValidatedMethodData(methodData, mCardEditor); |
415 if (mMethodData == null) { | 415 if (mMethodData == null) { |
416 disconnectFromClientWithDebugMessage("Invalid payment methods or dat
a"); | 416 disconnectFromClientWithDebugMessage("Invalid payment methods or dat
a"); |
417 recordAbortReasonHistogram( | 417 recordAbortReasonHistogram( |
418 PaymentRequestMetrics.ABORT_REASON_INVALID_DATA_FROM_RENDERE
R); | 418 PaymentRequestMetrics.ABORT_REASON_INVALID_DATA_FROM_RENDERE
R); |
419 return; | 419 return; |
420 } | 420 } |
421 | 421 |
422 if (!parseAndValidateDetailsOrDisconnectFromClient(details)) return; | 422 if (!parseAndValidateDetailsOrDisconnectFromClient(details)) return; |
423 | 423 |
| 424 if (mRawTotal == null) { |
| 425 disconnectFromClientWithDebugMessage("Missing total"); |
| 426 recordAbortReasonHistogram( |
| 427 PaymentRequestMetrics.ABORT_REASON_INVALID_DATA_FROM_RENDERE
R); |
| 428 return; |
| 429 } |
| 430 |
424 PaymentAppFactory.getInstance().create(mWebContents, | 431 PaymentAppFactory.getInstance().create(mWebContents, |
425 Collections.unmodifiableSet(mMethodData.keySet()), this /* callb
ack */); | 432 Collections.unmodifiableSet(mMethodData.keySet()), this /* callb
ack */); |
426 | 433 |
427 mRequestShipping = options != null && options.requestShipping; | 434 mRequestShipping = options != null && options.requestShipping; |
428 mRequestPayerName = options != null && options.requestPayerName; | 435 mRequestPayerName = options != null && options.requestPayerName; |
429 mRequestPayerPhone = options != null && options.requestPayerPhone; | 436 mRequestPayerPhone = options != null && options.requestPayerPhone; |
430 mRequestPayerEmail = options != null && options.requestPayerEmail; | 437 mRequestPayerEmail = options != null && options.requestPayerEmail; |
431 mShippingType = options == null ? PaymentShippingType.SHIPPING : options
.shippingType; | 438 mShippingType = options == null ? PaymentShippingType.SHIPPING : options
.shippingType; |
432 | 439 |
433 // If there is a single payment method and the merchant has not requeste
d any other | 440 // If there is a single payment method and the merchant has not requeste
d any other |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 recordAbortReasonHistogram( | 736 recordAbortReasonHistogram( |
730 PaymentRequestMetrics.ABORT_REASON_INVALID_DATA_FROM_RENDERE
R); | 737 PaymentRequestMetrics.ABORT_REASON_INVALID_DATA_FROM_RENDERE
R); |
731 return false; | 738 return false; |
732 } | 739 } |
733 | 740 |
734 if (mCurrencyFormatter == null) { | 741 if (mCurrencyFormatter == null) { |
735 mCurrencyFormatter = new CurrencyFormatter(details.total.amount.curr
ency, | 742 mCurrencyFormatter = new CurrencyFormatter(details.total.amount.curr
ency, |
736 details.total.amount.currencySystem, Locale.getDefault()); | 743 details.total.amount.currencySystem, Locale.getDefault()); |
737 } | 744 } |
738 | 745 |
739 // Total is never pending. | 746 if (details.total != null) { |
740 LineItem uiTotal = new LineItem(details.total.label, | 747 mRawTotal = details.total; |
741 mCurrencyFormatter.getFormattedCurrencyCode(), | 748 } |
742 mCurrencyFormatter.format(details.total.amount.value), /* isPend
ing */ false); | |
743 | 749 |
744 List<LineItem> uiLineItems = getLineItems(details.displayItems, mCurrenc
yFormatter); | 750 if (mRawTotal != null) { |
| 751 // Total is never pending. |
| 752 LineItem uiTotal = new LineItem(mRawTotal.label, |
| 753 mCurrencyFormatter.getFormattedCurrencyCode(), |
| 754 mCurrencyFormatter.format(mRawTotal.amount.value), /* isPend
ing */ false); |
745 | 755 |
746 mUiShoppingCart = new ShoppingCart(uiTotal, uiLineItems); | 756 List<LineItem> uiLineItems = getLineItems(details.displayItems, mCur
rencyFormatter); |
747 mRawTotal = details.total; | 757 |
| 758 mUiShoppingCart = new ShoppingCart(uiTotal, uiLineItems); |
| 759 } |
748 mRawLineItems = Collections.unmodifiableList(Arrays.asList(details.displ
ayItems)); | 760 mRawLineItems = Collections.unmodifiableList(Arrays.asList(details.displ
ayItems)); |
749 | 761 |
750 mUiShippingOptions = getShippingOptions(details.shippingOptions, mCurren
cyFormatter); | 762 mUiShippingOptions = getShippingOptions(details.shippingOptions, mCurren
cyFormatter); |
751 | 763 |
752 for (int i = 0; i < details.modifiers.length; i++) { | 764 for (int i = 0; i < details.modifiers.length; i++) { |
753 PaymentDetailsModifier modifier = details.modifiers[i]; | 765 PaymentDetailsModifier modifier = details.modifiers[i]; |
754 String[] methods = modifier.methodData.supportedMethods; | 766 String[] methods = modifier.methodData.supportedMethods; |
755 for (int j = 0; j < methods.length; j++) { | 767 for (int j = 0; j < methods.length; j++) { |
756 if (mModifiers == null) mModifiers = new ArrayMap<>(); | 768 if (mModifiers == null) mModifiers = new ArrayMap<>(); |
757 mModifiers.put(methods[j], modifier); | 769 mModifiers.put(methods[j], modifier); |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1673 | 1685 |
1674 /** | 1686 /** |
1675 * The frecency score is calculated according to use count and last use date
. The formula is | 1687 * The frecency score is calculated according to use count and last use date
. The formula is |
1676 * the same as the one used in GetFrecencyScore in autofill_data_model.cc. | 1688 * the same as the one used in GetFrecencyScore in autofill_data_model.cc. |
1677 */ | 1689 */ |
1678 private static final double getFrecencyScore(int count, long date) { | 1690 private static final double getFrecencyScore(int count, long date) { |
1679 long currentTime = System.currentTimeMillis(); | 1691 long currentTime = System.currentTimeMillis(); |
1680 return -Math.log((currentTime - date) / (24 * 60 * 60 * 1000) + 2) / Mat
h.log(count + 2); | 1692 return -Math.log((currentTime - date) / (24 * 60 * 60 * 1000) + 2) / Mat
h.log(count + 2); |
1681 } | 1693 } |
1682 } | 1694 } |
OLD | NEW |