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

Unified Diff: components/payments/payment_request_impl.cc

Issue 2611253004: [Payment Request] Change the lifetime management of PaymentRequestImpl (Closed)
Patch Set: added a browser test 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_impl.cc
diff --git a/components/payments/payment_request_impl.cc b/components/payments/payment_request_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..52357c119290d4f4fd2a38424224948cf9dcc448
--- /dev/null
+++ b/components/payments/payment_request_impl.cc
@@ -0,0 +1,63 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
please use gerrit instead 2017/01/06 21:49:09 2017
Mathieu 2017/01/07 05:03:07 Well it was moved so I'll keep 2016.
+// 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_impl.h"
+
+#include <map>
+
+#include "base/lazy_instance.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 {
+
+PaymentRequestImpl::PaymentRequestImpl(
+ 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(&PaymentRequestImpl::OnError, base::Unretained(this)));
+}
+
+PaymentRequestImpl::~PaymentRequestImpl() {}
+
+void PaymentRequestImpl::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 PaymentRequestImpl::Show() {
+ delegate_->ShowPaymentRequestDialog(this);
+}
+
+void PaymentRequestImpl::Cancel() {
+ client_->OnError(payments::mojom::PaymentErrorReason::USER_CANCEL);
+}
+
+void PaymentRequestImpl::OnError() {
+ binding_.Close();
+ // Kill ourselves.
please use gerrit instead 2017/01/06 21:49:09 DestroyRequest(this) is self-explanatory, IMHO.
Mathieu 2017/01/07 05:03:07 Done.
+ manager_->DestroyRequest(this);
+}
+
+} // namespace payments

Powered by Google App Engine
This is Rietveld 408576698