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

Unified Diff: components/payments/content/payment_request.h

Issue 2742813004: [Payments] Refactor into PaymentRequestState and Spec (Closed)
Patch Set: deps 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.h
diff --git a/components/payments/content/payment_request.h b/components/payments/content/payment_request.h
index 7933e61ffcd379d0b5e751265c5209d81006830d..b12bf66ad8b1cca4df7c1433aecc2f31fd35c22d 100644
--- a/components/payments/content/payment_request.h
+++ b/components/payments/content/payment_request.h
@@ -10,10 +10,10 @@
#include <vector>
#include "base/macros.h"
-#include "base/observer_list.h"
#include "components/payments/content/payment_request.mojom.h"
#include "components/payments/content/payment_request_delegate.h"
-#include "components/payments/core/payment_instrument.h"
+#include "components/payments/content/payment_request_spec.h"
+#include "components/payments/content/payment_request_state.h"
#include "mojo/public/cpp/bindings/binding.h"
namespace autofill {
@@ -32,18 +32,9 @@ class CurrencyFormatter;
class PaymentRequestWebContentsManager;
class PaymentRequest : public mojom::PaymentRequest,
- public PaymentInstrument::Delegate {
+ public PaymentRequestSpec::Observer,
+ public PaymentRequestState::Delegate {
public:
- class Observer {
- public:
- // Called when the information (payment method, address/contact info,
- // shipping option) changes.
- virtual void OnSelectedInformationChanged() = 0;
-
- protected:
- virtual ~Observer() {}
- };
-
PaymentRequest(
content::WebContents* web_contents,
std::unique_ptr<PaymentRequestDelegate> delegate,
@@ -62,11 +53,14 @@ class PaymentRequest : public mojom::PaymentRequest,
void Complete(payments::mojom::PaymentComplete result) override;
void CanMakePayment() override;
- // PaymentInstrument::Delegate:
- void OnInstrumentDetailsReady(
- const std::string& method_name,
- const std::string& stringified_details) override;
- void OnInstrumentDetailsError() override {}
+ // PaymentRequestSpec::Observer:
+ void OnInvalidSpecProvided() override;
+
+ // PaymentRequestState::Delegate:
+ const std::string& GetApplicationLocale() override;
+ const std::vector<autofill::AutofillProfile*>& GetBillingProfiles() override;
+
+ void OnPaymentResponseAvailable(mojom::PaymentResponsePtr response) override;
// Called when the user explicitely cancelled the flow. Will send a message
// to the renderer which will indirectly destroy this object (through
@@ -82,9 +76,6 @@ class PaymentRequest : public mojom::PaymentRequest,
// Called when the user clicks on the "Pay" button.
void Pay();
- void AddObserver(Observer* observer);
- void RemoveObserver(Observer* observer);
-
// Returns the CurrencyFormatter instance for this PaymentRequest.
// |locale_name| should be the result of the browser's GetApplicationLocale().
// Note: Having multiple currencies per PaymentRequest is not supported; hence
@@ -116,48 +107,14 @@ class PaymentRequest : public mojom::PaymentRequest,
return credit_cards_;
}
- // Gets the Autofill Profile representing the shipping address or contact
- // information currently selected for this PaymentRequest flow. Can return
- // null.
- autofill::AutofillProfile* selected_shipping_profile() const {
- return selected_shipping_profile_;
- }
- autofill::AutofillProfile* selected_contact_profile() const {
- return selected_contact_profile_;
- }
- // Returns the currently selected credit card for this PaymentRequest flow.
- // It's not guaranteed to be complete. Returns nullptr if there is no selected
- // card.
- autofill::CreditCard* selected_credit_card() { return selected_credit_card_; }
-
- payments::mojom::PaymentShippingOption* selected_shipping_option() {
- return selected_shipping_option_;
- }
-
- // Sets the |profile| to be the selected one and will update state and notify
- // observers.
- void SetSelectedShippingProfile(autofill::AutofillProfile* profile);
- void SetSelectedContactProfile(autofill::AutofillProfile* profile);
- void SetSelectedCreditCard(autofill::CreditCard* card);
-
autofill::PersonalDataManager* personal_data_manager() {
return delegate_->GetPersonalDataManager();
}
- const std::string& locale() { return delegate_->GetApplicationLocale(); }
- payments::mojom::PaymentDetails* details() { return details_.get(); }
- payments::mojom::PaymentOptions* options() { return options_.get(); }
- const std::vector<std::string>& supported_card_networks() {
- return supported_card_networks_;
- }
content::WebContents* web_contents() { return web_contents_; }
- bool request_shipping() const { return options_->request_shipping; }
- bool request_payer_name() const { return options_->request_payer_name; }
- bool request_payer_phone() const { return options_->request_payer_phone; }
- bool request_payer_email() const { return options_->request_payer_email; }
-
- bool is_ready_to_pay() { return is_ready_to_pay_; }
+ PaymentRequestSpec* spec() { return spec_.get(); }
+ PaymentRequestState* state() { return state_.get(); }
private:
// Fetches the Autofill Profiles for this user from the PersonalDataManager,
@@ -168,45 +125,16 @@ class PaymentRequest : public mojom::PaymentRequest,
// well as the selected Credit Card.
void SetDefaultProfileSelections();
- // Validates the |method_data| and fills |supported_card_networks_|.
- void PopulateValidatedMethodData(
- const std::vector<payments::mojom::PaymentMethodDataPtr>& method_data);
-
- // Updates |is_ready_to_pay_| with the current state, by validating that all
- // the required information is available and notify observers.
- void UpdateIsReadyToPayAndNotifyObservers();
-
- // Notifies all observers that selected information has changed.
- void NotifyOnSelectedInformationChanged();
-
- // Returns whether the selected data satisfies the PaymentDetails requirements
- // (payment methods).
- bool ArePaymentDetailsSatisfied();
- // Returns whether the selected data satisfies the PaymentOptions requirements
- // (contact info, shipping address).
- bool ArePaymentOptionsSatisfied();
-
- // Updates the selected_shipping_option based on the data passed to this
- // payment request by the website. This will set selected_shipping_option_ to
- // the last option marked selected in the options array.
- void UpdateSelectedShippingOptionFromDetails();
-
content::WebContents* web_contents_;
std::unique_ptr<PaymentRequestDelegate> delegate_;
// |manager_| owns this PaymentRequest.
PaymentRequestWebContentsManager* manager_;
mojo::Binding<payments::mojom::PaymentRequest> binding_;
payments::mojom::PaymentRequestClientPtr client_;
- payments::mojom::PaymentDetailsPtr details_;
- payments::mojom::PaymentOptionsPtr options_;
std::unique_ptr<CurrencyFormatter> currency_formatter_;
- // A set of supported basic card networks.
- std::vector<std::string> supported_card_networks_;
- bool is_ready_to_pay_;
- std::unique_ptr<PaymentInstrument> selected_payment_instrument_;
- mojom::PaymentResponsePtr payment_response_;
- base::ObserverList<Observer> observers_;
+ std::unique_ptr<PaymentRequestSpec> spec_;
+ std::unique_ptr<PaymentRequestState> state_;
// Profiles may change due to (e.g.) sync events, so profiles are cached after
// loading and owned here. They are populated once only, and ordered by
@@ -214,14 +142,8 @@ class PaymentRequest : public mojom::PaymentRequest,
std::vector<std::unique_ptr<autofill::AutofillProfile>> profile_cache_;
please use gerrit instead 2017/03/14 16:35:21 Should these be moved to state_?
Mathieu 2017/03/14 18:05:39 OK. Was trying not to conflate the state and the l
std::vector<autofill::AutofillProfile*> shipping_profiles_;
std::vector<autofill::AutofillProfile*> contact_profiles_;
- autofill::AutofillProfile* selected_shipping_profile_;
- autofill::AutofillProfile* selected_contact_profile_;
std::vector<std::unique_ptr<autofill::CreditCard>> card_cache_;
std::vector<autofill::CreditCard*> credit_cards_;
- autofill::CreditCard* selected_credit_card_;
- // This is owned by |details_|, which is owned by this object and lives until
- // |this| is destructed so it's safe to keep this raw pointer.
- payments::mojom::PaymentShippingOption* selected_shipping_option_;
DISALLOW_COPY_AND_ASSIGN(PaymentRequest);
};

Powered by Google App Engine
This is Rietveld 408576698