Chromium Code Reviews| Index: components/payments/core/profile_util.h |
| diff --git a/components/payments/core/profile_util.h b/components/payments/core/profile_util.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..58b7bfacac7be9a441cda7ed5b45adcf18597450 |
| --- /dev/null |
| +++ b/components/payments/core/profile_util.h |
| @@ -0,0 +1,68 @@ |
| +// 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" |
| + |
| +// Utility functions used for processing and filtering profiles. |
|
Mathieu
2017/04/03 19:11:53
*address profiles (AutofillProfile)
tmartino
2017/04/04 21:00:22
Done
|
| + |
| +namespace autofill { |
| +class AutofillProfile; |
| +} // namespace autofill |
| + |
| +namespace payments { |
| + |
| +class PaymentOptionsProvider; |
| + |
| +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 |options|. |
| +std::vector<autofill::AutofillProfile*> FilterProfilesForContact( |
| + const std::vector<autofill::AutofillProfile*>& profiles, |
| + const std::string& app_locale, |
| + PaymentOptionsProvider* options); |
|
Mathieu
2017/04/03 19:11:53
can this be const PaymentOptionsProvider& options?
tmartino
2017/04/04 21:00:22
I'm open to it. However, my search found lots of e
Mathieu
2017/04/05 13:43:10
The difference is that there are non-const methods
|
| + |
| +// Helper class which evaluates profiles for similarity and completeness. |
| +class PaymentsProfileComparator : public autofill::AutofillProfileComparator { |
| + public: |
| + PaymentsProfileComparator(const std::string& app_locale, |
| + PaymentOptionsProvider* options); |
|
Mathieu
2017/04/03 19:11:53
same
|
| + ~PaymentsProfileComparator(); |
| + |
| + // Returns true iff all of the contact info in |sub| also appears in |super|. |
| + // Only operates on fields requested in |options|. |
| + bool IsContactEqualOrSuperset(autofill::AutofillProfile* super, |
| + autofill::AutofillProfile* sub); |
| + |
| + // Returns the number of contact fields requested in |options| which are |
| + // nonempty in |profile|. |
| + int GetContactCompletenessScore(autofill::AutofillProfile* profile); |
| + |
| + // Returns true every contact field requested in |options| is nonempty in |
| + // |profile|. |
| + bool IsContactInfoComplete(autofill::AutofillProfile* profile); |
| + |
| + // Comparison function suitable for sorting profiles by contact completeness |
| + // score with std::sort. |
| + bool IsContactMoreComplete(autofill::AutofillProfile* p1, |
| + autofill::AutofillProfile* p2); |
| + |
| + private: |
| + PaymentOptionsProvider* options_; |
| +}; |
| + |
| +} // namespace profile_util |
| +} // namespace payments |
| + |
| +#endif // COMPONENTS_PAYMENTS_CONTENT_PROFILE_UTIL_H_ |