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

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

Issue 2742813004: [Payments] Refactor into PaymentRequestState and Spec (Closed)
Patch Set: don't stop rebasin' 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
« no previous file with comments | « components/payments/content/payment_request.cc ('k') | components/payments/content/payment_request_spec.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/payments/content/payment_request_spec.h
diff --git a/components/payments/content/payment_request_spec.h b/components/payments/content/payment_request_spec.h
new file mode 100644
index 0000000000000000000000000000000000000000..dbefd2b61e67376a8065156aa53d7acaf1f728cd
--- /dev/null
+++ b/components/payments/content/payment_request_spec.h
@@ -0,0 +1,76 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_SPEC_H_
+#define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_SPEC_H_
+
+#include <string>
+#include <vector>
+
+#include "base/macros.h"
+#include "base/observer_list.h"
+#include "components/payments/content/payment_request.mojom.h"
+
+namespace payments {
+
+// The spec contains all the options that the merchant has specified about this
+// Payment Request. It's a (mostly) read-only view, which can be updated in
+// certain occasions by the merchant (see API).
+class PaymentRequestSpec {
+ public:
+ // Any class call add itself as Observer via AddObserver() and receive
+ // notification about spec events.
+ class Observer {
+ public:
+ // Called when the provided spec (details, options, method_data) is invalid.
+ virtual void OnInvalidSpecProvided() = 0;
+
+ protected:
+ virtual ~Observer() {}
+ };
+
+ PaymentRequestSpec(mojom::PaymentOptionsPtr options,
+ mojom::PaymentDetailsPtr details,
+ std::vector<mojom::PaymentMethodDataPtr> method_data,
+ PaymentRequestSpec::Observer* observer);
+ ~PaymentRequestSpec();
+
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
+ 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; }
+
+ const std::vector<std::string>& supported_card_networks() {
+ return supported_card_networks_;
+ }
+
+ const mojom::PaymentDetails& details() const { return *details_.get(); }
+ const mojom::PaymentOptions& options() const { return *options_.get(); }
+
+ private:
+ // Validates the |method_data| and fills |supported_card_networks_|.
+ void PopulateValidatedMethodData(
+ const std::vector<mojom::PaymentMethodDataPtr>& method_data);
+
+ // Will notify all observers that the spec is invalid.
+ void NotifyOnInvalidSpecProvided();
+
+ mojom::PaymentOptionsPtr options_;
+ mojom::PaymentDetailsPtr details_;
+
+ // A list of supported basic card networks, in order that they were specified
+ // by the merchant.
+ std::vector<std::string> supported_card_networks_;
+
+ base::ObserverList<Observer> observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(PaymentRequestSpec);
+};
+
+} // namespace payments
+
+#endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_REQUEST_SPEC_H_
« no previous file with comments | « components/payments/content/payment_request.cc ('k') | components/payments/content/payment_request_spec.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698