| 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 93c47209ac331f929fee35542adb32e6c41538f7..a157cf4dcd40bba990393ca82efca522fcc9289b 100644
|
| --- a/content/browser/payments/payment_app_database.cc
|
| +++ b/content/browser/payments/payment_app_database.cc
|
| @@ -8,6 +8,7 @@
|
| #include <utility>
|
|
|
| #include "base/bind.h"
|
| +#include "base/memory/ptr_util.h"
|
| #include "base/optional.h"
|
| #include "base/time/time.h"
|
| #include "content/browser/payments/payment_app.pb.h"
|
| @@ -20,7 +21,6 @@ namespace content {
|
| namespace {
|
|
|
| using ::payments::mojom::PaymentHandlerStatus;
|
| -using ::payments::mojom::PaymentInstrument;
|
| using ::payments::mojom::PaymentInstrumentPtr;
|
|
|
| const char kPaymentAppManifestDataKey[] = "PaymentAppManifestData";
|
| @@ -77,12 +77,13 @@ std::map<uint64_t, std::string> DeserializePaymentInstrumentKeyInfo(
|
| return key_info;
|
| }
|
|
|
| -PaymentInstrumentPtr DeserializePaymentInstrument(const std::string& input) {
|
| +PaymentInstrumentPtr DeserializePaymentInstrumentForMojo(
|
| + const std::string& input) {
|
| PaymentInstrumentProto instrument_proto;
|
| if (!instrument_proto.ParseFromString(input))
|
| return nullptr;
|
|
|
| - PaymentInstrumentPtr instrument = PaymentInstrument::New();
|
| + PaymentInstrumentPtr instrument = payments::mojom::PaymentInstrument::New();
|
| instrument->name = instrument_proto.name();
|
| for (const auto& method : instrument_proto.enabled_methods())
|
| instrument->enabled_methods.push_back(method);
|
| @@ -92,6 +93,24 @@ PaymentInstrumentPtr DeserializePaymentInstrument(const std::string& input) {
|
| return instrument;
|
| }
|
|
|
| +std::unique_ptr<content::PaymentInstrument> DeserializePaymentInstrument(
|
| + const std::string& input) {
|
| + PaymentInstrumentProto instrument_proto;
|
| + if (!instrument_proto.ParseFromString(input))
|
| + return std::unique_ptr<content::PaymentInstrument>();
|
| +
|
| + std::unique_ptr<content::PaymentInstrument> instrument =
|
| + base::MakeUnique<content::PaymentInstrument>();
|
| + instrument->registration_id = instrument_proto.registration_id();
|
| + instrument->instrument_key = instrument_proto.instrument_key();
|
| + instrument->origin = GURL(instrument_proto.origin());
|
| + instrument->name = instrument_proto.name();
|
| + for (const auto& method : instrument_proto.enabled_methods())
|
| + instrument->enabled_methods.push_back(method);
|
| +
|
| + return instrument;
|
| +}
|
| +
|
| } // namespace
|
|
|
| PaymentAppDatabase::PaymentAppDatabase(
|
| @@ -135,6 +154,17 @@ void PaymentAppDatabase::ReadAllManifests(ReadAllManifestsCallback callback) {
|
| weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback)));
|
| }
|
|
|
| +void PaymentAppDatabase::ReadAllPaymentApps(
|
| + ReadAllPaymentAppsCallback callback) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| +
|
| + service_worker_context_->GetUserDataForAllRegistrationsByKeyPrefix(
|
| + kPaymentInstrumentPrefix,
|
| + base::Bind(&PaymentAppDatabase::DidReadAllPaymentApps,
|
| + weak_ptr_factory_.GetWeakPtr(),
|
| + base::Passed(std::move(callback))));
|
| +}
|
| +
|
| void PaymentAppDatabase::DeletePaymentInstrument(
|
| const GURL& scope,
|
| const std::string& instrument_key,
|
| @@ -330,6 +360,30 @@ void PaymentAppDatabase::DidReadAllManifests(
|
| std::move(callback).Run(std::move(manifests));
|
| }
|
|
|
| +void PaymentAppDatabase::DidReadAllPaymentApps(
|
| + ReadAllPaymentAppsCallback callback,
|
| + const std::vector<std::pair<int64_t, std::string>>& raw_data,
|
| + ServiceWorkerStatusCode status) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + if (status != SERVICE_WORKER_OK) {
|
| + std::move(callback).Run(PaymentApps());
|
| + return;
|
| + }
|
| +
|
| + PaymentApps apps;
|
| + for (const auto& item_of_raw_data : raw_data) {
|
| + std::unique_ptr<PaymentInstrument> instrument =
|
| + DeserializePaymentInstrument(item_of_raw_data.second);
|
| + if (!instrument)
|
| + continue;
|
| + if (!base::ContainsKey(apps, instrument->origin))
|
| + apps.insert(std::make_pair(instrument->origin, Instruments()));
|
| + apps[instrument->origin].push_back(std::move(instrument));
|
| + }
|
| +
|
| + std::move(callback).Run(std::move(apps));
|
| +}
|
| +
|
| void PaymentAppDatabase::DidFindRegistrationToDeletePaymentInstrument(
|
| const std::string& instrument_key,
|
| DeletePaymentInstrumentCallback callback,
|
| @@ -385,7 +439,7 @@ void PaymentAppDatabase::DidFindRegistrationToReadPaymentInstrument(
|
| scoped_refptr<ServiceWorkerRegistration> registration) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| if (status != SERVICE_WORKER_OK) {
|
| - std::move(callback).Run(PaymentInstrument::New(),
|
| + std::move(callback).Run(payments::mojom::PaymentInstrument::New(),
|
| PaymentHandlerStatus::NO_ACTIVE_WORKER);
|
| return;
|
| }
|
| @@ -403,14 +457,15 @@ void PaymentAppDatabase::DidReadPaymentInstrument(
|
| ServiceWorkerStatusCode status) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| if (status != SERVICE_WORKER_OK || data.size() != 1) {
|
| - std::move(callback).Run(PaymentInstrument::New(),
|
| + std::move(callback).Run(payments::mojom::PaymentInstrument::New(),
|
| PaymentHandlerStatus::NOT_FOUND);
|
| return;
|
| }
|
|
|
| - PaymentInstrumentPtr instrument = DeserializePaymentInstrument(data[0]);
|
| + PaymentInstrumentPtr instrument =
|
| + DeserializePaymentInstrumentForMojo(data[0]);
|
| if (!instrument) {
|
| - std::move(callback).Run(PaymentInstrument::New(),
|
| + std::move(callback).Run(payments::mojom::PaymentInstrument::New(),
|
| PaymentHandlerStatus::STORAGE_OPERATION_FAILED);
|
| return;
|
| }
|
| @@ -501,6 +556,9 @@ void PaymentAppDatabase::DidFindRegistrationToWritePaymentInstrument(
|
| }
|
|
|
| PaymentInstrumentProto instrument_proto;
|
| + instrument_proto.set_registration_id(registration->id());
|
| + instrument_proto.set_instrument_key(instrument_key);
|
| + instrument_proto.set_origin(registration->pattern().GetOrigin().spec());
|
| instrument_proto.set_name(instrument->name);
|
| for (const auto& method : instrument->enabled_methods) {
|
| instrument_proto.add_enabled_methods(method);
|
|
|