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

Unified Diff: components/payments/payment_request.cc

Issue 2649683002: [Payments] Improve the closing of the PR dialog. (Closed)
Patch Set: Initial 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.cc
diff --git a/components/payments/payment_request.cc b/components/payments/payment_request.cc
index 282b3fa38afad3d8ef83f6db57f9f05c532ca0ad..2daba0185e20c5d38c28a27ba7cf89e9f476f8fc 100644
--- a/components/payments/payment_request.cc
+++ b/components/payments/payment_request.cc
@@ -22,9 +22,15 @@ PaymentRequest::PaymentRequest(
: 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)));
+ binding_(this, std::move(request)),
+ user_cancelled_dialog_(false) {
+ // 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::~PaymentRequest() {}
@@ -38,7 +44,7 @@ void PaymentRequest::Init(
std::string error;
if (!payments::validatePaymentDetails(details, &error)) {
LOG(ERROR) << error;
- OnError();
+ OnConnectionTerminated();
client_.reset();
return;
}
@@ -48,18 +54,37 @@ void PaymentRequest::Init(
void PaymentRequest::Show() {
if (!client_.is_bound() || !binding_.is_bound()) {
- OnError();
+ LOG(ERROR) << "Attempted Show(), but binding(s) missing.";
+ OnConnectionTerminated();
return;
}
- delegate_->ShowPaymentRequestDialog(this);
+ delegate_->ShowDialog(this);
}
-void PaymentRequest::Cancel() {
+void PaymentRequest::Abort() {
+ // The API user has decided to abort. We return a successful abort message to
+ // the renderer, which closes the Mojo message pipe, which triggers
+ // PaymentRequest::OnConnectionTerminated, which destroys this object.
+ client_->OnAbort(true /* aborted_successfully */);
+}
+
+void PaymentRequest::UserCancelled() {
+ // This sends an error to the renderer, which closes the Mojo message pipe,
+ // which triggers PaymentRequest::OnConnectionTerminated, which destroys this
+ // object.
+ user_cancelled_dialog_ = true;
client_->OnError(payments::mojom::PaymentErrorReason::USER_CANCEL);
}
-void PaymentRequest::OnError() {
+void PaymentRequest::OnConnectionTerminated() {
please use gerrit instead 2017/01/23 15:02:08 Also need to close "client_" connection everywhere
Mathieu 2017/01/23 20:58:36 Done.
+ // We are here because of a browser-side error, or likely as a result of the
+ // connection_error_handler on |binding_|, which can mean that the renderer
+ // has decided to close the pipe for various reasons (see all uses of
+ // PaymentRequest::clearResolversAndCloseMojoConnection() in Blink). We close
+ // the binding and the dialog, and ask to be deleted.
binding_.Close();
please use gerrit instead 2017/01/23 15:02:08 I have a hunch that "binding_.is_bound()" is equia
Mathieu 2017/01/23 20:58:36 I rearranged things so that when UserCancelled is
+ if (!user_cancelled_dialog_)
+ delegate_->CloseDialog();
manager_->DestroyRequest(this);
}
@@ -71,7 +96,6 @@ CurrencyFormatter* PaymentRequest::GetOrCreateCurrencyFormatter(
currency_formatter_.reset(
new CurrencyFormatter(currency_code, currency_system, locale_name));
}
-
return currency_formatter_.get();
}

Powered by Google App Engine
This is Rietveld 408576698