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

Unified Diff: content/browser/payments/payment_app_provider_impl.cc

Issue 2718013004: PaymentApp: Implement respondWith() in PaymentRequestEvent. (content side) (Closed)
Patch Set: rebase Created 3 years, 9 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: content/browser/payments/payment_app_provider_impl.cc
diff --git a/content/browser/payments/payment_app_provider_impl.cc b/content/browser/payments/payment_app_provider_impl.cc
index e2cd3f033f389c37ee25b0ce42d81a45282c40cb..af8492a371b9bb4ddd42cd801e1d74c2552d477c 100644
--- a/content/browser/payments/payment_app_provider_impl.cc
+++ b/content/browser/payments/payment_app_provider_impl.cc
@@ -10,12 +10,52 @@
#include "content/browser/service_worker/service_worker_version.h"
#include "content/browser/storage_partition_impl.h"
#include "content/common/service_worker/service_worker_status_code.h"
+#include "content/common/service_worker/service_worker_utils.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
+#include "mojo/common/time.mojom.h"
namespace content {
namespace {
+class ResponseCallback : public payments::mojom::PaymentAppResponseCallback {
+ public:
+ static payments::mojom::PaymentAppResponseCallbackPtr Create(
+ int payment_request_id,
+ scoped_refptr<ServiceWorkerVersion> service_worker_version,
+ const PaymentAppProvider::InvokePaymentAppCallback callback) {
+ ResponseCallback* response_callback = new ResponseCallback(
+ payment_request_id, std::move(service_worker_version), callback);
+ return response_callback->binding_.CreateInterfacePtrAndBind();
+ }
+ ~ResponseCallback() override {}
+
+ void OnPaymentAppResponse(payments::mojom::PaymentAppResponsePtr response,
+ base::Time dispatch_event_time) override {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ service_worker_version_->FinishRequest(payment_request_id_, false,
+ std::move(dispatch_event_time));
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(callback_, base::Passed(std::move(response))));
+ delete this;
+ }
+
+ private:
+ ResponseCallback(int payment_request_id,
+ scoped_refptr<ServiceWorkerVersion> service_worker_version,
+ const PaymentAppProvider::InvokePaymentAppCallback callback)
+ : payment_request_id_(payment_request_id),
+ service_worker_version_(service_worker_version),
+ callback_(callback),
+ binding_(this) {}
+
+ int payment_request_id_;
+ scoped_refptr<ServiceWorkerVersion> service_worker_version_;
+ const PaymentAppProvider::InvokePaymentAppCallback callback_;
+ mojo::Binding<payments::mojom::PaymentAppResponseCallback> binding_;
+};
+
void DidGetAllManifestsOnIO(
const PaymentAppProvider::GetAllManifestsCallback& callback,
PaymentAppProvider::Manifests manifests) {
@@ -33,16 +73,6 @@ void GetAllManifestsOnIO(
base::Bind(&DidGetAllManifestsOnIO, callback));
}
-void DidDispatchPaymentRequestEvent(
- scoped_refptr<ServiceWorkerVersion> active_version,
- int request_id,
- ServiceWorkerStatusCode service_worker_status,
- base::Time dispatch_event_time) {
- active_version->FinishRequest(request_id,
- service_worker_status == SERVICE_WORKER_OK,
- dispatch_event_time);
-}
-
void DispatchPaymentRequestEventError(
ServiceWorkerStatusCode service_worker_status) {
NOTIMPLEMENTED();
@@ -50,21 +80,30 @@ void DispatchPaymentRequestEventError(
void DispatchPaymentRequestEvent(
payments::mojom::PaymentAppRequestPtr app_request,
+ const PaymentAppProvider::InvokePaymentAppCallback& callback,
scoped_refptr<ServiceWorkerVersion> active_version) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(active_version);
- int request_id = active_version->StartRequest(
+ int payment_request_id = active_version->StartRequest(
ServiceWorkerMetrics::EventType::PAYMENT_REQUEST,
base::Bind(&DispatchPaymentRequestEventError));
+ int event_finish_id = active_version->StartRequest(
+ ServiceWorkerMetrics::EventType::PAYMENT_REQUEST,
+ base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
+ payments::mojom::PaymentAppResponseCallbackPtr response_callback_ptr =
+ ResponseCallback::Create(payment_request_id, active_version, callback);
+ DCHECK(response_callback_ptr);
active_version->event_dispatcher()->DispatchPaymentRequestEvent(
- std::move(app_request),
- base::Bind(&DidDispatchPaymentRequestEvent, active_version, request_id));
+ payment_request_id, std::move(app_request),
+ std::move(response_callback_ptr),
+ active_version->CreateSimpleEventCallback(event_finish_id));
}
void DidFindRegistrationOnIO(
payments::mojom::PaymentAppRequestPtr app_request,
+ const PaymentAppProvider::InvokePaymentAppCallback& callback,
ServiceWorkerStatusCode service_worker_status,
scoped_refptr<ServiceWorkerRegistration> service_worker_registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -78,7 +117,7 @@ void DidFindRegistrationOnIO(
active_version->RunAfterStartWorker(
ServiceWorkerMetrics::EventType::PAYMENT_REQUEST,
base::Bind(&DispatchPaymentRequestEvent,
- base::Passed(std::move(app_request)),
+ base::Passed(std::move(app_request)), callback,
make_scoped_refptr(active_version)),
base::Bind(&DispatchPaymentRequestEventError));
}
@@ -86,12 +125,14 @@ void DidFindRegistrationOnIO(
void FindRegistrationOnIO(
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
int64_t registration_id,
- payments::mojom::PaymentAppRequestPtr app_request) {
+ payments::mojom::PaymentAppRequestPtr app_request,
+ const PaymentAppProvider::InvokePaymentAppCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
service_worker_context->FindReadyRegistrationForIdOnly(
- registration_id, base::Bind(&DidFindRegistrationOnIO,
- base::Passed(std::move(app_request))));
+ registration_id,
+ base::Bind(&DidFindRegistrationOnIO, base::Passed(std::move(app_request)),
+ callback));
}
} // namespace
@@ -125,7 +166,8 @@ void PaymentAppProviderImpl::GetAllManifests(
void PaymentAppProviderImpl::InvokePaymentApp(
BrowserContext* browser_context,
int64_t registration_id,
- payments::mojom::PaymentAppRequestPtr app_request) {
+ payments::mojom::PaymentAppRequestPtr app_request,
+ const InvokePaymentAppCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
@@ -136,7 +178,8 @@ void PaymentAppProviderImpl::InvokePaymentApp(
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&FindRegistrationOnIO, std::move(service_worker_context),
- registration_id, base::Passed(std::move(app_request))));
+ registration_id, base::Passed(std::move(app_request)),
+ callback));
}
PaymentAppProviderImpl::PaymentAppProviderImpl() {}
« no previous file with comments | « content/browser/payments/payment_app_provider_impl.h ('k') | content/browser/payments/payment_app_provider_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698