| 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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 void PaymentAppDatabase::DidWritePaymentInstrument( | 531 void PaymentAppDatabase::DidWritePaymentInstrument( |
| 519 WritePaymentInstrumentCallback callback, | 532 WritePaymentInstrumentCallback callback, |
| 520 ServiceWorkerStatusCode status) { | 533 ServiceWorkerStatusCode status) { |
| 521 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 534 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 522 return std::move(callback).Run( | 535 return std::move(callback).Run( |
| 523 status == SERVICE_WORKER_OK | 536 status == SERVICE_WORKER_OK |
| 524 ? PaymentHandlerStatus::SUCCESS | 537 ? PaymentHandlerStatus::SUCCESS |
| 525 : PaymentHandlerStatus::STORAGE_OPERATION_FAILED); | 538 : PaymentHandlerStatus::STORAGE_OPERATION_FAILED); |
| 526 } | 539 } |
| 527 | 540 |
| 541 void PaymentAppDatabase::DidFindRegistrationToClearPaymentInstruments( |
| 542 const GURL& scope, |
| 543 ClearPaymentInstrumentsCallback callback, |
| 544 ServiceWorkerStatusCode status, |
| 545 scoped_refptr<ServiceWorkerRegistration> registration) { |
| 546 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 547 |
| 548 if (status != SERVICE_WORKER_OK) { |
| 549 std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER); |
| 550 return; |
| 551 } |
| 552 |
| 553 KeysOfPaymentInstruments( |
| 554 scope, |
| 555 base::BindOnce(&PaymentAppDatabase::DidGetKeysToClearPaymentInstruments, |
| 556 weak_ptr_factory_.GetWeakPtr(), registration->id(), |
| 557 std::move(callback))); |
| 558 } |
| 559 |
| 560 void PaymentAppDatabase::DidGetKeysToClearPaymentInstruments( |
| 561 int64_t registration_id, |
| 562 ClearPaymentInstrumentsCallback callback, |
| 563 const std::vector<std::string>& keys, |
| 564 PaymentHandlerStatus status) { |
| 565 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 566 |
| 567 if (status != PaymentHandlerStatus::SUCCESS) { |
| 568 std::move(callback).Run(PaymentHandlerStatus::NOT_FOUND); |
| 569 return; |
| 570 } |
| 571 |
| 572 std::vector<std::string> keys_with_prefix; |
| 573 for (const auto& key : keys) { |
| 574 keys_with_prefix.push_back(CreatePaymentInstrumentKey(key)); |
| 575 keys_with_prefix.push_back(CreatePaymentInstrumentKeyInfoKey(key)); |
| 576 } |
| 577 |
| 578 service_worker_context_->ClearRegistrationUserData( |
| 579 registration_id, keys_with_prefix, |
| 580 base::Bind(&PaymentAppDatabase::DidClearPaymentInstruments, |
| 581 weak_ptr_factory_.GetWeakPtr(), |
| 582 base::Passed(std::move(callback)))); |
| 583 } |
| 584 |
| 585 void PaymentAppDatabase::DidClearPaymentInstruments( |
| 586 ClearPaymentInstrumentsCallback callback, |
| 587 ServiceWorkerStatusCode status) { |
| 588 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 589 return std::move(callback).Run(status == SERVICE_WORKER_OK |
| 590 ? PaymentHandlerStatus::SUCCESS |
| 591 : PaymentHandlerStatus::NOT_FOUND); |
| 592 } |
| 593 |
| 528 } // namespace content | 594 } // namespace content |
| OLD | NEW |