Commit 3b0d3c1f authored by jinho.bang's avatar jinho.bang Committed by Commit bot

PaymentApp: Introduce PaymentAppDatabase class.

The class is providing APIs to read/write payment app related data(e.g. manifest
and associated service worker). It can be shared between payment_app_manager.cc
and payment_app_context.cc.

The payment_app_manager.cc contains a actual implementation of the
PaymentAppManager interface[1] used on the page or worker.
Also, the payment_app_context.cc can be used to query all manifests data[2]
in order to update payment request UI in Chrome layer.

We can summarize this CL as follows.
  1. Rename PaymentAppContext in content/browser/payments to
     PaymentAppContextImpl and then add PaymentAppContext interface in
     content/public to expose some APIs to Chrome layer.
  2. Write PaymentAppDatabase class and then move most of logics to access
     database from PaymentAppManager to the new class.
  3. Add a interface to query all manifests data in Chrome layer but it's not
     implemented yet in this CL. It will be implemented in follow-up CL[2].

[1] https://w3c.github.io/webpayments-payment-apps-api/#payment-app-manager
[2] https://codereview.chromium.org/2556433002

BUG=661608
TEST=existing unittests

Review-Url: https://codereview.chromium.org/2560293002
Cr-Commit-Position: refs/heads/master@{#437855}
parent 2418e1b6
......@@ -956,8 +956,10 @@ source_set("browser") {
"notifications/platform_notification_context_impl.h",
"notifications/type_converters.cc",
"notifications/type_converters.h",
"payments/payment_app_context.cc",
"payments/payment_app_context.h",
"payments/payment_app_context_impl.cc",
"payments/payment_app_context_impl.h",
"payments/payment_app_database.cc",
"payments/payment_app_database.h",
"payments/payment_app_manager.cc",
"payments/payment_app_manager.h",
"permissions/permission_service_context.cc",
......
......@@ -2,68 +2,92 @@
// 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_context.h"
#include "content/browser/payments/payment_app_context_impl.h"
#include <utility>
#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "base/stl_util.h"
#include "content/browser/payments/payment_app_database.h"
#include "content/browser/payments/payment_app_manager.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/public/browser/browser_thread.h"
namespace content {
PaymentAppContext::PaymentAppContext(
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context)
: service_worker_context_(std::move(service_worker_context)) {
PaymentAppContextImpl::PaymentAppContextImpl() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
}
PaymentAppContext::~PaymentAppContext() {
DCHECK(services_.empty());
void PaymentAppContextImpl::Init(
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&PaymentAppContextImpl::CreatePaymentAppDatabaseOnIO, this,
service_worker_context));
}
void PaymentAppContext::Shutdown() {
void PaymentAppContextImpl::Shutdown() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&PaymentAppContext::ShutdownOnIO, this));
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&PaymentAppContextImpl::ShutdownOnIO, this));
}
void PaymentAppContext::CreateService(
void PaymentAppContextImpl::CreateService(
mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&PaymentAppContext::CreateServiceOnIOThread, this,
base::Bind(&PaymentAppContextImpl::CreateServiceOnIOThread, this,
base::Passed(&request)));
}
void PaymentAppContext::ServiceHadConnectionError(PaymentAppManager* service) {
void PaymentAppContextImpl::ServiceHadConnectionError(
PaymentAppManager* service) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(base::ContainsKey(services_, service));
services_.erase(service);
}
ServiceWorkerContextWrapper* PaymentAppContext::service_worker_context() const {
return service_worker_context_.get();
PaymentAppDatabase* PaymentAppContextImpl::payment_app_database() const {
return payment_app_database_.get();
}
void PaymentAppContextImpl::GetAllManifests(
const GetAllManifestsCallback& callback) {
NOTIMPLEMENTED();
}
PaymentAppContextImpl::~PaymentAppContextImpl() {
DCHECK(services_.empty());
DCHECK(!payment_app_database_);
}
void PaymentAppContextImpl::CreatePaymentAppDatabaseOnIO(
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
payment_app_database_ =
base::WrapUnique(new PaymentAppDatabase(service_worker_context));
}
void PaymentAppContext::CreateServiceOnIOThread(
void PaymentAppContextImpl::CreateServiceOnIOThread(
mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
PaymentAppManager* service = new PaymentAppManager(this, std::move(request));
services_[service] = base::WrapUnique(service);
}
void PaymentAppContext::ShutdownOnIO() {
void PaymentAppContextImpl::ShutdownOnIO() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
services_.clear();
payment_app_database_.reset();
}
} // namespace content
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_CONTEXT_H_
#define CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_CONTEXT_H_
#ifndef CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_CONTEXT_IMPL_H_
#define CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_CONTEXT_IMPL_H_
#include <map>
#include <memory>
......@@ -11,18 +11,23 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "components/payments/payment_app.mojom.h"
#include "content/browser/payments/payment_app_database.h"
#include "content/common/content_export.h"
#include "content/public/browser/payment_app_context.h"
namespace content {
class PaymentAppManager;
class ServiceWorkerContextWrapper;
class CONTENT_EXPORT PaymentAppContext
: public base::RefCountedThreadSafe<PaymentAppContext> {
class CONTENT_EXPORT PaymentAppContextImpl
: NON_EXPORTED_BASE(public PaymentAppContext),
public base::RefCountedThreadSafe<PaymentAppContextImpl> {
public:
explicit PaymentAppContext(
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context);
PaymentAppContextImpl();
// Init and Shutdown are for use on the UI thread when the
// StoragePartition is being setup and torn down.
void Init(scoped_refptr<ServiceWorkerContextWrapper> service_worker_context);
// Shutdown must be called before deleting this. Call on the UI thread.
void Shutdown();
......@@ -36,29 +41,35 @@ class CONTENT_EXPORT PaymentAppContext
// be deleted. Call on the IO thread.
void ServiceHadConnectionError(PaymentAppManager* service);
ServiceWorkerContextWrapper* service_worker_context() const;
PaymentAppDatabase* payment_app_database() const;
void GetAllManifests(const GetAllManifestsCallback& callback) override;
protected:
friend class base::RefCountedThreadSafe<PaymentAppContext>;
friend class base::RefCountedThreadSafe<PaymentAppContextImpl>;
friend class PaymentAppManagerTest;
virtual ~PaymentAppContext();
virtual ~PaymentAppContextImpl();
private:
void CreatePaymentAppDatabaseOnIO(
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context);
void CreateServiceOnIOThread(
mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request);
void ShutdownOnIO();
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
// Only accessed on the IO thread.
std::unique_ptr<PaymentAppDatabase> payment_app_database_;
// The services are owned by this. They're either deleted
// during ShutdownOnIO or when the channel is closed via
// ServiceHadConnectionError. Only accessed on the IO thread.
std::map<PaymentAppManager*, std::unique_ptr<PaymentAppManager>> services_;
DISALLOW_COPY_AND_ASSIGN(PaymentAppContext);
DISALLOW_COPY_AND_ASSIGN(PaymentAppContextImpl);
};
} // namespace content
#endif // CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_CONTEXT_H_
#endif // CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_CONTEXT_IMPL_H_
// 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
// 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.
#ifndef CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_DATABASE_H_
#define CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_DATABASE_H_
#include <string>
#include <vector>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "components/payments/payment_app.mojom.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_registration.h"
#include "content/common/content_export.h"
#include "content/common/service_worker/service_worker_status_code.h"
#include "mojo/public/cpp/bindings/binding.h"
namespace content {
class ServiceWorkerRegistration;
class CONTENT_EXPORT PaymentAppDatabase {
public:
using WriteManifestCallback =
base::Callback<void(payments::mojom::PaymentAppManifestError)>;
using ReadManifestCallback =
base::Callback<void(payments::mojom::PaymentAppManifestPtr,
payments::mojom::PaymentAppManifestError)>;
explicit PaymentAppDatabase(
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context);
~PaymentAppDatabase();
void WriteManifest(const GURL& scope,
payments::mojom::PaymentAppManifestPtr manifest,
const WriteManifestCallback& callback);
void ReadManifest(const GURL& scope, const ReadManifestCallback& callback);
private:
// WriteManifest callbacks
void DidFindRegistrationToWriteManifest(
payments::mojom::PaymentAppManifestPtr manifest,
const WriteManifestCallback& callback,
ServiceWorkerStatusCode status,
scoped_refptr<ServiceWorkerRegistration> registration);
void DidWriteManifest(const WriteManifestCallback& callback,
ServiceWorkerStatusCode status);
// ReadManifest callbacks
void DidFindRegistrationToReadManifest(
const ReadManifestCallback& callback,
ServiceWorkerStatusCode status,
scoped_refptr<ServiceWorkerRegistration> registration);
void DidReadManifest(const ReadManifestCallback& callback,
const std::vector<std::string>& data,
ServiceWorkerStatusCode status);
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
base::WeakPtrFactory<PaymentAppDatabase> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(PaymentAppDatabase);
};
} // namespace content
#endif // CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_DATABASE_H_
......@@ -9,24 +9,19 @@
#include "base/bind.h"
#include "base/optional.h"
#include "content/browser/payments/payment_app.pb.h"
#include "content/browser/payments/payment_app_context.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";
} // namespace
PaymentAppManager::~PaymentAppManager() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
}
PaymentAppManager::PaymentAppManager(
PaymentAppContext* payment_app_context,
PaymentAppContextImpl* payment_app_context,
mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request)
: payment_app_context_(payment_app_context),
binding_(this, std::move(request)),
......@@ -39,10 +34,6 @@ PaymentAppManager::PaymentAppManager(
base::Unretained(this)));
}
void PaymentAppManager::OnConnectionError() {
payment_app_context_->ServiceHadConnectionError(this);
}
void PaymentAppManager::SetManifest(
const std::string& scope,
payments::mojom::PaymentAppManifestPtr manifest,
......@@ -52,128 +43,20 @@ void PaymentAppManager::SetManifest(
// 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));
payment_app_context_->payment_app_database()->WriteManifest(
GURL(scope), std::move(manifest), callback);
}
void PaymentAppManager::GetManifest(const std::string& scope,
const GetManifestCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
payment_app_context_->service_worker_context()
->FindReadyRegistrationForPattern(
GURL(scope),
base::Bind(&PaymentAppManager::DidFindRegistrationToGetManifest,
weak_ptr_factory_.GetWeakPtr(), callback));
}
void PaymentAppManager::DidFindRegistrationToSetManifest(
payments::mojom::PaymentAppManifestPtr manifest,
const SetManifestCallback& 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;
}
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);
}
}
std::string serialized;
bool success = manifest_proto.SerializeToString(&serialized);
DCHECK(success);
payment_app_context_->service_worker_context()->StoreRegistrationUserData(
registration->id(), registration->pattern().GetOrigin(),
{{kPaymentAppManifestDataKey, serialized}},
base::Bind(&PaymentAppManager::DidSetManifest,
weak_ptr_factory_.GetWeakPtr(), callback));
payment_app_context_->payment_app_database()->ReadManifest(GURL(scope),
callback);
}
void PaymentAppManager::DidSetManifest(const SetManifestCallback& 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 PaymentAppManager::DidFindRegistrationToGetManifest(
const GetManifestCallback& 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;
}
payment_app_context_->service_worker_context()->GetRegistrationUserData(
registration->id(), {kPaymentAppManifestDataKey},
base::Bind(&PaymentAppManager::DidGetManifest,
weak_ptr_factory_.GetWeakPtr(), callback));
}
void PaymentAppManager::DidGetManifest(const GetManifestCallback& 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;
}
PaymentAppManifestProto manifest_proto;
bool success = manifest_proto.ParseFromString(data[0]);
if (!success) {
callback.Run(payments::mojom::PaymentAppManifest::New(),
payments::mojom::PaymentAppManifestError::
MANIFEST_STORAGE_OPERATION_FAILED);
return;
}
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));
}
callback.Run(std::move(manifest),
payments::mojom::PaymentAppManifestError::NONE);
void PaymentAppManager::OnConnectionError() {
payment_app_context_->ServiceHadConnectionError(this);
}
} // namespace content
......@@ -11,19 +11,17 @@
#include "base/memory/weak_ptr.h"
#include "components/payments/payment_app.mojom.h"
#include "content/common/content_export.h"
#include "content/common/service_worker/service_worker_status_code.h"
#include "mojo/public/cpp/bindings/binding.h"
namespace content {
class PaymentAppContext;
class ServiceWorkerRegistration;
class PaymentAppContextImpl;
class CONTENT_EXPORT PaymentAppManager
: public NON_EXPORTED_BASE(payments::mojom::PaymentAppManager) {
public:
PaymentAppManager(
PaymentAppContext* payment_app_context,
PaymentAppContextImpl* payment_app_context,
mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request);
~PaymentAppManager() override;
......@@ -38,29 +36,11 @@ class CONTENT_EXPORT PaymentAppManager
void GetManifest(const std::string& scope,
const GetManifestCallback& callback) override;
// SetManifest callbacks
void DidFindRegistrationToSetManifest(
payments::mojom::PaymentAppManifestPtr manifest,
const SetManifestCallback& callback,
ServiceWorkerStatusCode status,
scoped_refptr<ServiceWorkerRegistration> registration);
void DidSetManifest(const SetManifestCallback& callback,
ServiceWorkerStatusCode status);
// GetManifest callbacks
void DidFindRegistrationToGetManifest(
const GetManifestCallback& callback,
ServiceWorkerStatusCode status,
scoped_refptr<ServiceWorkerRegistration> registration);
void DidGetManifest(const GetManifestCallback& callback,
const std::vector<std::string>& data,
ServiceWorkerStatusCode status);
// Called when an error is detected on binding_.
void OnConnectionError();
// PaymentAppContext owns PaymentAppManager
PaymentAppContext* payment_app_context_;
// PaymentAppContextImpl owns PaymentAppManager
PaymentAppContextImpl* payment_app_context_;
mojo::Binding<payments::mojom::PaymentAppManager> binding_;
......
......@@ -62,12 +62,11 @@ class PaymentAppManagerTest : public testing::Test {
embedded_worker_helper_->browser_context(), base::FilePath(),
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr)) {
embedded_worker_helper_->context_wrapper()->set_storage_partition(
storage_partition_impl_.get());
payment_app_context_ =
new PaymentAppContext(embedded_worker_helper_->context_wrapper());
payment_app_context_ = new PaymentAppContextImpl();
payment_app_context_->Init(embedded_worker_helper_->context_wrapper());
bool called = false;
embedded_worker_helper_->context()->RegisterServiceWorker(
......@@ -109,7 +108,7 @@ class PaymentAppManagerTest : public testing::Test {
std::unique_ptr<EmbeddedWorkerTestHelper> embedded_worker_helper_;
std::unique_ptr<StoragePartitionImpl> storage_partition_impl_;
int64_t sw_registration_id_;
scoped_refptr<PaymentAppContext> payment_app_context_;
scoped_refptr<PaymentAppContextImpl> payment_app_context_;
payments::mojom::PaymentAppManagerPtr service_;
// Owned by payment_app_context_.
......
......@@ -1209,7 +1209,7 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() {
AddUIThreadInterface(
registry.get(),
base::Bind(&PaymentAppContext::CreateService,
base::Bind(&PaymentAppContextImpl::CreateService,
base::Unretained(
storage_partition_impl_->GetPaymentAppContext())));
......
......@@ -375,7 +375,7 @@ StoragePartitionImpl::StoragePartitionImpl(
HostZoomLevelContext* host_zoom_level_context,
PlatformNotificationContextImpl* platform_notification_context,
BackgroundSyncContext* background_sync_context,
PaymentAppContext* payment_app_context,
PaymentAppContextImpl* payment_app_context,
scoped_refptr<BroadcastChannelProvider> broadcast_channel_provider)
: partition_path_(partition_path),
quota_manager_(quota_manager),
......@@ -515,8 +515,9 @@ std::unique_ptr<StoragePartitionImpl> StoragePartitionImpl::Create(
new BackgroundSyncContext();
background_sync_context->Init(service_worker_context);
scoped_refptr<PaymentAppContext> payment_app_context =
new PaymentAppContext(service_worker_context);
scoped_refptr<PaymentAppContextImpl> payment_app_context =
new PaymentAppContextImpl();
payment_app_context->Init(service_worker_context);
scoped_refptr<BroadcastChannelProvider>
broadcast_channel_provider = new BroadcastChannelProvider();
......@@ -605,7 +606,7 @@ BackgroundSyncContext* StoragePartitionImpl::GetBackgroundSyncContext() {
return background_sync_context_.get();
}
PaymentAppContext* StoragePartitionImpl::GetPaymentAppContext() {
PaymentAppContextImpl* StoragePartitionImpl::GetPaymentAppContext() {
return payment_app_context_.get();
}
......
......@@ -22,7 +22,7 @@
#include "content/browser/host_zoom_level_context.h"
#include "content/browser/indexed_db/indexed_db_context_impl.h"
#include "content/browser/notifications/platform_notification_context_impl.h"
#include "content/browser/payments/payment_app_context.h"
#include "content/browser/payments/payment_app_context_impl.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/common/content_export.h"
#include "content/common/storage_partition_service.mojom.h"
......@@ -75,7 +75,7 @@ class CONTENT_EXPORT StoragePartitionImpl
PlatformNotificationContextImpl* GetPlatformNotificationContext() override;
BackgroundSyncContext* GetBackgroundSyncContext();
PaymentAppContext* GetPaymentAppContext();
PaymentAppContextImpl* GetPaymentAppContext();
BroadcastChannelProvider* GetBroadcastChannelProvider();
// mojom::StoragePartitionService interface.
......@@ -180,7 +180,7 @@ class CONTENT_EXPORT StoragePartitionImpl
HostZoomLevelContext* host_zoom_level_context,
PlatformNotificationContextImpl* platform_notification_context,
BackgroundSyncContext* background_sync_context,
PaymentAppContext* payment_app_context,
PaymentAppContextImpl* payment_app_context,
scoped_refptr<BroadcastChannelProvider>broadcast_channel_provider);
// We will never have both remove_origin be populated and a cookie_matcher.
......@@ -226,7 +226,7 @@ class CONTENT_EXPORT StoragePartitionImpl
scoped_refptr<HostZoomLevelContext> host_zoom_level_context_;
scoped_refptr<PlatformNotificationContextImpl> platform_notification_context_;
scoped_refptr<BackgroundSyncContext> background_sync_context_;
scoped_refptr<PaymentAppContext> payment_app_context_;
scoped_refptr<PaymentAppContextImpl> payment_app_context_;
scoped_refptr<BroadcastChannelProvider> broadcast_channel_provider_;
mojo::BindingSet<mojom::StoragePartitionService> bindings_;
......
// 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.
#ifndef CONTENT_PUBLIC_BROWSER_PAYMENT_APP_CONTEXT_H_
#define CONTENT_PUBLIC_BROWSER_PAYMENT_APP_CONTEXT_H_
#include <utility>
#include <vector>
#include "base/callback_forward.h"
namespace content {
class PaymentAppContext {
public:
// The ManifestWithID is a pair of the service worker registration id and
// the payment app manifest data associated with it.
using ManifestWithID =
std::pair<int64_t, payments::mojom::PaymentAppManifestPtr>;
using Manifests = std::vector<ManifestWithID>;
using GetAllManifestsCallback = base::Callback<void(Manifests)>;
virtual void GetAllManifests(const GetAllManifestsCallback& callback) = 0;
};
} // namespace content
#endif // CONTENT_PUBLIC_BROWSER_PAYMENT_APP_CONTEXT_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment