| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "components/autofill/core/browser/personal_data_manager.h" | 5 #include "components/autofill/core/browser/personal_data_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 std::list<const CreditCard*> cards_to_suggest(credit_cards.begin(), | 800 std::list<const CreditCard*> cards_to_suggest(credit_cards.begin(), |
| 801 credit_cards.end()); | 801 credit_cards.end()); |
| 802 | 802 |
| 803 DedupeCreditCardToSuggest(&cards_to_suggest); | 803 DedupeCreditCardToSuggest(&cards_to_suggest); |
| 804 | 804 |
| 805 // Rank the cards by frecency (see AutofillDataModel for details). All expired | 805 // Rank the cards by frecency (see AutofillDataModel for details). All expired |
| 806 // cards should be suggested last, also by frecency. | 806 // cards should be suggested last, also by frecency. |
| 807 base::Time comparison_time = base::Time::Now(); | 807 base::Time comparison_time = base::Time::Now(); |
| 808 cards_to_suggest.sort( | 808 cards_to_suggest.sort( |
| 809 [comparison_time](const CreditCard* a, const CreditCard* b) { | 809 [comparison_time](const CreditCard* a, const CreditCard* b) { |
| 810 bool a_has_valid_expiration = IsValidCreditCardExpirationDate( | 810 bool a_is_expired = a->IsExpired(comparison_time); |
| 811 a->expiration_year(), a->expiration_month(), comparison_time); | 811 if (a_is_expired != b->IsExpired(comparison_time)) |
| 812 if (a_has_valid_expiration != | 812 return !a_is_expired; |
| 813 IsValidCreditCardExpirationDate( | |
| 814 b->expiration_year(), b->expiration_month(), comparison_time)) | |
| 815 return a_has_valid_expiration; | |
| 816 | 813 |
| 817 return a->CompareFrecency(b, comparison_time); | 814 return a->CompareFrecency(b, comparison_time); |
| 818 }); | 815 }); |
| 819 | 816 |
| 820 return GetSuggestionsForCards(type, field_contents, cards_to_suggest); | 817 return GetSuggestionsForCards(type, field_contents, cards_to_suggest); |
| 821 } | 818 } |
| 822 | 819 |
| 823 bool PersonalDataManager::IsAutofillEnabled() const { | 820 bool PersonalDataManager::IsAutofillEnabled() const { |
| 824 return ::autofill::IsAutofillEnabled(pref_service_); | 821 return ::autofill::IsAutofillEnabled(pref_service_); |
| 825 } | 822 } |
| (...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1502 std::stable_sort(suggestions.begin(), suggestions.end(), | 1499 std::stable_sort(suggestions.begin(), suggestions.end(), |
| 1503 [](const Suggestion& a, const Suggestion& b) { | 1500 [](const Suggestion& a, const Suggestion& b) { |
| 1504 return a.match < b.match; | 1501 return a.match < b.match; |
| 1505 }); | 1502 }); |
| 1506 } | 1503 } |
| 1507 | 1504 |
| 1508 return suggestions; | 1505 return suggestions; |
| 1509 } | 1506 } |
| 1510 | 1507 |
| 1511 } // namespace autofill | 1508 } // namespace autofill |
| OLD | NEW |