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

Unified Diff: components/payments/payment_request.cc

Issue 2611253004: [Payment Request] Change the lifetime management of PaymentRequestImpl (Closed)
Patch Set: PaymentRequestImpl -> PaymentRequest 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
« no previous file with comments | « components/payments/payment_request.h ('k') | components/payments/payment_request_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/payments/payment_request.cc
diff --git a/components/payments/payment_request.cc b/components/payments/payment_request.cc
new file mode 100644
index 0000000000000000000000000000000000000000..538bea15975fec228e594a2756c94feea9b03955
--- /dev/null
+++ b/components/payments/payment_request.cc
@@ -0,0 +1,59 @@
+// Copyright 2016 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.
+
+#include "components/payments/payment_request.h"
+
+#include "components/payments/payment_details_validation.h"
+#include "components/payments/payment_request_delegate.h"
+#include "components/payments/payment_request_web_contents_manager.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/web_contents.h"
+
+namespace payments {
+
+PaymentRequest::PaymentRequest(
+ content::WebContents* web_contents,
+ std::unique_ptr<PaymentRequestDelegate> delegate,
+ PaymentRequestWebContentsManager* manager,
+ mojo::InterfaceRequest<payments::mojom::PaymentRequest> request)
+ : web_contents_(web_contents),
+ delegate_(std::move(delegate)),
+ manager_(manager),
+ binding_(this, std::move(request)) {
+ binding_.set_connection_error_handler(
+ base::Bind(&PaymentRequest::OnError, base::Unretained(this)));
+}
+
+PaymentRequest::~PaymentRequest() {}
+
+void PaymentRequest::Init(
+ payments::mojom::PaymentRequestClientPtr client,
+ std::vector<payments::mojom::PaymentMethodDataPtr> methodData,
+ payments::mojom::PaymentDetailsPtr details,
+ payments::mojom::PaymentOptionsPtr options) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ std::string error;
+ if (!payments::validatePaymentDetails(details, &error)) {
+ LOG(ERROR) << error;
+ OnError();
+ return;
+ }
+ client_ = std::move(client);
+ details_ = std::move(details);
+}
+
+void PaymentRequest::Show() {
+ delegate_->ShowPaymentRequestDialog(this);
+}
+
+void PaymentRequest::Cancel() {
+ client_->OnError(payments::mojom::PaymentErrorReason::USER_CANCEL);
+}
+
+void PaymentRequest::OnError() {
+ binding_.Close();
+ manager_->DestroyRequest(this);
+}
+
+} // namespace payments
« no previous file with comments | « components/payments/payment_request.h ('k') | components/payments/payment_request_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698