OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_database.h" | 5 #include "content/browser/payments/payment_app_database.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 196 |
197 service_worker_context_->FindReadyRegistrationForPattern( | 197 service_worker_context_->FindReadyRegistrationForPattern( |
198 scope, | 198 scope, |
199 base::Bind( | 199 base::Bind( |
200 &PaymentAppDatabase::DidFindRegistrationToWritePaymentInstrument, | 200 &PaymentAppDatabase::DidFindRegistrationToWritePaymentInstrument, |
201 weak_ptr_factory_.GetWeakPtr(), instrument_key, | 201 weak_ptr_factory_.GetWeakPtr(), instrument_key, |
202 base::Passed(std::move(instrument)), | 202 base::Passed(std::move(instrument)), |
203 base::Passed(std::move(callback)))); | 203 base::Passed(std::move(callback)))); |
204 } | 204 } |
205 | 205 |
| 206 void PaymentAppDatabase::ClearPaymentInstruments( |
| 207 const GURL& scope, |
| 208 ClearPaymentInstrumentsCallback callback) { |
| 209 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 210 |
| 211 service_worker_context_->FindReadyRegistrationForPattern( |
| 212 scope, |
| 213 base::Bind( |
| 214 &PaymentAppDatabase::DidFindRegistrationToClearPaymentInstruments, |
| 215 weak_ptr_factory_.GetWeakPtr(), scope, |
| 216 base::Passed(std::move(callback)))); |
| 217 } |
| 218 |
206 void PaymentAppDatabase::DidFindRegistrationToWriteManifest( | 219 void PaymentAppDatabase::DidFindRegistrationToWriteManifest( |
207 payments::mojom::PaymentAppManifestPtr manifest, | 220 payments::mojom::PaymentAppManifestPtr manifest, |
208 const WriteManifestCallback& callback, | 221 const WriteManifestCallback& callback, |
209 ServiceWorkerStatusCode status, | 222 ServiceWorkerStatusCode status, |
210 scoped_refptr<ServiceWorkerRegistration> registration) { | 223 scoped_refptr<ServiceWorkerRegistration> registration) { |
211 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 224 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
212 if (status != SERVICE_WORKER_OK) { | 225 if (status != SERVICE_WORKER_OK) { |
213 callback.Run(payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER); | 226 callback.Run(payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER); |
214 return; | 227 return; |
215 } | 228 } |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 void PaymentAppDatabase::DidWritePaymentInstrument( | 529 void PaymentAppDatabase::DidWritePaymentInstrument( |
517 WritePaymentInstrumentCallback callback, | 530 WritePaymentInstrumentCallback callback, |
518 ServiceWorkerStatusCode status) { | 531 ServiceWorkerStatusCode status) { |
519 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 532 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
520 return std::move(callback).Run( | 533 return std::move(callback).Run( |
521 status == SERVICE_WORKER_OK | 534 status == SERVICE_WORKER_OK |
522 ? PaymentHandlerStatus::SUCCESS | 535 ? PaymentHandlerStatus::SUCCESS |
523 : PaymentHandlerStatus::STORAGE_OPERATION_FAILED); | 536 : PaymentHandlerStatus::STORAGE_OPERATION_FAILED); |
524 } | 537 } |
525 | 538 |
| 539 void PaymentAppDatabase::DidFindRegistrationToClearPaymentInstruments( |
| 540 const GURL& scope, |
| 541 ClearPaymentInstrumentsCallback callback, |
| 542 ServiceWorkerStatusCode status, |
| 543 scoped_refptr<ServiceWorkerRegistration> registration) { |
| 544 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 545 |
| 546 if (status != SERVICE_WORKER_OK) { |
| 547 std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER); |
| 548 return; |
| 549 } |
| 550 |
| 551 KeysOfPaymentInstruments( |
| 552 scope, |
| 553 base::BindOnce(&PaymentAppDatabase::DidGetKeysToClearPaymentInstruments, |
| 554 weak_ptr_factory_.GetWeakPtr(), registration->id(), |
| 555 std::move(callback))); |
| 556 } |
| 557 |
| 558 void PaymentAppDatabase::DidGetKeysToClearPaymentInstruments( |
| 559 int64_t registration_id, |
| 560 ClearPaymentInstrumentsCallback callback, |
| 561 const std::vector<std::string>& keys, |
| 562 PaymentHandlerStatus status) { |
| 563 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 564 |
| 565 if (status != PaymentHandlerStatus::SUCCESS) { |
| 566 std::move(callback).Run(PaymentHandlerStatus::NOT_FOUND); |
| 567 return; |
| 568 } |
| 569 |
| 570 std::vector<std::string> keys_with_prefix; |
| 571 for (const auto& key : keys) { |
| 572 keys_with_prefix.push_back(CreatePaymentInstrumentKey(key)); |
| 573 keys_with_prefix.push_back(CreatePaymentInstrumentKeyInfoKey(key)); |
| 574 } |
| 575 |
| 576 service_worker_context_->ClearRegistrationUserData( |
| 577 registration_id, keys_with_prefix, |
| 578 base::Bind(&PaymentAppDatabase::DidClearPaymentInstruments, |
| 579 weak_ptr_factory_.GetWeakPtr(), |
| 580 base::Passed(std::move(callback)))); |
| 581 } |
| 582 |
| 583 void PaymentAppDatabase::DidClearPaymentInstruments( |
| 584 ClearPaymentInstrumentsCallback callback, |
| 585 ServiceWorkerStatusCode status) { |
| 586 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 587 return std::move(callback).Run(status == SERVICE_WORKER_OK |
| 588 ? PaymentHandlerStatus::SUCCESS |
| 589 : PaymentHandlerStatus::NOT_FOUND); |
| 590 } |
| 591 |
526 } // namespace content | 592 } // namespace content |
OLD | NEW |