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

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

Issue 2856973002: PaymentHandler: Implement PaymentInstruments.clear(). (Closed)
Patch Set: PaymentHandler: Implement PaymentInstruments.clear(). Created 3 years, 7 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
« no previous file with comments | « content/browser/payments/payment_app_database.h ('k') | content/browser/payments/payment_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/payments/payment_app_database.cc
diff --git a/content/browser/payments/payment_app_database.cc b/content/browser/payments/payment_app_database.cc
index 4a4644fc06900206376953d2a81f50a5d29f04b1..00e79cf9db20157f91dee5b7f7ceb9d13f267a42 100644
--- a/content/browser/payments/payment_app_database.cc
+++ b/content/browser/payments/payment_app_database.cc
@@ -203,6 +203,19 @@ void PaymentAppDatabase::WritePaymentInstrument(
base::Passed(std::move(callback))));
}
+void PaymentAppDatabase::ClearPaymentInstruments(
+ const GURL& scope,
+ ClearPaymentInstrumentsCallback callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ service_worker_context_->FindReadyRegistrationForPattern(
+ scope,
+ base::Bind(
+ &PaymentAppDatabase::DidFindRegistrationToClearPaymentInstruments,
+ weak_ptr_factory_.GetWeakPtr(), scope,
+ base::Passed(std::move(callback))));
+}
+
void PaymentAppDatabase::DidFindRegistrationToWriteManifest(
payments::mojom::PaymentAppManifestPtr manifest,
const WriteManifestCallback& callback,
@@ -525,4 +538,57 @@ void PaymentAppDatabase::DidWritePaymentInstrument(
: PaymentHandlerStatus::STORAGE_OPERATION_FAILED);
}
+void PaymentAppDatabase::DidFindRegistrationToClearPaymentInstruments(
+ const GURL& scope,
+ ClearPaymentInstrumentsCallback callback,
+ ServiceWorkerStatusCode status,
+ scoped_refptr<ServiceWorkerRegistration> registration) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ if (status != SERVICE_WORKER_OK) {
+ std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER);
+ return;
+ }
+
+ KeysOfPaymentInstruments(
+ scope,
+ base::BindOnce(&PaymentAppDatabase::DidGetKeysToClearPaymentInstruments,
+ weak_ptr_factory_.GetWeakPtr(), registration->id(),
+ std::move(callback)));
+}
+
+void PaymentAppDatabase::DidGetKeysToClearPaymentInstruments(
+ int64_t registration_id,
+ ClearPaymentInstrumentsCallback callback,
+ const std::vector<std::string>& keys,
+ PaymentHandlerStatus status) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ if (status != PaymentHandlerStatus::SUCCESS) {
+ std::move(callback).Run(PaymentHandlerStatus::NOT_FOUND);
+ return;
+ }
+
+ std::vector<std::string> keys_with_prefix;
+ for (const auto& key : keys) {
+ keys_with_prefix.push_back(CreatePaymentInstrumentKey(key));
+ keys_with_prefix.push_back(CreatePaymentInstrumentKeyInfoKey(key));
+ }
+
+ service_worker_context_->ClearRegistrationUserData(
+ registration_id, keys_with_prefix,
+ base::Bind(&PaymentAppDatabase::DidClearPaymentInstruments,
+ weak_ptr_factory_.GetWeakPtr(),
+ base::Passed(std::move(callback))));
+}
+
+void PaymentAppDatabase::DidClearPaymentInstruments(
+ ClearPaymentInstrumentsCallback callback,
+ ServiceWorkerStatusCode status) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ return std::move(callback).Run(status == SERVICE_WORKER_OK
+ ? PaymentHandlerStatus::SUCCESS
+ : PaymentHandlerStatus::NOT_FOUND);
+}
+
} // namespace content
« no previous file with comments | « content/browser/payments/payment_app_database.h ('k') | content/browser/payments/payment_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698