Chromium Code Reviews| Index: components/payments/content/profile_util.h |
| diff --git a/components/payments/content/profile_util.h b/components/payments/content/profile_util.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4f5ec94fd5149cc8566c2dbdc7a87d82835a36fb |
| --- /dev/null |
| +++ b/components/payments/content/profile_util.h |
| @@ -0,0 +1,66 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +#ifndef COMPONENTS_PAYMENTS_CONTENT_PROFILE_UTIL_H_ |
| +#define COMPONENTS_PAYMENTS_CONTENT_PROFILE_UTIL_H_ |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "components/autofill/core/browser/autofill_profile_comparator.h" |
| +#include "components/payments/content/payment_request_spec.h" |
| + |
| +// Utility functions used for processing and filtering profiles. |
| +// TODO(tmartino): Remove dependency on PaymentRequestSpec and move to core. |
|
Mathieu
2017/03/24 16:16:02
If it's just for the three requestPayer* bool, I w
tmartino
2017/03/24 16:28:52
One thing anthonyvd and I discussed was potentiall
Mathieu
2017/03/24 16:37:27
I would use the booleans for now and re-evaluate l
tmartino
2017/04/03 16:42:55
Looking at iOS, and talking to mahmadi@, actually
|
| + |
| +namespace autofill { |
| +class AutofillProfile; |
| +} // namespace autofill |
| + |
| +namespace payments { |
| +namespace profile_util { |
| + |
| +// Returns profiles for contact info, ordered by completeness and deduplicated. |
| +// |profiles| should be passed in order of frecency, and this order will be |
| +// preserved among equally-complete profiles. Deduplication here means that |
| +// profiles returned are excluded if they are a subset of a more complete or |
| +// more frecent profile. Completeness here refers only to the presence of the |
| +// fields requested per the request_payer_* fields in |spec|. |
| +std::vector<autofill::AutofillProfile*> FilterProfilesForContact( |
| + const std::vector<autofill::AutofillProfile*>& profiles, |
| + const std::string& app_locale, |
| + PaymentRequestSpec* spec); |
| + |
| +// Helper class which evaluates profiles for similarity and completeness. |
| +class PaymentsProfileComparator : public autofill::AutofillProfileComparator { |
| + public: |
| + PaymentsProfileComparator(const std::string& app_locale, |
| + PaymentRequestSpec* spec); |
| + ~PaymentsProfileComparator(); |
| + |
| + // Returns true iff all of the contact info in |sub| also appears in |super|. |
| + // Only operates on fields requested in |spec|. |
| + bool IsContactEqualOrSuperset(autofill::AutofillProfile* super, |
| + autofill::AutofillProfile* sub); |
| + |
| + // Returns the number of contact fields requested in |spec| which are nonempty |
| + // in |profile|. |
| + int GetContactCompletenessScore(autofill::AutofillProfile* profile); |
| + |
| + // Returns true every contact field requested in |spec| is nonempty in |
| + // |profile|. |
| + bool IsContactInfoComplete(autofill::AutofillProfile* profile); |
| + |
| + // Comparison function suitable for sorting profiles by contact completeness |
| + // score with std::sort. |
| + bool CompareContactCompleteness(autofill::AutofillProfile* p1, |
|
Roger McFarlane (Chromium)
2017/03/24 18:23:16
nit: this name doesn't really suggest a boolean re
tmartino
2017/04/03 16:42:54
Done.
|
| + autofill::AutofillProfile* p2); |
| + |
| + private: |
| + PaymentRequestSpec* spec_; |
| +}; |
| + |
| +} // namespace profile_util |
| +} // namespace payments |
| + |
| +#endif // COMPONENTS_PAYMENTS_CONTENT_PROFILE_UTIL_H_ |