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

Unified Diff: components/payments/payment_request.cc

Issue 2643643006: [WebPayments] Adding something resembling Shipping Address list (Closed)
Patch Set: Cleanup 2 Created 3 years, 11 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/payment_request.cc
diff --git a/components/payments/payment_request.cc b/components/payments/payment_request.cc
index 282b3fa38afad3d8ef83f6db57f9f05c532ca0ad..1715ce471c2fec7de64cb9700546731a85e0c186 100644
--- a/components/payments/payment_request.cc
+++ b/components/payments/payment_request.cc
@@ -22,7 +22,9 @@ PaymentRequest::PaymentRequest(
: web_contents_(web_contents),
delegate_(std::move(delegate)),
manager_(manager),
- binding_(this, std::move(request)) {
+ binding_(this, std::move(request)),
+ selected_shipping_profile_(nullptr),
+ selected_contact_profile_(nullptr) {
binding_.set_connection_error_handler(
base::Bind(&PaymentRequest::OnError, base::Unretained(this)));
}
@@ -44,6 +46,7 @@ void PaymentRequest::Init(
}
client_ = std::move(client);
details_ = std::move(details);
+ SetDefaultProfileSelections();
}
void PaymentRequest::Show() {
@@ -75,17 +78,46 @@ CurrencyFormatter* PaymentRequest::GetOrCreateCurrencyFormatter(
return currency_formatter_.get();
}
-autofill::AutofillProfile* PaymentRequest::GetCurrentlySelectedProfile() {
- // TODO(tmartino): Implement more sophisticated algorithm for populating
- // this when it starts empty.
- if (!profile_) {
+std::vector<autofill::AutofillProfile*> PaymentRequest::GetProfiles() {
+ if (profile_cache_.empty()) {
autofill::PersonalDataManager* data_manager =
delegate_->GetPersonalDataManager();
- auto profiles = data_manager->GetProfiles();
- if (!profiles.empty())
- profile_ = base::MakeUnique<autofill::AutofillProfile>(*profiles[0]);
+ std::vector<autofill::AutofillProfile*> profiles =
+ data_manager->GetProfilesToSuggest();
+
+ // PaymentRequest may outlive the Profiles returned by the Data Manager.
+ // Thus, we store copies, and return a vector of pointers to these copies.
+ for (autofill::AutofillProfile* profile : profiles) {
+ profile_cache_.push_back(
+ base::MakeUnique<autofill::AutofillProfile>(*profile));
+ }
}
- return profile_ ? profile_.get() : nullptr;
+
+ std::vector<autofill::AutofillProfile*> return_profiles(
+ profile_cache_.size());
+ std::transform(profile_cache_.begin(), profile_cache_.end(),
+ return_profiles.begin(),
+ [](const std::unique_ptr<autofill::AutofillProfile>& profile) {
+ return profile.get();
+ });
+
+ return return_profiles;
+}
+
+autofill::AutofillProfile* PaymentRequest::GetSelectedShippingProfile() {
please use gerrit instead 2017/01/20 19:32:53 Here and below: Simple getters and settings shoul
tmartino 2017/01/25 00:08:41 Done
+ return selected_shipping_profile_;
+}
+
+void PaymentRequest::SetShippingProfile(autofill::AutofillProfile* profile) {
+ selected_shipping_profile_ = profile;
+}
+
+autofill::AutofillProfile* PaymentRequest::GetSelectedContactProfile() {
+ return selected_contact_profile_;
+}
+
+void PaymentRequest::SetContactProfile(autofill::AutofillProfile* profile) {
+ selected_contact_profile_ = profile;
}
autofill::CreditCard* PaymentRequest::GetCurrentlySelectedCreditCard() {
@@ -107,4 +139,15 @@ autofill::CreditCard* PaymentRequest::GetCurrentlySelectedCreditCard() {
return first_complete_card == cards.end() ? nullptr : *first_complete_card;
}
+void PaymentRequest::SetDefaultProfileSelections() {
+ auto profiles = GetProfiles();
+ if (!profiles.empty()) {
+ // TODO(tmartino): Examine the details to determine whether the shipping
+ // address should be prefilled, and what constraints apply to profiles
+ // for prefilling the contact info.
+ SetShippingProfile(profiles[0]);
+ SetContactProfile(profiles[0]);
+ }
+}
+
} // namespace payments
« components/payments/payment_request.h ('K') | « components/payments/payment_request.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698