Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors |
vasilii | e4e2b2b1 | 2016-12-12 13:47:27 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
jinho.bang | 745d987b | 2016-12-14 19:06:54 | [diff] [blame] | 5 | #ifndef CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_CONTEXT_IMPL_H_ |
| 6 | #define CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_CONTEXT_IMPL_H_ |
vasilii | e4e2b2b1 | 2016-12-12 13:47:27 | [diff] [blame] | 7 | |
| 8 | #include <map> |
| 9 | #include <memory> |
| 10 | |
Hans Wennborg | f30ad80 | 2020-06-20 16:50:20 | [diff] [blame] | 11 | #include "base/check_op.h" |
vasilii | e4e2b2b1 | 2016-12-12 13:47:27 | [diff] [blame] | 12 | #include "base/memory/ref_counted.h" |
Francois Doray | 5a6eb20 | 2018-02-23 19:19:35 | [diff] [blame] | 13 | #include "base/synchronization/atomic_flag.h" |
jinho.bang | e7f7d131 | 2016-12-19 20:45:00 | [diff] [blame] | 14 | #include "content/browser/payments/payment_app_database.h" |
vasilii | e4e2b2b1 | 2016-12-12 13:47:27 | [diff] [blame] | 15 | #include "content/common/content_export.h" |
Francois Doray | 5a6eb20 | 2018-02-23 19:19:35 | [diff] [blame] | 16 | #include "content/public/browser/browser_thread.h" |
Miyoung Shin | f661d57 | 2019-09-04 11:58:27 | [diff] [blame] | 17 | #include "mojo/public/cpp/bindings/pending_receiver.h" |
Han Leon | abbe7c90 | 2018-08-30 02:08:10 | [diff] [blame] | 18 | #include "third_party/blink/public/mojom/payments/payment_app.mojom.h" |
vasilii | e4e2b2b1 | 2016-12-12 13:47:27 | [diff] [blame] | 19 | |
| 20 | namespace content { |
| 21 | |
jinho.bang | ab43057 | 2016-12-16 14:33:58 | [diff] [blame] | 22 | class PaymentAppDatabase; |
jinho.bang | bbb00c3 | 2017-03-30 15:09:09 | [diff] [blame] | 23 | class PaymentManager; |
vasilii | e4e2b2b1 | 2016-12-12 13:47:27 | [diff] [blame] | 24 | class ServiceWorkerContextWrapper; |
| 25 | |
jinho.bang | ab43057 | 2016-12-16 14:33:58 | [diff] [blame] | 26 | // One instance of this exists per StoragePartition, and services multiple child |
| 27 | // processes/origins. Most logic is delegated to the owned PaymentAppDatabase |
Matt Falkenhagen | 016104e | 2021-09-10 01:01:33 | [diff] [blame] | 28 | // instance. |
jinho.bang | ab43057 | 2016-12-16 14:33:58 | [diff] [blame] | 29 | // |
Matt Falkenhagen | 016104e | 2021-09-10 01:01:33 | [diff] [blame] | 30 | // This class is created by StoragePartitionImpl. It lives on the UI thread. |
jinho.bang | 745d987b | 2016-12-14 19:06:54 | [diff] [blame] | 31 | class CONTENT_EXPORT PaymentAppContextImpl |
Matt Falkenhagen | 016104e | 2021-09-10 01:01:33 | [diff] [blame] | 32 | : public base::RefCounted<PaymentAppContextImpl> { |
vasilii | e4e2b2b1 | 2016-12-12 13:47:27 | [diff] [blame] | 33 | public: |
jinho.bang | ab43057 | 2016-12-16 14:33:58 | [diff] [blame] | 34 | PaymentAppContextImpl(); |
| 35 | |
Peter Boström | 9b03653 | 2021-10-28 23:37:28 | [diff] [blame] | 36 | PaymentAppContextImpl(const PaymentAppContextImpl&) = delete; |
| 37 | PaymentAppContextImpl& operator=(const PaymentAppContextImpl&) = delete; |
| 38 | |
Matt Falkenhagen | 016104e | 2021-09-10 01:01:33 | [diff] [blame] | 39 | // 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.bang | ab43057 | 2016-12-16 14:33:58 | [diff] [blame] | 41 | void Init(scoped_refptr<ServiceWorkerContextWrapper> service_worker_context); |
vasilii | e4e2b2b1 | 2016-12-12 13:47:27 | [diff] [blame] | 42 | |
Matt Falkenhagen | 016104e | 2021-09-10 01:01:33 | [diff] [blame] | 43 | // Creates a PaymentManager that is owned by this. |
Rouslan Solomakhin | 8788e254 | 2019-10-24 01:10:05 | [diff] [blame] | 44 | void CreatePaymentManagerForOrigin( |
| 45 | const url::Origin& origin, |
Miyoung Shin | f661d57 | 2019-09-04 11:58:27 | [diff] [blame] | 46 | mojo::PendingReceiver<payments::mojom::PaymentManager> receiver); |
vasilii | e4e2b2b1 | 2016-12-12 13:47:27 | [diff] [blame] | 47 | |
Matt Falkenhagen | 016104e | 2021-09-10 01:01:33 | [diff] [blame] | 48 | // Called by PaymentManager objects so that they can be deleted. |
jinho.bang | bbb00c3 | 2017-03-30 15:09:09 | [diff] [blame] | 49 | void PaymentManagerHadConnectionError(PaymentManager* service); |
vasilii | e4e2b2b1 | 2016-12-12 13:47:27 | [diff] [blame] | 50 | |
jinho.bang | ab43057 | 2016-12-16 14:33:58 | [diff] [blame] | 51 | PaymentAppDatabase* payment_app_database() const; |
vasilii | e4e2b2b1 | 2016-12-12 13:47:27 | [diff] [blame] | 52 | |
vasilii | e4e2b2b1 | 2016-12-12 13:47:27 | [diff] [blame] | 53 | private: |
jinho.bang | e7f7d131 | 2016-12-19 20:45:00 | [diff] [blame] | 54 | friend class PaymentAppContentUnitTestBase; |
Matt Falkenhagen | 016104e | 2021-09-10 01:01:33 | [diff] [blame] | 55 | friend class base::RefCounted<PaymentAppContextImpl>; |
jinho.bang | ac34b3a3 | 2017-01-05 12:51:21 | [diff] [blame] | 56 | ~PaymentAppContextImpl(); |
jinho.bang | 745d987b | 2016-12-14 19:06:54 | [diff] [blame] | 57 | |
jinho.bang | ab43057 | 2016-12-16 14:33:58 | [diff] [blame] | 58 | std::unique_ptr<PaymentAppDatabase> payment_app_database_; |
vasilii | e4e2b2b1 | 2016-12-12 13:47:27 | [diff] [blame] | 59 | |
Matt Falkenhagen | 016104e | 2021-09-10 01:01:33 | [diff] [blame] | 60 | // The PaymentManagers are owned by this. They're either deleted in the |
| 61 | // destructor or when the channel is closed via |
| 62 | // PaymentManagerHadConnectionError. |
jinho.bang | bbb00c3 | 2017-03-30 15:09:09 | [diff] [blame] | 63 | std::map<PaymentManager*, std::unique_ptr<PaymentManager>> payment_managers_; |
vasilii | e4e2b2b1 | 2016-12-12 13:47:27 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | } // namespace content |
| 67 | |
jinho.bang | 745d987b | 2016-12-14 19:06:54 | [diff] [blame] | 68 | #endif // CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_CONTEXT_IMPL_H_ |