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 9adcb8b2fa70aceb806ef925f999355b9b5aa0fc..d59277459d731f3e0ed8395c5e28f157b4816990 100644 |
--- a/content/browser/payments/payment_app_database.cc |
+++ b/content/browser/payments/payment_app_database.cc |
@@ -4,12 +4,10 @@ |
#include "content/browser/payments/payment_app_database.h" |
-#include <map> |
#include <utility> |
#include "base/bind.h" |
#include "base/optional.h" |
-#include "base/time/time.h" |
#include "content/browser/payments/payment_app.pb.h" |
#include "content/browser/payments/payment_app_context_impl.h" |
#include "content/browser/service_worker/service_worker_context_wrapper.h" |
@@ -24,16 +22,10 @@ |
using ::payments::mojom::PaymentInstrumentPtr; |
const char kPaymentAppManifestDataKey[] = "PaymentAppManifestData"; |
-const char kPaymentInstrumentPrefix[] = "PaymentInstrument:"; |
-const char kPaymentInstrumentKeyInfoPrefix[] = "PaymentInstrumentKeyInfo:"; |
+const char kPaymentInstrumentKeyPrefix[] = "PaymentInstrument:"; |
std::string CreatePaymentInstrumentKey(const std::string& instrument_key) { |
- return kPaymentInstrumentPrefix + instrument_key; |
-} |
- |
-std::string CreatePaymentInstrumentKeyInfoKey( |
- const std::string& instrument_key) { |
- return kPaymentInstrumentKeyInfoPrefix + instrument_key; |
+ return kPaymentInstrumentKeyPrefix + instrument_key; |
} |
payments::mojom::PaymentAppManifestPtr DeserializePaymentAppManifest( |
@@ -62,21 +54,6 @@ |
return manifest; |
} |
-std::map<uint64_t, std::string> DeserializePaymentInstrumentKeyInfo( |
- const std::vector<std::string>& inputs) { |
- std::map<uint64_t, std::string> key_info; |
- for (const auto& input : inputs) { |
- PaymentInstrumentKeyInfoProto key_info_proto; |
- if (!key_info_proto.ParseFromString(input)) |
- return std::map<uint64_t, std::string>(); |
- |
- key_info.insert(std::pair<uint64_t, std::string>( |
- key_info_proto.insertion_order(), key_info_proto.key())); |
- } |
- |
- return key_info; |
-} |
- |
PaymentInstrumentPtr DeserializePaymentInstrument(const std::string& input) { |
PaymentInstrumentProto instrument_proto; |
if (!instrument_proto.ParseFromString(input)) |
@@ -161,17 +138,6 @@ |
&PaymentAppDatabase::DidFindRegistrationToReadPaymentInstrument, |
weak_ptr_factory_.GetWeakPtr(), instrument_key, |
base::Passed(std::move(callback)))); |
-} |
- |
-void PaymentAppDatabase::KeysOfPaymentInstruments( |
- const GURL& scope, |
- KeysOfPaymentInstrumentsCallback callback) { |
- DCHECK_CURRENTLY_ON(BrowserThread::IO); |
- |
- service_worker_context_->FindReadyRegistrationForPattern( |
- scope, base::Bind(&PaymentAppDatabase::DidFindRegistrationToGetKeys, |
- weak_ptr_factory_.GetWeakPtr(), |
- base::Passed(std::move(callback)))); |
} |
void PaymentAppDatabase::HasPaymentInstrument( |
@@ -346,9 +312,7 @@ |
} |
service_worker_context_->ClearRegistrationUserData( |
- registration_id, |
- {CreatePaymentInstrumentKey(instrument_key), |
- CreatePaymentInstrumentKeyInfoKey(instrument_key)}, |
+ registration_id, {CreatePaymentInstrumentKey(instrument_key)}, |
base::Bind(&PaymentAppDatabase::DidDeletePaymentInstrument, |
weak_ptr_factory_.GetWeakPtr(), |
base::Passed(std::move(callback)))); |
@@ -403,43 +367,6 @@ |
std::move(callback).Run(std::move(instrument), PaymentHandlerStatus::SUCCESS); |
} |
-void PaymentAppDatabase::DidFindRegistrationToGetKeys( |
- KeysOfPaymentInstrumentsCallback callback, |
- ServiceWorkerStatusCode status, |
- scoped_refptr<ServiceWorkerRegistration> registration) { |
- DCHECK_CURRENTLY_ON(BrowserThread::IO); |
- if (status != SERVICE_WORKER_OK) { |
- std::move(callback).Run(std::vector<std::string>(), |
- PaymentHandlerStatus::NO_ACTIVE_WORKER); |
- return; |
- } |
- |
- service_worker_context_->GetRegistrationUserDataByKeyPrefix( |
- registration->id(), {kPaymentInstrumentKeyInfoPrefix}, |
- base::Bind(&PaymentAppDatabase::DidGetKeysOfPaymentInstruments, |
- weak_ptr_factory_.GetWeakPtr(), |
- base::Passed(std::move(callback)))); |
-} |
- |
-void PaymentAppDatabase::DidGetKeysOfPaymentInstruments( |
- KeysOfPaymentInstrumentsCallback callback, |
- const std::vector<std::string>& data, |
- ServiceWorkerStatusCode status) { |
- DCHECK_CURRENTLY_ON(BrowserThread::IO); |
- if (status != SERVICE_WORKER_OK) { |
- std::move(callback).Run(std::vector<std::string>(), |
- PaymentHandlerStatus::NOT_FOUND); |
- return; |
- } |
- |
- std::vector<std::string> keys; |
- for (const auto& key_info : DeserializePaymentInstrumentKeyInfo(data)) { |
- keys.push_back(key_info.second); |
- } |
- |
- std::move(callback).Run(keys, PaymentHandlerStatus::SUCCESS); |
-} |
- |
void PaymentAppDatabase::DidFindRegistrationToHasPaymentInstrument( |
const std::string& instrument_key, |
HasPaymentInstrumentCallback callback, |
@@ -493,21 +420,13 @@ |
instrument_proto.set_stringified_capabilities( |
instrument->stringified_capabilities); |
- std::string serialized_instrument; |
- DCHECK(instrument_proto.SerializeToString(&serialized_instrument)); |
- |
- PaymentInstrumentKeyInfoProto key_info_proto; |
- key_info_proto.set_key(instrument_key); |
- key_info_proto.set_insertion_order(base::Time::Now().ToInternalValue()); |
- |
- std::string serialized_key_info; |
- DCHECK(key_info_proto.SerializeToString(&serialized_key_info)); |
+ std::string serialized; |
+ bool success = instrument_proto.SerializeToString(&serialized); |
+ DCHECK(success); |
service_worker_context_->StoreRegistrationUserData( |
registration->id(), registration->pattern().GetOrigin(), |
- {{CreatePaymentInstrumentKey(instrument_key), serialized_instrument}, |
- {CreatePaymentInstrumentKeyInfoKey(instrument_key), |
- serialized_key_info}}, |
+ {{CreatePaymentInstrumentKey(instrument_key), serialized}}, |
base::Bind(&PaymentAppDatabase::DidWritePaymentInstrument, |
weak_ptr_factory_.GetWeakPtr(), |
base::Passed(std::move(callback)))); |