[Web Payments] User weak ptr in Payment Request's error callback

Bug: 742329
Change-Id: I73b2043c63f814d0394ed745eb6b1e55814db339
Reviewed-on: https://chromium-review.googlesource.com/570982
Commit-Queue: Anthony Vallee-Dubois <[email protected]>
Reviewed-by: Mathieu Perreault <[email protected]>
Cr-Commit-Position: refs/heads/master@{#487077}
diff --git a/components/payments/content/payment_request.cc b/components/payments/content/payment_request.cc
index cf0c0718..e9198fba 100644
--- a/components/payments/content/payment_request.cc
+++ b/components/payments/content/payment_request.cc
@@ -36,14 +36,15 @@
       observer_for_testing_(observer_for_testing),
       journey_logger_(delegate_->IsIncognito(),
                       web_contents_->GetLastCommittedURL(),
-                      delegate_->GetUkmRecorder()) {
+                      delegate_->GetUkmRecorder()),
+      weak_ptr_factory_(this) {
   // OnConnectionTerminated will be called when the Mojo pipe is closed. This
   // will happen as a result of many renderer-side events (both successful and
   // erroneous in nature).
   // TODO(crbug.com/683636): Investigate using
   // set_connection_error_with_reason_handler with Binding::CloseWithReason.
   binding_.set_connection_error_handler(base::Bind(
-      &PaymentRequest::OnConnectionTerminated, base::Unretained(this)));
+      &PaymentRequest::OnConnectionTerminated, weak_ptr_factory_.GetWeakPtr()));
 }
 
 PaymentRequest::~PaymentRequest() {}