| Index: content/browser/payments/payment_app_context_impl.cc
|
| diff --git a/content/browser/payments/payment_app_context_impl.cc b/content/browser/payments/payment_app_context_impl.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..715de170a4c5d9af6d8f4e5059e210d71fee7cfc
|
| --- /dev/null
|
| +++ b/content/browser/payments/payment_app_context_impl.cc
|
| @@ -0,0 +1,113 @@
|
| +// 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_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_data_conversions.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 {
|
| +
|
| +PaymentAppContextImpl::PaymentAppContextImpl(
|
| + scoped_refptr<ServiceWorkerContextWrapper> service_worker_context)
|
| + : service_worker_context_(std::move(service_worker_context)),
|
| + weak_ptr_factory_(this) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| +}
|
| +
|
| +PaymentAppContextImpl::~PaymentAppContextImpl() {
|
| + DCHECK(services_.empty());
|
| +}
|
| +
|
| +void PaymentAppContextImpl::Shutdown() {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| +
|
| + BrowserThread::PostTask(
|
| + BrowserThread::IO, FROM_HERE,
|
| + base::Bind(&PaymentAppContextImpl::ShutdownOnIO, this));
|
| +}
|
| +
|
| +void PaymentAppContextImpl::CreateService(
|
| + mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| +
|
| + BrowserThread::PostTask(
|
| + BrowserThread::IO, FROM_HERE,
|
| + base::Bind(&PaymentAppContextImpl::CreateServiceOnIOThread, this,
|
| + base::Passed(&request)));
|
| +}
|
| +
|
| +void PaymentAppContextImpl::ServiceHadConnectionError(
|
| + PaymentAppManager* service) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + DCHECK(base::ContainsKey(services_, service));
|
| +
|
| + services_.erase(service);
|
| +}
|
| +
|
| +ServiceWorkerContextWrapper* PaymentAppContextImpl::service_worker_context()
|
| + const {
|
| + return service_worker_context_.get();
|
| +}
|
| +
|
| +void PaymentAppContextImpl::GetAllManifests(
|
| + const GetAllManifestsCallback& callback) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + BrowserThread::PostTask(
|
| + BrowserThread::IO, FROM_HERE,
|
| + base::Bind(&PaymentAppContextImpl::GetAllManifestsOnIO, this, callback));
|
| +}
|
| +
|
| +void PaymentAppContextImpl::GetAllManifestsOnIO(const GetAllManifestsCallback& callback) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + service_worker_context_->GetUserDataForAllRegistrations("PaymentAppManifestData", base::Bind(&PaymentAppContextImpl::DidGetAllManifests, this, callback));
|
| +}
|
| +
|
| +void PaymentAppContextImpl::DidGetAllManifests(
|
| + const GetAllManifestsCallback& callback,
|
| + const std::vector<std::pair<int64_t, std::string>>& raw_data,
|
| + ServiceWorkerStatusCode status) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| +
|
| + std::vector<PaymentAppContext::PaymentAppManifestWithID> manifests;
|
| + for (auto& payment_app_raw_data : raw_data) {
|
| + payments::mojom::PaymentAppManifestPtr manifest =
|
| + payments::mojom::PaymentAppManifest::New();
|
| + if (!DeserializePaymentAppManifest(payment_app_raw_data.second, manifest)) {
|
| + continue;
|
| + }
|
| + manifests.push_back(PaymentAppContext::PaymentAppManifestWithID(payment_app_raw_data.first, std::move(manifest)));
|
| + }
|
| +
|
| + BrowserThread::PostTask(
|
| + BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&PaymentAppContextImpl::GetAll, this, callback));
|
| +}
|
| +
|
| +void PaymentAppContextImpl::GetAll(
|
| + const GetAllManifestsCallback& callback) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| +}
|
| +
|
| +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 PaymentAppContextImpl::ShutdownOnIO() {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| +
|
| + services_.clear();
|
| +}
|
| +
|
| +} // namespace content
|
|
|