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

Side by Side Diff: content/browser/payments/payment_app_database.cc

Issue 2844463002: PaymentHandler: Implement PaymentInstruments.delete(). (Closed)
Patch Set: Created 3 years, 8 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 unified diff | Download patch
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/optional.h" 10 #include "base/optional.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 void PaymentAppDatabase::ReadAllManifests( 100 void PaymentAppDatabase::ReadAllManifests(
101 const ReadAllManifestsCallback& callback) { 101 const ReadAllManifestsCallback& callback) {
102 DCHECK_CURRENTLY_ON(BrowserThread::IO); 102 DCHECK_CURRENTLY_ON(BrowserThread::IO);
103 103
104 service_worker_context_->GetUserDataForAllRegistrations( 104 service_worker_context_->GetUserDataForAllRegistrations(
105 kPaymentAppManifestDataKey, 105 kPaymentAppManifestDataKey,
106 base::Bind(&PaymentAppDatabase::DidReadAllManifests, 106 base::Bind(&PaymentAppDatabase::DidReadAllManifests,
107 weak_ptr_factory_.GetWeakPtr(), callback)); 107 weak_ptr_factory_.GetWeakPtr(), callback));
108 } 108 }
109 109
110 void PaymentAppDatabase::DeletePaymentInstrument(
111 const GURL& scope,
112 const std::string& instrumentKey,
113 DeletePaymentInstrumentCallback callback) {
114 DCHECK_CURRENTLY_ON(BrowserThread::IO);
115
116 service_worker_context_->FindReadyRegistrationForPattern(
117 scope,
118 base::Bind(
119 &PaymentAppDatabase::DidFindRegistrationToDeletePaymentInstrument,
120 weak_ptr_factory_.GetWeakPtr(), instrumentKey,
121 base::Passed(std::move(callback))));
please use gerrit instead 2017/04/25 15:21:40 Is base::Passed() necessary? I believe std::move()
zino 2017/04/25 21:48:51 The FindReadyRegistrationForPattern requires legac
122 }
123
110 void PaymentAppDatabase::ReadPaymentInstrument( 124 void PaymentAppDatabase::ReadPaymentInstrument(
111 const GURL& scope, 125 const GURL& scope,
112 const std::string& instrumentKey, 126 const std::string& instrumentKey,
113 ReadPaymentInstrumentCallback callback) { 127 ReadPaymentInstrumentCallback callback) {
114 DCHECK_CURRENTLY_ON(BrowserThread::IO); 128 DCHECK_CURRENTLY_ON(BrowserThread::IO);
115 129
116 service_worker_context_->FindReadyRegistrationForPattern( 130 service_worker_context_->FindReadyRegistrationForPattern(
117 scope, 131 scope,
118 base::Bind( 132 base::Bind(
119 &PaymentAppDatabase::DidFindRegistrationToReadPaymentInstrument, 133 &PaymentAppDatabase::DidFindRegistrationToReadPaymentInstrument,
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 if (!manifest) 256 if (!manifest)
243 continue; 257 continue;
244 258
245 manifests.push_back( 259 manifests.push_back(
246 ManifestWithID(item_of_raw_data.first, std::move(manifest))); 260 ManifestWithID(item_of_raw_data.first, std::move(manifest)));
247 } 261 }
248 262
249 callback.Run(std::move(manifests)); 263 callback.Run(std::move(manifests));
250 } 264 }
251 265
266 void PaymentAppDatabase::DidFindRegistrationToDeletePaymentInstrument(
267 const std::string& instrument_key,
268 DeletePaymentInstrumentCallback callback,
269 ServiceWorkerStatusCode status,
270 scoped_refptr<ServiceWorkerRegistration> registration) {
271 DCHECK_CURRENTLY_ON(BrowserThread::IO);
272 if (status != SERVICE_WORKER_OK) {
273 std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER);
274 return;
275 }
276
277 service_worker_context_->GetRegistrationUserData(
278 registration->id(), {instrument_key},
279 base::Bind(&PaymentAppDatabase::DidFindPaymentInstrument,
280 weak_ptr_factory_.GetWeakPtr(), registration->id(),
281 instrument_key, base::Passed(std::move(callback))));
please use gerrit instead 2017/04/25 15:21:40 Same comment about base::Passed().
zino 2017/04/25 21:48:51 I already left a comment in above your comment.
282 }
283
284 void PaymentAppDatabase::DidFindPaymentInstrument(
285 int64_t registration_id,
286 const std::string& instrument_key,
287 DeletePaymentInstrumentCallback callback,
288 const std::vector<std::string>& data,
289 ServiceWorkerStatusCode status) {
290 DCHECK_CURRENTLY_ON(BrowserThread::IO);
291 if (status != SERVICE_WORKER_OK || data.size() != 1) {
292 std::move(callback).Run(PaymentHandlerStatus::NOT_FOUND);
293 return;
294 }
295
296 service_worker_context_->ClearRegistrationUserData(
297 registration_id, {instrument_key},
298 base::Bind(&PaymentAppDatabase::DidDeletePaymentInstrument,
299 weak_ptr_factory_.GetWeakPtr(),
300 base::Passed(std::move(callback))));
301 }
302
303 void PaymentAppDatabase::DidDeletePaymentInstrument(
304 DeletePaymentInstrumentCallback callback,
305 ServiceWorkerStatusCode status) {
306 DCHECK_CURRENTLY_ON(BrowserThread::IO);
307 return std::move(callback).Run(status == SERVICE_WORKER_OK
308 ? PaymentHandlerStatus::SUCCESS
309 : PaymentHandlerStatus::NOT_FOUND);
310 }
311
252 void PaymentAppDatabase::DidFindRegistrationToReadPaymentInstrument( 312 void PaymentAppDatabase::DidFindRegistrationToReadPaymentInstrument(
253 const std::string& instrumentKey, 313 const std::string& instrumentKey,
254 ReadPaymentInstrumentCallback callback, 314 ReadPaymentInstrumentCallback callback,
255 ServiceWorkerStatusCode status, 315 ServiceWorkerStatusCode status,
256 scoped_refptr<ServiceWorkerRegistration> registration) { 316 scoped_refptr<ServiceWorkerRegistration> registration) {
257 DCHECK_CURRENTLY_ON(BrowserThread::IO); 317 DCHECK_CURRENTLY_ON(BrowserThread::IO);
258 if (status != SERVICE_WORKER_OK) { 318 if (status != SERVICE_WORKER_OK) {
259 std::move(callback).Run(PaymentInstrument::New(), 319 std::move(callback).Run(PaymentInstrument::New(),
260 PaymentHandlerStatus::NO_ACTIVE_WORKER); 320 PaymentHandlerStatus::NO_ACTIVE_WORKER);
261 return; 321 return;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 WritePaymentInstrumentCallback callback, 385 WritePaymentInstrumentCallback callback,
326 ServiceWorkerStatusCode status) { 386 ServiceWorkerStatusCode status) {
327 DCHECK_CURRENTLY_ON(BrowserThread::IO); 387 DCHECK_CURRENTLY_ON(BrowserThread::IO);
328 return std::move(callback).Run( 388 return std::move(callback).Run(
329 status == SERVICE_WORKER_OK 389 status == SERVICE_WORKER_OK
330 ? PaymentHandlerStatus::SUCCESS 390 ? PaymentHandlerStatus::SUCCESS
331 : PaymentHandlerStatus::STORAGE_OPERATION_FAILED); 391 : PaymentHandlerStatus::STORAGE_OPERATION_FAILED);
332 } 392 }
333 393
334 } // namespace content 394 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698