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

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

Issue 2789093002: [Payments] Desktop: implement shipping address/option change (Closed)
Patch Set: compile fix 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_spec.cc
diff --git a/components/payments/content/payment_request_spec.cc b/components/payments/content/payment_request_spec.cc
index bcc98b441bded800d4de21d2e054274536f98189..1fe9b0049ef27709986e4590ae8cbe30c32112c7 100644
--- a/components/payments/content/payment_request_spec.cc
+++ b/components/payments/content/payment_request_spec.cc
@@ -20,13 +20,23 @@ PaymentRequestSpec::PaymentRequestSpec(
const std::string& app_locale)
: options_(std::move(options)),
details_(std::move(details)),
- app_locale_(app_locale) {
+ app_locale_(app_locale),
+ selected_shipping_option_(nullptr),
+ observer_for_testing_(nullptr) {
if (observer)
AddObserver(observer);
+ UpdateSelectedShippingOption();
PopulateValidatedMethodData(method_data);
}
PaymentRequestSpec::~PaymentRequestSpec() {}
+void PaymentRequestSpec::UpdateWith(mojom::PaymentDetailsPtr details) {
+ details_ = std::move(details);
+ // We reparse the |details_| and update the observers.
+ UpdateSelectedShippingOption();
+ NotifyOnSpecUpdated();
+}
+
void PaymentRequestSpec::AddObserver(Observer* observer) {
CHECK(observer);
observers_.AddObserver(observer);
@@ -164,9 +174,34 @@ void PaymentRequestSpec::PopulateValidatedMethodData(
supported_card_networks_.end());
}
+void PaymentRequestSpec::UpdateSelectedShippingOption() {
+ if (!request_shipping())
+ return;
+
+ // As per the spec, the selected shipping option should initially be the last
+ // one in the array that has its selected field set to true.
+ auto selected_shipping_option_it = std::find_if(
+ details().shipping_options.rbegin(), details().shipping_options.rend(),
+ [](const payments::mojom::PaymentShippingOptionPtr& element) {
+ return element->selected;
+ });
+ if (selected_shipping_option_it != details().shipping_options.rend()) {
+ selected_shipping_option_ = selected_shipping_option_it->get();
+ }
+}
+
void PaymentRequestSpec::NotifyOnInvalidSpecProvided() {
for (auto& observer : observers_)
observer.OnInvalidSpecProvided();
+ if (observer_for_testing_)
+ observer_for_testing_->OnInvalidSpecProvided();
+}
+
+void PaymentRequestSpec::NotifyOnSpecUpdated() {
+ for (auto& observer : observers_)
+ observer.OnSpecUpdated();
+ if (observer_for_testing_)
+ observer_for_testing_->OnSpecUpdated();
}
CurrencyFormatter* PaymentRequestSpec::GetOrCreateCurrencyFormatter(
« no previous file with comments | « components/payments/content/payment_request_spec.h ('k') | components/payments/content/payment_request_spec_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698