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

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

Issue 2565423002: Revert of PaymentApp: Introduce PaymentAppDatabase class. (Closed)
Patch Set: 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
deleted file mode 100644
index 9f18a2dc242e44427a398d3af2cb6f1bdbb3122e..0000000000000000000000000000000000000000
--- a/content/browser/payments/payment_app_database.cc
+++ /dev/null
@@ -1,178 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "content/browser/payments/payment_app_database.h"
-
-#include <utility>
-
-#include "base/bind.h"
-#include "base/optional.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"
-#include "content/browser/service_worker/service_worker_registration.h"
-#include "content/public/browser/browser_thread.h"
-
-namespace content {
-namespace {
-
-const char kPaymentAppManifestDataKey[] = "PaymentAppManifestData";
-
-payments::mojom::PaymentAppManifestPtr DeserializePaymentAppManifest(
- const std::string& input) {
- PaymentAppManifestProto manifest_proto;
- bool success = manifest_proto.ParseFromString(input);
- if (!success)
- return nullptr;
-
- payments::mojom::PaymentAppManifestPtr manifest =
- payments::mojom::PaymentAppManifest::New();
-
- manifest->label = manifest_proto.label();
- 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->label = option_proto.label();
- 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;
-}
-
-bool SerializePaymentAppManifest(
- payments::mojom::PaymentAppManifestPtr manifest,
- std::string* output) {
- DCHECK(manifest);
-
- PaymentAppManifestProto manifest_proto;
- manifest_proto.set_label(manifest->label);
- if (manifest->icon)
- manifest_proto.set_icon(manifest->icon.value());
-
- for (const auto& option : manifest->options) {
- PaymentAppOptionProto* option_proto = manifest_proto.add_options();
- option_proto->set_label(option->label);
- if (option->icon)
- option_proto->set_icon(option->icon.value());
- option_proto->set_id(option->id);
- for (const auto& method : option->enabled_methods) {
- option_proto->add_enabled_methods(method);
- }
- }
-
- return manifest_proto.SerializeToString(output);
-}
-
-} // namespace
-
-PaymentAppDatabase::PaymentAppDatabase(
- scoped_refptr<ServiceWorkerContextWrapper> service_worker_context)
- : service_worker_context_(service_worker_context), weak_ptr_factory_(this) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
-}
-
-PaymentAppDatabase::~PaymentAppDatabase() {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
-}
-
-void PaymentAppDatabase::WriteManifest(
- const GURL& scope,
- payments::mojom::PaymentAppManifestPtr manifest,
- const WriteManifestCallback& callback) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
-
- service_worker_context_->FindReadyRegistrationForPattern(
- scope, base::Bind(&PaymentAppDatabase::DidFindRegistrationToWriteManifest,
- weak_ptr_factory_.GetWeakPtr(),
- base::Passed(std::move(manifest)), callback));
-}
-
-void PaymentAppDatabase::ReadManifest(const GURL& scope,
- const ReadManifestCallback& callback) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
-
- service_worker_context_->FindReadyRegistrationForPattern(
- scope, base::Bind(&PaymentAppDatabase::DidFindRegistrationToReadManifest,
- weak_ptr_factory_.GetWeakPtr(), callback));
-}
-
-void PaymentAppDatabase::DidFindRegistrationToWriteManifest(
- payments::mojom::PaymentAppManifestPtr manifest,
- const WriteManifestCallback& callback,
- ServiceWorkerStatusCode status,
- scoped_refptr<ServiceWorkerRegistration> registration) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (status != SERVICE_WORKER_OK) {
- callback.Run(payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER);
- return;
- }
-
- std::string serialized;
- DCHECK(SerializePaymentAppManifest(std::move(manifest), &serialized));
-
- service_worker_context_->StoreRegistrationUserData(
- registration->id(), registration->pattern().GetOrigin(),
- {{kPaymentAppManifestDataKey, serialized}},
- base::Bind(&PaymentAppDatabase::DidWriteManifest,
- weak_ptr_factory_.GetWeakPtr(), callback));
-}
-
-void PaymentAppDatabase::DidWriteManifest(const WriteManifestCallback& callback,
- ServiceWorkerStatusCode status) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- return callback.Run(status == SERVICE_WORKER_OK
- ? payments::mojom::PaymentAppManifestError::NONE
- : payments::mojom::PaymentAppManifestError::
- MANIFEST_STORAGE_OPERATION_FAILED);
-}
-
-void PaymentAppDatabase::DidFindRegistrationToReadManifest(
- const ReadManifestCallback& callback,
- ServiceWorkerStatusCode status,
- scoped_refptr<ServiceWorkerRegistration> registration) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (status != SERVICE_WORKER_OK) {
- callback.Run(payments::mojom::PaymentAppManifest::New(),
- payments::mojom::PaymentAppManifestError::NO_ACTIVE_WORKER);
- return;
- }
-
- service_worker_context_->GetRegistrationUserData(
- registration->id(), {kPaymentAppManifestDataKey},
- base::Bind(&PaymentAppDatabase::DidReadManifest,
- weak_ptr_factory_.GetWeakPtr(), callback));
-}
-
-void PaymentAppDatabase::DidReadManifest(const ReadManifestCallback& callback,
- const std::vector<std::string>& data,
- ServiceWorkerStatusCode status) {
- DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (status != SERVICE_WORKER_OK || data.size() != 1) {
- callback.Run(payments::mojom::PaymentAppManifest::New(),
- payments::mojom::PaymentAppManifestError::
- MANIFEST_STORAGE_OPERATION_FAILED);
- return;
- }
-
- payments::mojom::PaymentAppManifestPtr manifest =
- DeserializePaymentAppManifest(data[0]);
- if (!manifest) {
- callback.Run(payments::mojom::PaymentAppManifest::New(),
- payments::mojom::PaymentAppManifestError::
- MANIFEST_STORAGE_OPERATION_FAILED);
- return;
- }
-
- callback.Run(std::move(manifest),
- payments::mojom::PaymentAppManifestError::NONE);
-}
-
-} // 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