| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_PAYMENTS_CONTENT_PROFILE_UTIL_H_ |
| 6 #define COMPONENTS_PAYMENTS_CONTENT_PROFILE_UTIL_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "components/autofill/core/browser/autofill_profile_comparator.h" |
| 12 |
| 13 // Utility functions used for processing and filtering address profiles |
| 14 // (AutofillProfile). |
| 15 |
| 16 namespace autofill { |
| 17 class AutofillProfile; |
| 18 } // namespace autofill |
| 19 |
| 20 namespace payments { |
| 21 |
| 22 class PaymentOptionsProvider; |
| 23 |
| 24 namespace profile_util { |
| 25 |
| 26 // Returns profiles for contact info, ordered by completeness and deduplicated. |
| 27 // |profiles| should be passed in order of frecency, and this order will be |
| 28 // preserved among equally-complete profiles. Deduplication here means that |
| 29 // profiles returned are excluded if they are a subset of a more complete or |
| 30 // more frecent profile. Completeness here refers only to the presence of the |
| 31 // fields requested per the request_payer_* fields in |options|. |
| 32 std::vector<autofill::AutofillProfile*> FilterProfilesForContact( |
| 33 const std::vector<autofill::AutofillProfile*>& profiles, |
| 34 const std::string& app_locale, |
| 35 const PaymentOptionsProvider& options); |
| 36 |
| 37 // Helper class which evaluates profiles for similarity and completeness. |
| 38 class PaymentsProfileComparator : public autofill::AutofillProfileComparator { |
| 39 public: |
| 40 PaymentsProfileComparator(const std::string& app_locale, |
| 41 const PaymentOptionsProvider& options); |
| 42 ~PaymentsProfileComparator(); |
| 43 |
| 44 // Returns true iff all of the contact info in |sub| also appears in |super|. |
| 45 // Only operates on fields requested in |options|. |
| 46 bool IsContactEqualOrSuperset(const autofill::AutofillProfile& super, |
| 47 const autofill::AutofillProfile& sub); |
| 48 |
| 49 // Returns the number of contact fields requested in |options| which are |
| 50 // nonempty in |profile|. |
| 51 int GetContactCompletenessScore(const autofill::AutofillProfile* profile); |
| 52 |
| 53 // Returns true iff every contact field requested in |options| is nonempty in |
| 54 // |profile|. |
| 55 bool IsContactInfoComplete(const autofill::AutofillProfile* profile); |
| 56 |
| 57 // Comparison function suitable for sorting profiles by contact completeness |
| 58 // score with std::sort. |
| 59 bool IsContactMoreComplete(const autofill::AutofillProfile* p1, |
| 60 const autofill::AutofillProfile* p2); |
| 61 |
| 62 private: |
| 63 const PaymentOptionsProvider& options_; |
| 64 }; |
| 65 |
| 66 } // namespace profile_util |
| 67 } // namespace payments |
| 68 |
| 69 #endif // COMPONENTS_PAYMENTS_CONTENT_PROFILE_UTIL_H_ |
| OLD | NEW |