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

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

Issue 2572183002: PaymentApp: Introduce PaymentAppDatabase class. (Closed)
Patch Set: rebase 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_manager.cc b/content/browser/payments/payment_app_database.cc
similarity index 63%
copy from content/browser/payments/payment_app_manager.cc
copy to content/browser/payments/payment_app_database.cc
index dc98a02c3c7ce4a920a584e938a16e4233201057..e21bb765afb42d4b1157b2a6cde77d3c6185130d 100644
--- a/content/browser/payments/payment_app_manager.cc
+++ b/content/browser/payments/payment_app_database.cc
@@ -2,7 +2,7 @@
// 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_manager.h"
+#include "content/browser/payments/payment_app_database.h"
#include <utility>
@@ -21,59 +21,40 @@ const char kPaymentAppManifestDataKey[] = "PaymentAppManifestData";
} // namespace
-PaymentAppManager::~PaymentAppManager() {
+PaymentAppDatabase::PaymentAppDatabase(
+ scoped_refptr<ServiceWorkerContextWrapper> service_worker_context)
+ : service_worker_context_(service_worker_context), weak_ptr_factory_(this) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
}
-PaymentAppManager::PaymentAppManager(
- PaymentAppContextImpl* payment_app_context,
- mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request)
- : payment_app_context_(payment_app_context),
- binding_(this, std::move(request)),
- weak_ptr_factory_(this) {
+PaymentAppDatabase::~PaymentAppDatabase() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- DCHECK(payment_app_context);
-
- binding_.set_connection_error_handler(
- base::Bind(&PaymentAppManager::OnConnectionError,
- base::Unretained(this)));
-}
-
-void PaymentAppManager::OnConnectionError() {
- payment_app_context_->ServiceHadConnectionError(this);
}
-void PaymentAppManager::SetManifest(
- const std::string& scope,
+void PaymentAppDatabase::WriteManifest(
+ const GURL& scope,
payments::mojom::PaymentAppManifestPtr manifest,
- const SetManifestCallback& callback) {
+ const WriteManifestCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- // TODO(zino): Should implement requesting a permission for users to allow
- // the payment app to be registered. Please see http://crbug.com/665949.
-
- payment_app_context_->service_worker_context()
- ->FindReadyRegistrationForPattern(
- GURL(scope),
- base::Bind(&PaymentAppManager::DidFindRegistrationToSetManifest,
- weak_ptr_factory_.GetWeakPtr(),
- base::Passed(std::move(manifest)), callback));
+ service_worker_context_->FindReadyRegistrationForPattern(
+ scope, base::Bind(&PaymentAppDatabase::DidFindRegistrationToWriteManifest,
+ weak_ptr_factory_.GetWeakPtr(),
+ base::Passed(std::move(manifest)), callback));
}
-void PaymentAppManager::GetManifest(const std::string& scope,
- const GetManifestCallback& callback) {
+void PaymentAppDatabase::ReadManifest(const GURL& scope,
+ const ReadManifestCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- payment_app_context_->service_worker_context()
- ->FindReadyRegistrationForPattern(
- GURL(scope),
- base::Bind(&PaymentAppManager::DidFindRegistrationToGetManifest,
- weak_ptr_factory_.GetWeakPtr(), callback));
+ service_worker_context_->FindReadyRegistrationForPattern(
+ scope, base::Bind(&PaymentAppDatabase::DidFindRegistrationToReadManifest,
+ weak_ptr_factory_.GetWeakPtr(), callback));
}
-void PaymentAppManager::DidFindRegistrationToSetManifest(
+void PaymentAppDatabase::DidFindRegistrationToWriteManifest(
payments::mojom::PaymentAppManifestPtr manifest,
- const SetManifestCallback& callback,
+ const WriteManifestCallback& callback,
ServiceWorkerStatusCode status,
scoped_refptr<ServiceWorkerRegistration> registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -102,15 +83,15 @@ void PaymentAppManager::DidFindRegistrationToSetManifest(
bool success = manifest_proto.SerializeToString(&serialized);
DCHECK(success);
- payment_app_context_->service_worker_context()->StoreRegistrationUserData(
+ service_worker_context_->StoreRegistrationUserData(
registration->id(), registration->pattern().GetOrigin(),
{{kPaymentAppManifestDataKey, serialized}},
- base::Bind(&PaymentAppManager::DidSetManifest,
+ base::Bind(&PaymentAppDatabase::DidWriteManifest,
weak_ptr_factory_.GetWeakPtr(), callback));
}
-void PaymentAppManager::DidSetManifest(const SetManifestCallback& callback,
- ServiceWorkerStatusCode status) {
+void PaymentAppDatabase::DidWriteManifest(const WriteManifestCallback& callback,
+ ServiceWorkerStatusCode status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
return callback.Run(status == SERVICE_WORKER_OK
? payments::mojom::PaymentAppManifestError::NONE
@@ -118,8 +99,8 @@ void PaymentAppManager::DidSetManifest(const SetManifestCallback& callback,
MANIFEST_STORAGE_OPERATION_FAILED);
}
-void PaymentAppManager::DidFindRegistrationToGetManifest(
- const GetManifestCallback& callback,
+void PaymentAppDatabase::DidFindRegistrationToReadManifest(
+ const ReadManifestCallback& callback,
ServiceWorkerStatusCode status,
scoped_refptr<ServiceWorkerRegistration> registration) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -129,15 +110,15 @@ void PaymentAppManager::DidFindRegistrationToGetManifest(
return;
}
- payment_app_context_->service_worker_context()->GetRegistrationUserData(
+ service_worker_context_->GetRegistrationUserData(
registration->id(), {kPaymentAppManifestDataKey},
- base::Bind(&PaymentAppManager::DidGetManifest,
+ base::Bind(&PaymentAppDatabase::DidReadManifest,
weak_ptr_factory_.GetWeakPtr(), callback));
}
-void PaymentAppManager::DidGetManifest(const GetManifestCallback& callback,
- const std::vector<std::string>& data,
- ServiceWorkerStatusCode status) {
+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(),
« 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