| 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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 | 520 |
| 521 // Limit the number of suggestions. | 521 // Limit the number of suggestions. |
| 522 addresses = addresses.subList(0, Math.min(addresses.size(), SUGGESTIONS_
LIMIT)); | 522 addresses = addresses.subList(0, Math.min(addresses.size(), SUGGESTIONS_
LIMIT)); |
| 523 | 523 |
| 524 // Load the validation rules for each unique region code. | 524 // Load the validation rules for each unique region code. |
| 525 Set<String> uniqueCountryCodes = new HashSet<>(); | 525 Set<String> uniqueCountryCodes = new HashSet<>(); |
| 526 for (int i = 0; i < addresses.size(); ++i) { | 526 for (int i = 0; i < addresses.size(); ++i) { |
| 527 String countryCode = AutofillAddress.getCountryCode(addresses.get(i)
.getProfile()); | 527 String countryCode = AutofillAddress.getCountryCode(addresses.get(i)
.getProfile()); |
| 528 if (!uniqueCountryCodes.contains(countryCode)) { | 528 if (!uniqueCountryCodes.contains(countryCode)) { |
| 529 uniqueCountryCodes.add(countryCode); | 529 uniqueCountryCodes.add(countryCode); |
| 530 PersonalDataManager.getInstance().loadRulesForRegion(countryCode
); | 530 PersonalDataManager.getInstance().loadRulesForAddressNormalizati
on(countryCode); |
| 531 } | 531 } |
| 532 } | 532 } |
| 533 | 533 |
| 534 // Log the number of suggested shipping addresses. | 534 // Log the number of suggested shipping addresses. |
| 535 mJourneyLogger.setNumberOfSuggestionsShown( | 535 mJourneyLogger.setNumberOfSuggestionsShown( |
| 536 JourneyLogger.SECTION_SHIPPING_ADDRESS, addresses.size()); | 536 JourneyLogger.SECTION_SHIPPING_ADDRESS, addresses.size()); |
| 537 | 537 |
| 538 // Automatically select the first address if one is complete and if the
merchant does | 538 // Automatically select the first address if one is complete and if the
merchant does |
| 539 // not require a shipping address to calculate shipping costs. | 539 // not require a shipping address to calculate shipping costs. |
| 540 int firstCompleteAddressIndex = SectionInformation.NO_SELECTION; | 540 int firstCompleteAddressIndex = SectionInformation.NO_SELECTION; |
| (...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1378 // addresses and check for validity. | 1378 // addresses and check for validity. |
| 1379 Set<String> uniqueCountryCodes = new HashSet<>(); | 1379 Set<String> uniqueCountryCodes = new HashSet<>(); |
| 1380 for (int i = 0; i < mPendingAutofillInstruments.size(); ++i) { | 1380 for (int i = 0; i < mPendingAutofillInstruments.size(); ++i) { |
| 1381 assert mPendingAutofillInstruments.get(i) instanceof AutofillPayment
Instrument; | 1381 assert mPendingAutofillInstruments.get(i) instanceof AutofillPayment
Instrument; |
| 1382 AutofillPaymentInstrument creditCard = | 1382 AutofillPaymentInstrument creditCard = |
| 1383 (AutofillPaymentInstrument) mPendingAutofillInstruments.get(
i); | 1383 (AutofillPaymentInstrument) mPendingAutofillInstruments.get(
i); |
| 1384 | 1384 |
| 1385 String countryCode = AutofillAddress.getCountryCode(creditCard.getBi
llingAddress()); | 1385 String countryCode = AutofillAddress.getCountryCode(creditCard.getBi
llingAddress()); |
| 1386 if (!uniqueCountryCodes.contains(countryCode)) { | 1386 if (!uniqueCountryCodes.contains(countryCode)) { |
| 1387 uniqueCountryCodes.add(countryCode); | 1387 uniqueCountryCodes.add(countryCode); |
| 1388 PersonalDataManager.getInstance().loadRulesForRegion(countryCode
); | 1388 PersonalDataManager.getInstance().loadRulesForAddressNormalizati
on(countryCode); |
| 1389 } | 1389 } |
| 1390 | 1390 |
| 1391 // If there's a card on file with a valid number and a name, then | 1391 // If there's a card on file with a valid number and a name, then |
| 1392 // PaymentRequest.canMakePayment() returns true. | 1392 // PaymentRequest.canMakePayment() returns true. |
| 1393 mCanMakePayment |= creditCard.isValidCard(); | 1393 mCanMakePayment |= creditCard.isValidCard(); |
| 1394 } | 1394 } |
| 1395 | 1395 |
| 1396 // List order: | 1396 // List order: |
| 1397 // > Non-autofill instruments. | 1397 // > Non-autofill instruments. |
| 1398 // > Complete autofill instruments. | 1398 // > Complete autofill instruments. |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1685 | 1685 |
| 1686 /** | 1686 /** |
| 1687 * 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 |
| 1688 * 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. |
| 1689 */ | 1689 */ |
| 1690 private static final double getFrecencyScore(int count, long date) { | 1690 private static final double getFrecencyScore(int count, long date) { |
| 1691 long currentTime = System.currentTimeMillis(); | 1691 long currentTime = System.currentTimeMillis(); |
| 1692 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); |
| 1693 } | 1693 } |
| 1694 } | 1694 } |
| OLD | NEW |