OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/payments/payment_app_provider_impl.h" | 5 #include "content/browser/payments/payment_app_provider_impl.h" |
6 | 6 |
7 #include "content/browser/payments/payment_app_context_impl.h" | 7 #include "content/browser/payments/payment_app_context_impl.h" |
8 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 8 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
9 #include "content/browser/service_worker/service_worker_metrics.h" | 9 #include "content/browser/service_worker/service_worker_metrics.h" |
10 #include "content/browser/service_worker/service_worker_version.h" | 10 #include "content/browser/service_worker/service_worker_version.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 payment_app_context->payment_app_database()->ReadAllPaymentApps( | 72 payment_app_context->payment_app_database()->ReadAllPaymentApps( |
73 base::BindOnce(&DidGetAllPaymentAppsOnIO, std::move(callback))); | 73 base::BindOnce(&DidGetAllPaymentAppsOnIO, std::move(callback))); |
74 } | 74 } |
75 | 75 |
76 void DispatchPaymentRequestEventError( | 76 void DispatchPaymentRequestEventError( |
77 ServiceWorkerStatusCode service_worker_status) { | 77 ServiceWorkerStatusCode service_worker_status) { |
78 NOTIMPLEMENTED(); | 78 NOTIMPLEMENTED(); |
79 } | 79 } |
80 | 80 |
81 void DispatchPaymentRequestEvent( | 81 void DispatchPaymentRequestEvent( |
82 payments::mojom::PaymentAppRequestPtr app_request, | 82 payments::mojom::PaymentRequestEventDataPtr event_data, |
83 const PaymentAppProvider::InvokePaymentAppCallback& callback, | 83 const PaymentAppProvider::InvokePaymentAppCallback& callback, |
84 scoped_refptr<ServiceWorkerVersion> active_version) { | 84 scoped_refptr<ServiceWorkerVersion> active_version) { |
85 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 85 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
86 DCHECK(active_version); | 86 DCHECK(active_version); |
87 | 87 |
88 int payment_request_id = active_version->StartRequest( | 88 int payment_request_id = active_version->StartRequest( |
89 ServiceWorkerMetrics::EventType::PAYMENT_REQUEST, | 89 ServiceWorkerMetrics::EventType::PAYMENT_REQUEST, |
90 base::Bind(&DispatchPaymentRequestEventError)); | 90 base::Bind(&DispatchPaymentRequestEventError)); |
91 int event_finish_id = active_version->StartRequest( | 91 int event_finish_id = active_version->StartRequest( |
92 ServiceWorkerMetrics::EventType::PAYMENT_REQUEST, | 92 ServiceWorkerMetrics::EventType::PAYMENT_REQUEST, |
93 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 93 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
94 | 94 |
95 payments::mojom::PaymentAppResponseCallbackPtr response_callback_ptr = | 95 payments::mojom::PaymentAppResponseCallbackPtr response_callback_ptr = |
96 ResponseCallback::Create(payment_request_id, active_version, callback); | 96 ResponseCallback::Create(payment_request_id, active_version, callback); |
97 DCHECK(response_callback_ptr); | 97 DCHECK(response_callback_ptr); |
98 active_version->event_dispatcher()->DispatchPaymentRequestEvent( | 98 active_version->event_dispatcher()->DispatchPaymentRequestEvent( |
99 payment_request_id, std::move(app_request), | 99 payment_request_id, std::move(event_data), |
100 std::move(response_callback_ptr), | 100 std::move(response_callback_ptr), |
101 active_version->CreateSimpleEventCallback(event_finish_id)); | 101 active_version->CreateSimpleEventCallback(event_finish_id)); |
102 } | 102 } |
103 | 103 |
104 void DidFindRegistrationOnIO( | 104 void DidFindRegistrationOnIO( |
105 payments::mojom::PaymentAppRequestPtr app_request, | 105 payments::mojom::PaymentRequestEventDataPtr event_data, |
106 const PaymentAppProvider::InvokePaymentAppCallback& callback, | 106 const PaymentAppProvider::InvokePaymentAppCallback& callback, |
107 ServiceWorkerStatusCode service_worker_status, | 107 ServiceWorkerStatusCode service_worker_status, |
108 scoped_refptr<ServiceWorkerRegistration> service_worker_registration) { | 108 scoped_refptr<ServiceWorkerRegistration> service_worker_registration) { |
109 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 109 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
110 | 110 |
111 if (service_worker_status != SERVICE_WORKER_OK) | 111 if (service_worker_status != SERVICE_WORKER_OK) |
112 return; | 112 return; |
113 | 113 |
114 ServiceWorkerVersion* active_version = | 114 ServiceWorkerVersion* active_version = |
115 service_worker_registration->active_version(); | 115 service_worker_registration->active_version(); |
116 DCHECK(active_version); | 116 DCHECK(active_version); |
117 active_version->RunAfterStartWorker( | 117 active_version->RunAfterStartWorker( |
118 ServiceWorkerMetrics::EventType::PAYMENT_REQUEST, | 118 ServiceWorkerMetrics::EventType::PAYMENT_REQUEST, |
119 base::Bind(&DispatchPaymentRequestEvent, | 119 base::Bind(&DispatchPaymentRequestEvent, |
120 base::Passed(std::move(app_request)), callback, | 120 base::Passed(std::move(event_data)), callback, |
121 make_scoped_refptr(active_version)), | 121 make_scoped_refptr(active_version)), |
122 base::Bind(&DispatchPaymentRequestEventError)); | 122 base::Bind(&DispatchPaymentRequestEventError)); |
123 } | 123 } |
124 | 124 |
125 void FindRegistrationOnIO( | 125 void FindRegistrationOnIO( |
126 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, | 126 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, |
127 int64_t registration_id, | 127 int64_t registration_id, |
128 payments::mojom::PaymentAppRequestPtr app_request, | 128 payments::mojom::PaymentRequestEventDataPtr event_data, |
129 const PaymentAppProvider::InvokePaymentAppCallback& callback) { | 129 const PaymentAppProvider::InvokePaymentAppCallback& callback) { |
130 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 130 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
131 | 131 |
132 service_worker_context->FindReadyRegistrationForIdOnly( | 132 service_worker_context->FindReadyRegistrationForIdOnly( |
133 registration_id, | 133 registration_id, |
134 base::Bind(&DidFindRegistrationOnIO, base::Passed(std::move(app_request)), | 134 base::Bind(&DidFindRegistrationOnIO, base::Passed(std::move(event_data)), |
135 callback)); | 135 callback)); |
136 } | 136 } |
137 | 137 |
138 } // namespace | 138 } // namespace |
139 | 139 |
140 // static | 140 // static |
141 PaymentAppProvider* PaymentAppProvider::GetInstance() { | 141 PaymentAppProvider* PaymentAppProvider::GetInstance() { |
142 return PaymentAppProviderImpl::GetInstance(); | 142 return PaymentAppProviderImpl::GetInstance(); |
143 } | 143 } |
144 | 144 |
(...skipping 15 matching lines...) Expand all Loading... |
160 | 160 |
161 BrowserThread::PostTask( | 161 BrowserThread::PostTask( |
162 BrowserThread::IO, FROM_HERE, | 162 BrowserThread::IO, FROM_HERE, |
163 base::BindOnce(&GetAllPaymentAppsOnIO, payment_app_context, | 163 base::BindOnce(&GetAllPaymentAppsOnIO, payment_app_context, |
164 std::move(callback))); | 164 std::move(callback))); |
165 } | 165 } |
166 | 166 |
167 void PaymentAppProviderImpl::InvokePaymentApp( | 167 void PaymentAppProviderImpl::InvokePaymentApp( |
168 BrowserContext* browser_context, | 168 BrowserContext* browser_context, |
169 int64_t registration_id, | 169 int64_t registration_id, |
170 payments::mojom::PaymentAppRequestPtr app_request, | 170 payments::mojom::PaymentRequestEventDataPtr event_data, |
171 const InvokePaymentAppCallback& callback) { | 171 const InvokePaymentAppCallback& callback) { |
172 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 172 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
173 | 173 |
174 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( | 174 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
175 BrowserContext::GetDefaultStoragePartition(browser_context)); | 175 BrowserContext::GetDefaultStoragePartition(browser_context)); |
176 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context = | 176 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context = |
177 partition->GetServiceWorkerContext(); | 177 partition->GetServiceWorkerContext(); |
178 | 178 |
179 BrowserThread::PostTask( | 179 BrowserThread::PostTask( |
180 BrowserThread::IO, FROM_HERE, | 180 BrowserThread::IO, FROM_HERE, |
181 base::Bind(&FindRegistrationOnIO, std::move(service_worker_context), | 181 base::Bind(&FindRegistrationOnIO, std::move(service_worker_context), |
182 registration_id, base::Passed(std::move(app_request)), | 182 registration_id, base::Passed(std::move(event_data)), |
183 callback)); | 183 callback)); |
184 } | 184 } |
185 | 185 |
186 PaymentAppProviderImpl::PaymentAppProviderImpl() {} | 186 PaymentAppProviderImpl::PaymentAppProviderImpl() {} |
187 | 187 |
188 PaymentAppProviderImpl::~PaymentAppProviderImpl() {} | 188 PaymentAppProviderImpl::~PaymentAppProviderImpl() {} |
189 | 189 |
190 } // namespace content | 190 } // namespace content |
OLD | NEW |