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

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

Issue 2556433002: PaymentApp: Implement GetAllManifests() in PaymentAppContext. (Closed)
Patch Set: addressed comments Created 4 years 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_app_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 765de426a7f91da0a7031f5003a9714ea057327b..1809cc398d9fa3abf405902f41b5b7e637e78e55 100644
--- a/content/browser/payments/payment_app_database.cc
+++ b/content/browser/payments/payment_app_database.cc
@@ -19,6 +19,32 @@ namespace {
const char kPaymentAppManifestDataKey[] = "PaymentAppManifestData";
+payments::mojom::PaymentAppManifestPtr DeserializePaymentAppManifest(
+ const std::string& input) {
+ PaymentAppManifestProto manifest_proto;
+ if (!manifest_proto.ParseFromString(input))
+ return nullptr;
+
+ payments::mojom::PaymentAppManifestPtr manifest =
+ payments::mojom::PaymentAppManifest::New();
+ manifest->name = manifest_proto.name();
+ if (manifest_proto.has_icon())
+ manifest->icon = manifest_proto.icon();
+ for (const auto& option_proto : manifest_proto.options()) {
+ payments::mojom::PaymentAppOptionPtr option =
+ payments::mojom::PaymentAppOption::New();
+ option->name = option_proto.name();
+ if (option_proto.has_icon())
+ option->icon = option_proto.icon();
+ option->id = option_proto.id();
+ for (const auto& method : option_proto.enabled_methods())
+ option->enabled_methods.push_back(method);
+ manifest->options.push_back(std::move(option));
+ }
+
+ return manifest;
+}
+
} // namespace
PaymentAppDatabase::PaymentAppDatabase(
@@ -52,6 +78,16 @@ void PaymentAppDatabase::ReadManifest(const GURL& scope,
weak_ptr_factory_.GetWeakPtr(), callback));
}
+void PaymentAppDatabase::ReadAllManifests(
+ const ReadAllManifestsCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ service_worker_context_->GetUserDataForAllRegistrations(
+ kPaymentAppManifestDataKey,
+ base::Bind(&PaymentAppDatabase::DidReadAllManifests,
+ weak_ptr_factory_.GetWeakPtr(), callback));
+}
+
void PaymentAppDatabase::DidFindRegistrationToWriteManifest(
payments::mojom::PaymentAppManifestPtr manifest,
const WriteManifestCallback& callback,
@@ -127,34 +163,41 @@ void PaymentAppDatabase::DidReadManifest(const ReadManifestCallback& callback,
return;
}
- PaymentAppManifestProto manifest_proto;
- bool success = manifest_proto.ParseFromString(data[0]);
- if (!success) {
+ payments::mojom::PaymentAppManifestPtr manifest =
+ DeserializePaymentAppManifest(data[0]);
+ if (!manifest) {
callback.Run(payments::mojom::PaymentAppManifest::New(),
payments::mojom::PaymentAppManifestError::
MANIFEST_STORAGE_OPERATION_FAILED);
return;
}
- payments::mojom::PaymentAppManifestPtr manifest =
- payments::mojom::PaymentAppManifest::New();
- manifest->name = manifest_proto.name();
- if (manifest_proto.has_icon())
- manifest->icon = manifest_proto.icon();
- for (const auto& option_proto : manifest_proto.options()) {
- payments::mojom::PaymentAppOptionPtr option =
- payments::mojom::PaymentAppOption::New();
- option->name = option_proto.name();
- if (option_proto.has_icon())
- option->icon = option_proto.icon();
- option->id = option_proto.id();
- for (const auto& method : option_proto.enabled_methods())
- option->enabled_methods.push_back(method);
- manifest->options.push_back(std::move(option));
- }
-
callback.Run(std::move(manifest),
payments::mojom::PaymentAppManifestError::NONE);
}
+void PaymentAppDatabase::DidReadAllManifests(
+ const ReadAllManifestsCallback& callback,
+ const std::vector<std::pair<int64_t, std::string>>& raw_data,
+ ServiceWorkerStatusCode status) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ if (status != SERVICE_WORKER_OK) {
+ callback.Run(Manifests());
+ return;
+ }
+
+ Manifests manifests;
+ for (const auto& item_of_raw_data : raw_data) {
+ payments::mojom::PaymentAppManifestPtr manifest =
+ DeserializePaymentAppManifest(item_of_raw_data.second);
+ if (!manifest)
+ continue;
+
+ manifests.push_back(
+ ManifestWithID(item_of_raw_data.first, std::move(manifest)));
+ }
+
+ callback.Run(std::move(manifests));
+}
+
} // namespace content
« no previous file with comments | « content/browser/payments/payment_app_database.h ('k') | content/browser/payments/payment_app_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698