| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #ifndef COMPONENTS_PAYMENTS_CORE_PAYMENTS_PROFILE_COMPARATOR_H_ | 5 #ifndef COMPONENTS_PAYMENTS_CORE_PAYMENTS_PROFILE_COMPARATOR_H_ |
| 6 #define COMPONENTS_PAYMENTS_CORE_PAYMENTS_PROFILE_COMPARATOR_H_ | 6 #define COMPONENTS_PAYMENTS_CORE_PAYMENTS_PROFILE_COMPARATOR_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 // Returns the number of contact fields requested in |options| which are | 65 // Returns the number of contact fields requested in |options| which are |
| 66 // nonempty in |profile|. | 66 // nonempty in |profile|. |
| 67 int GetContactCompletenessScore( | 67 int GetContactCompletenessScore( |
| 68 const autofill::AutofillProfile* profile) const; | 68 const autofill::AutofillProfile* profile) const; |
| 69 | 69 |
| 70 // Returns true iff every contact field requested in |options| is nonempty in | 70 // Returns true iff every contact field requested in |options| is nonempty in |
| 71 // |profile|. | 71 // |profile|. |
| 72 bool IsContactInfoComplete(const autofill::AutofillProfile* profile) const; | 72 bool IsContactInfoComplete(const autofill::AutofillProfile* profile) const; |
| 73 | 73 |
| 74 // Returns profiles for shipping, ordered by completeness. |profiles| should | 74 // Comparison function suitable for sorting profiles by contact completeness |
| 75 // be passed in order of frecency, and this order will be preserved among | 75 // score with std::sort. |
| 76 // equally-complete profiles. | 76 bool IsContactMoreComplete(const autofill::AutofillProfile* p1, |
| 77 std::vector<autofill::AutofillProfile*> FilterProfilesForShipping( | 77 const autofill::AutofillProfile* p2) const; |
| 78 const std::vector<autofill::AutofillProfile*>& profiles) const; | |
| 79 | 78 |
| 80 int GetShippingCompletenessScore( | 79 // Returns a localized string to be displayed in UI indicating what action, |
| 81 const autofill::AutofillProfile* profile) const; | 80 // if any, must be taken for the given profile to be used as contact info. |
| 81 base::string16 GetStringForMissingContactFields( |
| 82 const autofill::AutofillProfile& profile) const; |
| 82 | 83 |
| 83 // Returns true iff every field needed to use |profile| as a shipping address | 84 // Returns true iff every field needed to use |profile| as a shipping address |
| 84 // is populated. | 85 // is populated. |
| 85 bool IsShippingComplete(const autofill::AutofillProfile* profile) const; | 86 bool IsShippingComplete(const autofill::AutofillProfile* profile) const; |
| 86 | 87 |
| 87 // Returns a localized string to be displayed in UI indicating what action, | 88 // Returns a localized string to be displayed in UI indicating what action, |
| 88 // if any, must be taken for the given profile to be used as contact info. | |
| 89 base::string16 GetStringForMissingContactFields( | |
| 90 const autofill::AutofillProfile& profile) const; | |
| 91 | |
| 92 // Returns a localized string to be displayed in UI indicating what action, | |
| 93 // if any, must be taken for the given profile to be used as a shipping | 89 // if any, must be taken for the given profile to be used as a shipping |
| 94 // address. | 90 // address. |
| 95 base::string16 GetStringForMissingShippingFields( | 91 base::string16 GetStringForMissingShippingFields( |
| 96 const autofill::AutofillProfile& profile) const; | 92 const autofill::AutofillProfile& profile) const; |
| 97 | 93 |
| 98 // Clears the cached evaluation result for |profile|. Must be called when a | 94 // Clears the cached evaluation result for |profile|. Must be called when a |
| 99 // profile is modified and saved during the course of a PaymentRequest. | 95 // profile is modified and saved during the course of a PaymentRequest. |
| 100 void Invalidate(const autofill::AutofillProfile& profile); | 96 void Invalidate(const autofill::AutofillProfile& profile); |
| 101 | 97 |
| 102 private: | 98 private: |
| 103 ProfileFields ComputeMissingFields( | 99 ProfileFields ComputeMissingFields( |
| 104 const autofill::AutofillProfile& profile) const; | 100 const autofill::AutofillProfile& profile) const; |
| 105 ProfileFields GetRequiredProfileFieldsForContact() const; | 101 ProfileFields GetRequiredProfileFieldsForContact() const; |
| 106 ProfileFields GetRequiredProfileFieldsForShipping() const; | 102 ProfileFields GetRequiredProfileFieldsForShipping() const; |
| 107 base::string16 GetStringForMissingFields(ProfileFields fields) const; | 103 base::string16 GetStringForMissingFields(ProfileFields fields) const; |
| 108 bool AreRequiredAddressFieldsPresent( | 104 bool AreRequiredAddressFieldsPresent( |
| 109 const autofill::AutofillProfile& profile) const; | 105 const autofill::AutofillProfile& profile) const; |
| 110 | |
| 111 // Comparison functions suitable for sorting profiles by completeness | |
| 112 // score with std::sort. | |
| 113 bool IsContactMoreComplete(const autofill::AutofillProfile* p1, | |
| 114 const autofill::AutofillProfile* p2) const; | |
| 115 bool IsShippingMoreComplete(const autofill::AutofillProfile* p1, | |
| 116 const autofill::AutofillProfile* p2) const; | |
| 117 | |
| 118 mutable std::map<std::string, ProfileFields> cache_; | 106 mutable std::map<std::string, ProfileFields> cache_; |
| 119 const PaymentOptionsProvider& options_; | 107 const PaymentOptionsProvider& options_; |
| 120 }; | 108 }; |
| 121 | 109 |
| 122 } // namespace payments | 110 } // namespace payments |
| 123 | 111 |
| 124 #endif // COMPONENTS_PAYMENTS_CORE_PAYMENTS_PROFILE_COMPARATOR_H_ | 112 #endif // COMPONENTS_PAYMENTS_CORE_PAYMENTS_PROFILE_COMPARATOR_H_ |
| OLD | NEW |