Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Unified Diff: components/payments/core/profile_util.h

Issue 2847503002: [WebPayments] Show labels on incomplete profiles (Closed)
Patch Set: ios namespace Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/payments/core/profile_util.h
diff --git a/components/payments/core/profile_util.h b/components/payments/core/profile_util.h
index 6693fe854c8d6b7dce341d75d7fa50da10cb1165..4f3192e004304b286d7dffacd60a72e9c866d9c9 100644
--- a/components/payments/core/profile_util.h
+++ b/components/payments/core/profile_util.h
@@ -5,6 +5,7 @@
#ifndef COMPONENTS_PAYMENTS_CONTENT_PROFILE_UTIL_H_
#define COMPONENTS_PAYMENTS_CONTENT_PROFILE_UTIL_H_
+#include <map>
#include <string>
#include <vector>
@@ -21,49 +22,89 @@ 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,
- const PaymentOptionsProvider& options);
-
// Helper class which evaluates profiles for similarity and completeness.
+// Profiles are evaluated once for completeness, and the result is cached,
+// meaning one instance of this class should be used per-request to avoid
+// redoing expensive validation checks.
+// Note that, if a profile is modified and saved during the course of the
+// PaymentRequest, it is important to call the Invalidate method to ensure
+// it is properly evaluated.
class PaymentsProfileComparator : public autofill::AutofillProfileComparator {
public:
+ // Bitmask of potentially-required fields used in evaluating completeness.
+ using ProfileFields = uint32_t;
+ const static ProfileFields kName = 1 << 0;
+ const static ProfileFields kPhone = 1 << 1;
+ const static ProfileFields kEmail = 1 << 2;
+ const static ProfileFields kAddress = 1 << 3;
+
PaymentsProfileComparator(const std::string& app_locale,
const PaymentOptionsProvider& options);
~PaymentsProfileComparator();
+ // Returns a bitmask indicating which fields (or groups of fields) on this
+ // profile are not complete and valid.
+ ProfileFields GetMissingProfileFields(
+ const autofill::AutofillProfile* profile) const;
+
+ // 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;
+
// Returns true iff all of the contact info in |sub| also appears in |super|.
// Only operates on fields requested in |options|.
bool IsContactEqualOrSuperset(const autofill::AutofillProfile& super,
- const autofill::AutofillProfile& sub);
+ const autofill::AutofillProfile& sub) const;
// Returns the number of contact fields requested in |options| which are
// nonempty in |profile|.
- int GetContactCompletenessScore(const autofill::AutofillProfile* profile);
+ int GetContactCompletenessScore(
+ const autofill::AutofillProfile* profile) const;
// Returns true iff every contact field requested in |options| is nonempty in
// |profile|.
- bool IsContactInfoComplete(const autofill::AutofillProfile* profile);
+ bool IsContactInfoComplete(const autofill::AutofillProfile* profile) const;
// Comparison function suitable for sorting profiles by contact completeness
// score with std::sort.
bool IsContactMoreComplete(const autofill::AutofillProfile* p1,
- const autofill::AutofillProfile* p2);
+ const autofill::AutofillProfile* p2) const;
+
+ // Returns a localized string to be displayed in UI indicating what action,
+ // if any, must be taken for the given profile to be used as contact info.
+ base::string16 GetStringForMissingContactFields(
+ const autofill::AutofillProfile& profile) const;
+
+ // Returns true iff every field needed to use |profile| as a shipping address
+ // is populated.
+ bool IsShippingComplete(const autofill::AutofillProfile* profile) const;
+
+ // Returns a localized string to be displayed in UI indicating what action,
+ // if any, must be taken for the given profile to be used as a shipping
+ // address.
+ base::string16 GetStringForMissingShippingFields(
+ const autofill::AutofillProfile& profile) const;
+
+ // Clears the cached evaluation result for |profile|. Must be called when a
+ // profile is modified and saved during the course of a PaymentRequest.
+ void Invalidate(const autofill::AutofillProfile& profile);
private:
+ ProfileFields GetRequiredProfileFieldsForContact() const;
+ ProfileFields GetRequiredProfileFieldsForShipping() const;
+ base::string16 ProfileFieldsToUIString(ProfileFields fields) const;
+ bool AreRequiredAddressFieldsPresent(
+ const autofill::AutofillProfile& profile) const;
+ mutable std::map<std::string, ProfileFields> cache_;
const PaymentOptionsProvider& options_;
};
-} // namespace profile_util
} // namespace payments
#endif // COMPONENTS_PAYMENTS_CONTENT_PROFILE_UTIL_H_

Powered by Google App Engine
This is Rietveld 408576698