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

Unified Diff: components/payments/content/payment_request_state.cc

Issue 2775553004: [WebPayments] Implementing Profile filter and dedupe (Closed)
Patch Set: include algo Created 3 years, 9 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/content/payment_request_state.cc
diff --git a/components/payments/content/payment_request_state.cc b/components/payments/content/payment_request_state.cc
index 785517d5db21a1e8cb380394b80a636fdbebfe5f..bbd7e66e7fc21acec9b1c2097cfa25cc7674a050 100644
--- a/components/payments/content/payment_request_state.cc
+++ b/components/payments/content/payment_request_state.cc
@@ -14,6 +14,7 @@
#include "components/payments/content/payment_request_spec.h"
#include "components/payments/content/payment_response_helper.h"
#include "components/payments/core/autofill_payment_instrument.h"
+#include "components/payments/core/profile_util.h"
namespace payments {
@@ -156,12 +157,22 @@ void PaymentRequestState::PopulateProfileCache() {
profile_cache_.push_back(
base::MakeUnique<autofill::AutofillProfile>(*profiles[i]));
- // TODO(tmartino): Implement deduplication rules specific to shipping and
- // contact profiles.
+ // TODO(tmartino): Implement deduplication rules specific to shipping
+ // profiles.
shipping_profiles_.push_back(profile_cache_[i].get());
- contact_profiles_.push_back(profile_cache_[i].get());
}
+ std::vector<autofill::AutofillProfile*> raw_profiles_for_filtering(
+ profile_cache_.size());
+ std::transform(profile_cache_.begin(), profile_cache_.end(),
+ raw_profiles_for_filtering.begin(),
+ [](const std::unique_ptr<autofill::AutofillProfile>& p) {
+ return p.get();
+ });
+
+ contact_profiles_ = profile_util::FilterProfilesForContact(
+ raw_profiles_for_filtering, GetApplicationLocale(), spec_);
+
// Create the list of available instruments.
const std::vector<autofill::CreditCard*>& cards =
personal_data_manager_->GetCreditCardsToSuggest();
@@ -234,32 +245,8 @@ bool PaymentRequestState::ArePaymentOptionsSatisfied() {
if (spec_->request_shipping() && selected_shipping_profile_ == nullptr)
return false;
- // TODO(mathp): Make an encompassing class to validate contact info.
- if (spec_->request_payer_name() &&
- (selected_contact_profile_ == nullptr ||
- selected_contact_profile_
- ->GetInfo(autofill::AutofillType(autofill::NAME_FULL), app_locale_)
- .empty())) {
- return false;
- }
- if (spec_->request_payer_email() &&
- (selected_contact_profile_ == nullptr ||
- selected_contact_profile_
- ->GetInfo(autofill::AutofillType(autofill::EMAIL_ADDRESS),
- app_locale_)
- .empty())) {
- return false;
- }
- if (spec_->request_payer_phone() &&
- (selected_contact_profile_ == nullptr ||
- selected_contact_profile_
- ->GetInfo(autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER),
- app_locale_)
- .empty())) {
- return false;
- }
-
- return true;
+ profile_util::PaymentsProfileComparator comparator(app_locale_, spec_);
+ return comparator.IsContactInfoComplete(selected_contact_profile_);
}
void PaymentRequestState::UpdateSelectedShippingOption() {

Powered by Google App Engine
This is Rietveld 408576698