blob: 80324c596f32b1c194d9e3d61e1d63e748c199b7 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2016 The Chromium Authors
vasiliie4e2b2b12016-12-12 13:47:272// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
jinho.bang745d987b2016-12-14 19:06:545#ifndef CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_CONTEXT_IMPL_H_
6#define CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_CONTEXT_IMPL_H_
vasiliie4e2b2b12016-12-12 13:47:277
8#include <map>
9#include <memory>
10
Hans Wennborgf30ad802020-06-20 16:50:2011#include "base/check_op.h"
vasiliie4e2b2b12016-12-12 13:47:2712#include "base/memory/ref_counted.h"
Francois Doray5a6eb202018-02-23 19:19:3513#include "base/synchronization/atomic_flag.h"
jinho.bange7f7d1312016-12-19 20:45:0014#include "content/browser/payments/payment_app_database.h"
vasiliie4e2b2b12016-12-12 13:47:2715#include "content/common/content_export.h"
Francois Doray5a6eb202018-02-23 19:19:3516#include "content/public/browser/browser_thread.h"
Miyoung Shinf661d572019-09-04 11:58:2717#include "mojo/public/cpp/bindings/pending_receiver.h"
Han Leonabbe7c902018-08-30 02:08:1018#include "third_party/blink/public/mojom/payments/payment_app.mojom.h"
vasiliie4e2b2b12016-12-12 13:47:2719
20namespace content {
21
jinho.bangab430572016-12-16 14:33:5822class PaymentAppDatabase;
jinho.bangbbb00c32017-03-30 15:09:0923class PaymentManager;
vasiliie4e2b2b12016-12-12 13:47:2724class ServiceWorkerContextWrapper;
25
jinho.bangab430572016-12-16 14:33:5826// One instance of this exists per StoragePartition, and services multiple child
27// processes/origins. Most logic is delegated to the owned PaymentAppDatabase
Matt Falkenhagen016104e2021-09-10 01:01:3328// instance.
jinho.bangab430572016-12-16 14:33:5829//
Matt Falkenhagen016104e2021-09-10 01:01:3330// This class is created by StoragePartitionImpl. It lives on the UI thread.
jinho.bang745d987b2016-12-14 19:06:5431class CONTENT_EXPORT PaymentAppContextImpl
Matt Falkenhagen016104e2021-09-10 01:01:3332 : public base::RefCounted<PaymentAppContextImpl> {
vasiliie4e2b2b12016-12-12 13:47:2733 public:
jinho.bangab430572016-12-16 14:33:5834 PaymentAppContextImpl();
35
Peter Boström9b036532021-10-28 23:37:2836 PaymentAppContextImpl(const PaymentAppContextImpl&) = delete;
37 PaymentAppContextImpl& operator=(const PaymentAppContextImpl&) = delete;
38
Matt Falkenhagen016104e2021-09-10 01:01:3339 // Init() must be called before using this. It is separate from the
40 // constructor for tests that want to inject a `service_worker_context`.
jinho.bangab430572016-12-16 14:33:5841 void Init(scoped_refptr<ServiceWorkerContextWrapper> service_worker_context);
vasiliie4e2b2b12016-12-12 13:47:2742
Matt Falkenhagen016104e2021-09-10 01:01:3343 // Creates a PaymentManager that is owned by this.
Rouslan Solomakhin8788e2542019-10-24 01:10:0544 void CreatePaymentManagerForOrigin(
45 const url::Origin& origin,
Miyoung Shinf661d572019-09-04 11:58:2746 mojo::PendingReceiver<payments::mojom::PaymentManager> receiver);
vasiliie4e2b2b12016-12-12 13:47:2747
Matt Falkenhagen016104e2021-09-10 01:01:3348 // Called by PaymentManager objects so that they can be deleted.
jinho.bangbbb00c32017-03-30 15:09:0949 void PaymentManagerHadConnectionError(PaymentManager* service);
vasiliie4e2b2b12016-12-12 13:47:2750
jinho.bangab430572016-12-16 14:33:5851 PaymentAppDatabase* payment_app_database() const;
vasiliie4e2b2b12016-12-12 13:47:2752
vasiliie4e2b2b12016-12-12 13:47:2753 private:
jinho.bange7f7d1312016-12-19 20:45:0054 friend class PaymentAppContentUnitTestBase;
Matt Falkenhagen016104e2021-09-10 01:01:3355 friend class base::RefCounted<PaymentAppContextImpl>;
jinho.bangac34b3a32017-01-05 12:51:2156 ~PaymentAppContextImpl();
jinho.bang745d987b2016-12-14 19:06:5457
jinho.bangab430572016-12-16 14:33:5858 std::unique_ptr<PaymentAppDatabase> payment_app_database_;
vasiliie4e2b2b12016-12-12 13:47:2759
Matt Falkenhagen016104e2021-09-10 01:01:3360 // The PaymentManagers are owned by this. They're either deleted in the
61 // destructor or when the channel is closed via
62 // PaymentManagerHadConnectionError.
jinho.bangbbb00c32017-03-30 15:09:0963 std::map<PaymentManager*, std::unique_ptr<PaymentManager>> payment_managers_;
vasiliie4e2b2b12016-12-12 13:47:2764};
65
66} // namespace content
67
jinho.bang745d987b2016-12-14 19:06:5468#endif // CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_CONTEXT_IMPL_H_