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

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

Issue 2844673002: PaymentHandler: Implement PaymentInstruments.has(). (Closed)
Patch Set: PaymentHandler: Implement PaymentInstruments.has(). 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 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 DCHECK_CURRENTLY_ON(BrowserThread::IO); 128 DCHECK_CURRENTLY_ON(BrowserThread::IO);
129 129
130 service_worker_context_->FindReadyRegistrationForPattern( 130 service_worker_context_->FindReadyRegistrationForPattern(
131 scope, 131 scope,
132 base::Bind( 132 base::Bind(
133 &PaymentAppDatabase::DidFindRegistrationToReadPaymentInstrument, 133 &PaymentAppDatabase::DidFindRegistrationToReadPaymentInstrument,
134 weak_ptr_factory_.GetWeakPtr(), instrument_key, 134 weak_ptr_factory_.GetWeakPtr(), instrument_key,
135 base::Passed(std::move(callback)))); 135 base::Passed(std::move(callback))));
136 } 136 }
137 137
138 void PaymentAppDatabase::HasPaymentInstrument(
139 const GURL& scope,
140 const std::string& instrument_key,
141 HasPaymentInstrumentCallback callback) {
142 DCHECK_CURRENTLY_ON(BrowserThread::IO);
143
144 service_worker_context_->FindReadyRegistrationForPattern(
145 scope,
146 base::Bind(&PaymentAppDatabase::DidFindRegistrationToHasPaymentInstrument,
147 weak_ptr_factory_.GetWeakPtr(), instrument_key,
148 base::Passed(std::move(callback))));
149 }
150
138 void PaymentAppDatabase::WritePaymentInstrument( 151 void PaymentAppDatabase::WritePaymentInstrument(
139 const GURL& scope, 152 const GURL& scope,
140 const std::string& instrument_key, 153 const std::string& instrument_key,
141 PaymentInstrumentPtr instrument, 154 PaymentInstrumentPtr instrument,
142 WritePaymentInstrumentCallback callback) { 155 WritePaymentInstrumentCallback callback) {
143 DCHECK_CURRENTLY_ON(BrowserThread::IO); 156 DCHECK_CURRENTLY_ON(BrowserThread::IO);
144 157
145 service_worker_context_->FindReadyRegistrationForPattern( 158 service_worker_context_->FindReadyRegistrationForPattern(
146 scope, 159 scope,
147 base::Bind( 160 base::Bind(
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 PaymentInstrumentPtr instrument = DeserializePaymentInstrument(data[0]); 355 PaymentInstrumentPtr instrument = DeserializePaymentInstrument(data[0]);
343 if (!instrument) { 356 if (!instrument) {
344 std::move(callback).Run(PaymentInstrument::New(), 357 std::move(callback).Run(PaymentInstrument::New(),
345 PaymentHandlerStatus::STORAGE_OPERATION_FAILED); 358 PaymentHandlerStatus::STORAGE_OPERATION_FAILED);
346 return; 359 return;
347 } 360 }
348 361
349 std::move(callback).Run(std::move(instrument), PaymentHandlerStatus::SUCCESS); 362 std::move(callback).Run(std::move(instrument), PaymentHandlerStatus::SUCCESS);
350 } 363 }
351 364
365 void PaymentAppDatabase::DidFindRegistrationToHasPaymentInstrument(
366 const std::string& instrument_key,
367 HasPaymentInstrumentCallback callback,
368 ServiceWorkerStatusCode status,
369 scoped_refptr<ServiceWorkerRegistration> registration) {
370 DCHECK_CURRENTLY_ON(BrowserThread::IO);
371 if (status != SERVICE_WORKER_OK) {
372 std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER);
373 return;
374 }
375
376 service_worker_context_->GetRegistrationUserData(
377 registration->id(), {instrument_key},
378 base::Bind(&PaymentAppDatabase::DidHasPaymentInstrument,
379 weak_ptr_factory_.GetWeakPtr(), registration->id(),
380 instrument_key, base::Passed(std::move(callback))));
381 }
382
383 void PaymentAppDatabase::DidHasPaymentInstrument(
384 int64_t registration_id,
385 const std::string& instrument_key,
386 DeletePaymentInstrumentCallback callback,
387 const std::vector<std::string>& data,
388 ServiceWorkerStatusCode status) {
389 DCHECK_CURRENTLY_ON(BrowserThread::IO);
390 if (status != SERVICE_WORKER_OK || data.size() != 1) {
391 std::move(callback).Run(PaymentHandlerStatus::NOT_FOUND);
392 return;
393 }
394
395 std::move(callback).Run(PaymentHandlerStatus::SUCCESS);
396 }
397
352 void PaymentAppDatabase::DidFindRegistrationToWritePaymentInstrument( 398 void PaymentAppDatabase::DidFindRegistrationToWritePaymentInstrument(
353 const std::string& instrument_key, 399 const std::string& instrument_key,
354 PaymentInstrumentPtr instrument, 400 PaymentInstrumentPtr instrument,
355 WritePaymentInstrumentCallback callback, 401 WritePaymentInstrumentCallback callback,
356 ServiceWorkerStatusCode status, 402 ServiceWorkerStatusCode status,
357 scoped_refptr<ServiceWorkerRegistration> registration) { 403 scoped_refptr<ServiceWorkerRegistration> registration) {
358 DCHECK_CURRENTLY_ON(BrowserThread::IO); 404 DCHECK_CURRENTLY_ON(BrowserThread::IO);
359 if (status != SERVICE_WORKER_OK) { 405 if (status != SERVICE_WORKER_OK) {
360 std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER); 406 std::move(callback).Run(PaymentHandlerStatus::NO_ACTIVE_WORKER);
361 return; 407 return;
(...skipping 23 matching lines...) Expand all
385 WritePaymentInstrumentCallback callback, 431 WritePaymentInstrumentCallback callback,
386 ServiceWorkerStatusCode status) { 432 ServiceWorkerStatusCode status) {
387 DCHECK_CURRENTLY_ON(BrowserThread::IO); 433 DCHECK_CURRENTLY_ON(BrowserThread::IO);
388 return std::move(callback).Run( 434 return std::move(callback).Run(
389 status == SERVICE_WORKER_OK 435 status == SERVICE_WORKER_OK
390 ? PaymentHandlerStatus::SUCCESS 436 ? PaymentHandlerStatus::SUCCESS
391 : PaymentHandlerStatus::STORAGE_OPERATION_FAILED); 437 : PaymentHandlerStatus::STORAGE_OPERATION_FAILED);
392 } 438 }
393 439
394 } // namespace content 440 } // namespace content
OLDNEW
« 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