Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(495)

Side by Side Diff: content/browser/payments/payment_app_context_impl.h

Issue 2609103002: PaymentApp: Add PaymentAppProvider class. (Closed)
Patch Set: PaymentApp: Add PaymentAppProvider class. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/browser/payments/payment_app_database.h"
15 #include "content/common/content_export.h" 15 #include "content/common/content_export.h"
16 #include "content/public/browser/payment_app_context.h"
17 16
18 namespace content { 17 namespace content {
19 18
20 class PaymentAppDatabase; 19 class PaymentAppDatabase;
21 class PaymentAppManager; 20 class PaymentAppManager;
22 class ServiceWorkerContextWrapper; 21 class ServiceWorkerContextWrapper;
23 22
24 // One instance of this exists per StoragePartition, and services multiple child 23 // One instance of this exists per StoragePartition, and services multiple child
25 // processes/origins. Most logic is delegated to the owned PaymentAppDatabase 24 // processes/origins. Most logic is delegated to the owned PaymentAppDatabase
26 // instance, which is only accessed on the IO thread. 25 // instance, which is only accessed on the IO thread.
27 // 26 //
28 // This class is created/destructed by StoragePartitionImpl on UI thread. 27 // This class is created/destructed by StoragePartitionImpl on UI thread.
29 // However, the PaymentAppDatabase that this class has internally should work on 28 // However, the PaymentAppDatabase that this class has internally should work on
30 // IO thread. So, this class has Init() and Shutdown() methods in addition to 29 // IO thread. So, this class has Init() and Shutdown() methods in addition to
31 // constructor and destructor. They should be called explicitly when creating 30 // constructor and destructor. They should be called explicitly when creating
32 // and destroying StoragePartitionImpl. 31 // and destroying StoragePartitionImpl.
33 // 32 //
34 // Expected order of lifetime calls: 33 // Expected order of lifetime calls:
35 // 1) Constructor 34 // 1) Constructor
36 // 2) Init() 35 // 2) Init()
37 // 3) Can now call other public methods in this class in any order. 36 // 3) Can now call other public methods in this class in any order.
38 // - Can call CreatePaymentAppManager() on UI thread. 37 // - Can call CreatePaymentAppManager() on UI thread.
39 // - Can call GetAllManifests() on UI thread. 38 // - Can call GetAllManifests() on UI thread.
40 // - Can call PaymentAppManagerHadConnectionError() on IO thread. 39 // - Can call PaymentAppManagerHadConnectionError() on IO thread.
41 // - Can call payment_app_database() on IO thread. 40 // - Can call payment_app_database() on IO thread.
42 // 4) Shutdown() 41 // 4) Shutdown()
43 // 5) Destructor 42 // 5) Destructor
44 class CONTENT_EXPORT PaymentAppContextImpl 43 class CONTENT_EXPORT PaymentAppContextImpl
45 : public base::RefCountedThreadSafe<PaymentAppContextImpl>, 44 : public base::RefCountedThreadSafe<PaymentAppContextImpl> {
46 NON_EXPORTED_BASE(public PaymentAppContext) {
47 public: 45 public:
48 PaymentAppContextImpl(); 46 PaymentAppContextImpl();
49 47
50 // Init and Shutdown are for use on the UI thread when the 48 // Init and Shutdown are for use on the UI thread when the
51 // StoragePartition is being setup and torn down. 49 // StoragePartition is being setup and torn down.
52 void Init(scoped_refptr<ServiceWorkerContextWrapper> service_worker_context); 50 void Init(scoped_refptr<ServiceWorkerContextWrapper> service_worker_context);
53 51
54 // Shutdown must be called before deleting this. Call on the UI thread. 52 // Shutdown must be called before deleting this. Call on the UI thread.
55 void Shutdown(); 53 void Shutdown();
56 54
57 // Create a PaymentAppManager that is owned by this. Call on the UI 55 // Create a PaymentAppManager that is owned by this. Call on the UI
58 // thread. 56 // thread.
59 void CreatePaymentAppManager( 57 void CreatePaymentAppManager(
60 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request); 58 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request);
61 59
62 // Called by PaymentAppManager objects so that they can 60 // Called by PaymentAppManager objects so that they can
63 // be deleted. Call on the IO thread. 61 // be deleted. Call on the IO thread.
64 void PaymentAppManagerHadConnectionError(PaymentAppManager* service); 62 void PaymentAppManagerHadConnectionError(PaymentAppManager* service);
65 63
66 // Should be accessed only on the IO thread. 64 // Should be accessed only on the IO thread.
67 PaymentAppDatabase* payment_app_database() const; 65 PaymentAppDatabase* payment_app_database() const;
68 66
69 // PaymentAppContext implementation:
70 // Should be accessed only on the UI thread.
71 void GetAllManifests(const GetAllManifestsCallback& callback) override;
72
73 private: 67 private:
74 friend class PaymentAppContentUnitTestBase; 68 friend class PaymentAppContentUnitTestBase;
75 friend class base::RefCountedThreadSafe<PaymentAppContextImpl>; 69 friend class base::RefCountedThreadSafe<PaymentAppContextImpl>;
76 ~PaymentAppContextImpl() override; 70 ~PaymentAppContextImpl();
please use gerrit instead 2017/01/04 16:55:43 base::RefCountedThreadSafe has a destructor, so we
zino 2017/01/04 17:29:59 Done.
zino 2017/01/05 00:08:04 There was no virtual destructor in RefCountedThrea
77 71
78 void CreatePaymentAppDatabaseOnIO( 72 void CreatePaymentAppDatabaseOnIO(
79 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context); 73 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context);
80 74
81 void CreatePaymentAppManagerOnIO( 75 void CreatePaymentAppManagerOnIO(
82 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request); 76 mojo::InterfaceRequest<payments::mojom::PaymentAppManager> request);
83 77
84 void ShutdownOnIO(); 78 void ShutdownOnIO();
85 void DidShutdown(); 79 void DidShutdown();
86 80
87 void GetAllManifestsOnIO(const GetAllManifestsCallback& callback);
88 void DidGetAllManifestsOnIO(const GetAllManifestsCallback& callback,
89 PaymentAppDatabase::Manifests manifests);
90
91 // Only accessed on the IO thread. 81 // Only accessed on the IO thread.
92 std::unique_ptr<PaymentAppDatabase> payment_app_database_; 82 std::unique_ptr<PaymentAppDatabase> payment_app_database_;
93 83
94 // The PaymentAppManagers are owned by this. They're either deleted during 84 // The PaymentAppManagers are owned by this. They're either deleted during
95 // ShutdownOnIO or when the channel is closed via 85 // ShutdownOnIO or when the channel is closed via
96 // PaymentAppManagerHadConnectionError. Only accessed on the IO thread. 86 // PaymentAppManagerHadConnectionError. Only accessed on the IO thread.
97 std::map<PaymentAppManager*, std::unique_ptr<PaymentAppManager>> 87 std::map<PaymentAppManager*, std::unique_ptr<PaymentAppManager>>
98 payment_app_managers_; 88 payment_app_managers_;
99 89
100 // Only accessed on the UI thread. 90 // Only accessed on the UI thread.
101 bool is_shutdown_; 91 bool is_shutdown_;
102 92
103 DISALLOW_COPY_AND_ASSIGN(PaymentAppContextImpl); 93 DISALLOW_COPY_AND_ASSIGN(PaymentAppContextImpl);
104 }; 94 };
105 95
106 } // namespace content 96 } // namespace content
107 97
108 #endif // CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_CONTEXT_IMPL_H_ 98 #endif // CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_CONTEXT_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698