OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_CONTEXT_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_CONTEXT_IMPL_H_ |
6 #define CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_CONTEXT_IMPL_H_ | 6 #define CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_CONTEXT_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "components/payments/payment_app.mojom.h" | 13 #include "components/payments/payment_app.mojom.h" |
| 14 #include "content/browser/payments/payment_app_database.h" |
14 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
15 #include "content/public/browser/payment_app_context.h" | 16 #include "content/public/browser/payment_app_context.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 | 19 |
19 class PaymentAppManager; | 20 class PaymentAppManager; |
20 class ServiceWorkerContextWrapper; | 21 class ServiceWorkerContextWrapper; |
21 | 22 |
22 class CONTENT_EXPORT PaymentAppContextImpl | 23 class CONTENT_EXPORT PaymentAppContextImpl |
23 : NON_EXPORTED_BASE(public PaymentAppContext), | 24 : NON_EXPORTED_BASE(public PaymentAppContext), |
24 public base::RefCountedThreadSafe<PaymentAppContextImpl> { | 25 public base::RefCountedThreadSafe<PaymentAppContextImpl> { |
25 public: | 26 public: |
26 explicit PaymentAppContextImpl( | 27 PaymentAppContextImpl(); |
27 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context); | 28 |
| 29 // Init and Shutdown are for use on the UI thread when the |
| 30 // StoragePartition is being setup and torn down. |
| 31 void Init(scoped_refptr<ServiceWorkerContextWrapper> service_worker_context); |
28 | 32 |
29 // Shutdown must be called before deleting this. Call on the UI thread. | 33 // Shutdown must be called before deleting this. Call on the UI thread. |
30 void Shutdown(); | 34 void Shutdown(); |
31 | 35 |
32 // Create a PaymentAppManager that is owned by this. Call on the UI | 36 // Create a PaymentAppManager that is owned by this. Call on the UI |
33 // thread. | 37 // thread. |
34 void CreateService( | 38 void CreateService( |
35 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request); | 39 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request); |
36 | 40 |
37 // Called by PaymentAppManager objects so that they can | 41 // Called by PaymentAppManager objects so that they can |
38 // be deleted. Call on the IO thread. | 42 // be deleted. Call on the IO thread. |
39 void ServiceHadConnectionError(PaymentAppManager* service); | 43 void ServiceHadConnectionError(PaymentAppManager* service); |
40 | 44 |
41 ServiceWorkerContextWrapper* service_worker_context() const; | 45 PaymentAppDatabase* payment_app_database() const; |
42 | 46 |
43 void GetAllManifests(const GetAllManifestsCallback& callback) override; | 47 void GetAllManifests(const GetAllManifestsCallback& callback) override; |
44 | 48 |
45 protected: | 49 protected: |
46 friend class base::RefCountedThreadSafe<PaymentAppContextImpl>; | 50 friend class base::RefCountedThreadSafe<PaymentAppContextImpl>; |
47 friend class PaymentAppManagerTest; | 51 friend class PaymentAppManagerTest; |
48 virtual ~PaymentAppContextImpl(); | 52 virtual ~PaymentAppContextImpl(); |
49 | 53 |
50 private: | 54 private: |
| 55 void CreatePaymentAppDatabaseOnIO( |
| 56 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context); |
| 57 |
51 void CreateServiceOnIOThread( | 58 void CreateServiceOnIOThread( |
52 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request); | 59 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request); |
53 | 60 |
54 void ShutdownOnIO(); | 61 void ShutdownOnIO(); |
55 | 62 |
56 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | 63 // Only accessed on the IO thread. |
| 64 std::unique_ptr<PaymentAppDatabase> payment_app_database_; |
57 | 65 |
58 // The services are owned by this. They're either deleted | 66 // The services are owned by this. They're either deleted |
59 // during ShutdownOnIO or when the channel is closed via | 67 // during ShutdownOnIO or when the channel is closed via |
60 // ServiceHadConnectionError. Only accessed on the IO thread. | 68 // ServiceHadConnectionError. Only accessed on the IO thread. |
61 std::map<PaymentAppManager*, std::unique_ptr<PaymentAppManager>> services_; | 69 std::map<PaymentAppManager*, std::unique_ptr<PaymentAppManager>> services_; |
62 | 70 |
63 DISALLOW_COPY_AND_ASSIGN(PaymentAppContextImpl); | 71 DISALLOW_COPY_AND_ASSIGN(PaymentAppContextImpl); |
64 }; | 72 }; |
65 | 73 |
66 } // namespace content | 74 } // namespace content |
67 | 75 |
68 #endif // CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_CONTEXT_IMPL_H_ | 76 #endif // CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_CONTEXT_IMPL_H_ |
OLD | NEW |