Commit 0c23959a authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Commit Bot

[Web Payment] Static methods for creating RespondWithCallback.

Before this patch, the exact constructor for RespondWithCallback that
payment_app_provider_impl.cc used depended only on the type of the
callback object, which made the code harder to understand.

This patch replaces the two constructors with two static methods:
CreateForInvoke() and CreateForEvent().

After this patch, it is clear which code path is taken when reading the
code.

Bug: 1005076
Change-Id: Idc762c79077082088b81d8a564b5acc11e47ae12
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2089616
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarDanyao Wang <danyao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748755}
parent abafaff8
...@@ -122,30 +122,31 @@ class InvokePaymentAppCallbackRepository { ...@@ -122,30 +122,31 @@ class InvokePaymentAppCallbackRepository {
// called. // called.
class RespondWithCallbacks : public PaymentHandlerResponseCallback { class RespondWithCallbacks : public PaymentHandlerResponseCallback {
public: public:
RespondWithCallbacks( static RespondWithCallbacks* CreateForInvoke(
BrowserContext* browser_context, BrowserContext* browser_context,
ServiceWorkerMetrics::EventType event_type, ServiceWorkerMetrics::EventType event_type,
scoped_refptr<ServiceWorkerVersion> service_worker_version, scoped_refptr<ServiceWorkerVersion> service_worker_version,
PaymentAppProvider::InvokePaymentAppCallback callback) PaymentAppProvider::InvokePaymentAppCallback callback) {
: RespondWithCallbacks(browser_context, RespondWithCallbacks* callbacks = new RespondWithCallbacks(
event_type, browser_context, event_type, service_worker_version,
service_worker_version, /*invoke_callback=*/std::move(callback),
/*invoke_callback=*/std::move(callback), PaymentAppProvider::PaymentEventResultCallback());
PaymentAppProvider::PaymentEventResultCallback()) {
InvokePaymentAppCallbackRepository::GetInstance()->SetCallback( InvokePaymentAppCallbackRepository::GetInstance()->SetCallback(
browser_context, this); browser_context, callbacks);
return callbacks;
} }
RespondWithCallbacks( static RespondWithCallbacks* CreateForEvent(
BrowserContext* browser_context, BrowserContext* browser_context,
ServiceWorkerMetrics::EventType event_type, ServiceWorkerMetrics::EventType event_type,
scoped_refptr<ServiceWorkerVersion> service_worker_version, scoped_refptr<ServiceWorkerVersion> service_worker_version,
PaymentAppProvider::PaymentEventResultCallback callback) PaymentAppProvider::PaymentEventResultCallback callback) {
: RespondWithCallbacks(browser_context, RespondWithCallbacks* callbacks = new RespondWithCallbacks(
event_type, browser_context, event_type, service_worker_version,
service_worker_version, PaymentAppProvider::InvokePaymentAppCallback(),
PaymentAppProvider::InvokePaymentAppCallback(), /*event_callback=*/std::move(callback));
/*event_callback=*/std::move(callback)) {} return callbacks;
}
// Disallow copy and assign. // Disallow copy and assign.
RespondWithCallbacks(const RespondWithCallbacks& other) = delete; RespondWithCallbacks(const RespondWithCallbacks& other) = delete;
...@@ -321,10 +322,12 @@ void DispatchAbortPaymentEvent( ...@@ -321,10 +322,12 @@ void DispatchAbortPaymentEvent(
int event_finish_id = active_version->StartRequest( int event_finish_id = active_version->StartRequest(
ServiceWorkerMetrics::EventType::CAN_MAKE_PAYMENT, base::DoNothing()); ServiceWorkerMetrics::EventType::CAN_MAKE_PAYMENT, base::DoNothing());
// This object self-deletes after either success or error callback is invoked. // This object self-deletes after either success or error callback is
RespondWithCallbacks* invocation_callbacks = new RespondWithCallbacks( // invoked.
browser_context, ServiceWorkerMetrics::EventType::ABORT_PAYMENT, RespondWithCallbacks* invocation_callbacks =
active_version, std::move(callback)); RespondWithCallbacks::CreateForEvent(
browser_context, ServiceWorkerMetrics::EventType::ABORT_PAYMENT,
active_version, std::move(callback));
active_version->endpoint()->DispatchAbortPaymentEvent( active_version->endpoint()->DispatchAbortPaymentEvent(
invocation_callbacks->BindNewPipeAndPassRemote(), invocation_callbacks->BindNewPipeAndPassRemote(),
...@@ -350,10 +353,12 @@ void DispatchCanMakePaymentEvent( ...@@ -350,10 +353,12 @@ void DispatchCanMakePaymentEvent(
int event_finish_id = active_version->StartRequest( int event_finish_id = active_version->StartRequest(
ServiceWorkerMetrics::EventType::CAN_MAKE_PAYMENT, base::DoNothing()); ServiceWorkerMetrics::EventType::CAN_MAKE_PAYMENT, base::DoNothing());
// This object self-deletes after either success or error callback is invoked. // This object self-deletes after either success or error callback is
RespondWithCallbacks* invocation_callbacks = new RespondWithCallbacks( // invoked.
browser_context, ServiceWorkerMetrics::EventType::CAN_MAKE_PAYMENT, RespondWithCallbacks* invocation_callbacks =
active_version, std::move(callback)); RespondWithCallbacks::CreateForEvent(
browser_context, ServiceWorkerMetrics::EventType::CAN_MAKE_PAYMENT,
active_version, std::move(callback));
active_version->endpoint()->DispatchCanMakePaymentEvent( active_version->endpoint()->DispatchCanMakePaymentEvent(
std::move(event_data), invocation_callbacks->BindNewPipeAndPassRemote(), std::move(event_data), invocation_callbacks->BindNewPipeAndPassRemote(),
...@@ -383,10 +388,12 @@ void DispatchPaymentRequestEvent( ...@@ -383,10 +388,12 @@ void DispatchPaymentRequestEvent(
int event_finish_id = active_version->StartRequest( int event_finish_id = active_version->StartRequest(
ServiceWorkerMetrics::EventType::PAYMENT_REQUEST, base::DoNothing()); ServiceWorkerMetrics::EventType::PAYMENT_REQUEST, base::DoNothing());
// This object self-deletes after either success or error callback is invoked. // This object self-deletes after either success or error callback is
RespondWithCallbacks* invocation_callbacks = new RespondWithCallbacks( // invoked.
browser_context, ServiceWorkerMetrics::EventType::PAYMENT_REQUEST, RespondWithCallbacks* invocation_callbacks =
active_version, std::move(callback)); RespondWithCallbacks::CreateForInvoke(
browser_context, ServiceWorkerMetrics::EventType::PAYMENT_REQUEST,
active_version, std::move(callback));
active_version->endpoint()->DispatchPaymentRequestEvent( active_version->endpoint()->DispatchPaymentRequestEvent(
std::move(event_data), invocation_callbacks->BindNewPipeAndPassRemote(), std::move(event_data), invocation_callbacks->BindNewPipeAndPassRemote(),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment