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

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

Issue 2958333002: [Payments] Implement web payment app manifest (Closed)
Patch Set: Created 3 years, 5 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_DATABASE_H_ 5 #ifndef CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_DATABASE_H_
6 #define CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_DATABASE_H_ 6 #define CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_DATABASE_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "content/browser/payments/payment_app_info_fetcher.h"
14 #include "content/browser/payments/payment_instrument_icon_fetcher.h" 15 #include "content/browser/payments/payment_instrument_icon_fetcher.h"
15 #include "content/browser/service_worker/service_worker_context_wrapper.h" 16 #include "content/browser/service_worker/service_worker_context_wrapper.h"
16 #include "content/browser/service_worker/service_worker_registration.h" 17 #include "content/browser/service_worker/service_worker_registration.h"
17 #include "content/common/content_export.h" 18 #include "content/common/content_export.h"
18 #include "content/common/service_worker/service_worker_status_code.h" 19 #include "content/common/service_worker/service_worker_status_code.h"
19 #include "content/public/browser/stored_payment_instrument.h" 20 #include "content/public/browser/stored_payment_app.h"
20 #include "mojo/public/cpp/bindings/binding.h" 21 #include "mojo/public/cpp/bindings/binding.h"
21 #include "third_party/WebKit/public/platform/modules/payments/payment_app.mojom. h" 22 #include "third_party/WebKit/public/platform/modules/payments/payment_app.mojom. h"
22 23
23 namespace content { 24 namespace content {
24 25
25 class ServiceWorkerRegistration; 26 class ServiceWorkerRegistration;
26 27
27 class CONTENT_EXPORT PaymentAppDatabase { 28 class CONTENT_EXPORT PaymentAppDatabase {
28 public: 29 public:
29 using Instruments = std::vector<std::unique_ptr<StoredPaymentInstrument>>; 30 using PaymentApps = std::map<GURL, std::unique_ptr<StoredPaymentApp>>;
30 using PaymentApps = std::map<GURL, Instruments>;
31 using ReadAllPaymentAppsCallback = base::OnceCallback<void(PaymentApps)>; 31 using ReadAllPaymentAppsCallback = base::OnceCallback<void(PaymentApps)>;
32 32
33 using DeletePaymentInstrumentCallback = 33 using DeletePaymentInstrumentCallback =
34 base::OnceCallback<void(payments::mojom::PaymentHandlerStatus)>; 34 base::OnceCallback<void(payments::mojom::PaymentHandlerStatus)>;
35 using ReadPaymentInstrumentCallback = 35 using ReadPaymentInstrumentCallback =
36 base::OnceCallback<void(payments::mojom::PaymentInstrumentPtr, 36 base::OnceCallback<void(payments::mojom::PaymentInstrumentPtr,
37 payments::mojom::PaymentHandlerStatus)>; 37 payments::mojom::PaymentHandlerStatus)>;
38 using KeysOfPaymentInstrumentsCallback = 38 using KeysOfPaymentInstrumentsCallback =
39 base::OnceCallback<void(const std::vector<std::string>&, 39 base::OnceCallback<void(const std::vector<std::string>&,
40 payments::mojom::PaymentHandlerStatus)>; 40 payments::mojom::PaymentHandlerStatus)>;
41 using HasPaymentInstrumentCallback = 41 using HasPaymentInstrumentCallback =
42 base::OnceCallback<void(payments::mojom::PaymentHandlerStatus)>; 42 base::OnceCallback<void(payments::mojom::PaymentHandlerStatus)>;
43 using WritePaymentInstrumentCallback = 43 using WritePaymentInstrumentCallback =
44 base::OnceCallback<void(payments::mojom::PaymentHandlerStatus)>; 44 base::OnceCallback<void(payments::mojom::PaymentHandlerStatus)>;
45 using FetchAndWritePaymentAppInfoCallback =
46 base::OnceCallback<void(payments::mojom::PaymentHandlerStatus)>;
45 using ClearPaymentInstrumentsCallback = 47 using ClearPaymentInstrumentsCallback =
46 base::OnceCallback<void(payments::mojom::PaymentHandlerStatus)>; 48 base::OnceCallback<void(payments::mojom::PaymentHandlerStatus)>;
47 49
48 explicit PaymentAppDatabase( 50 explicit PaymentAppDatabase(
49 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context); 51 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context);
50 ~PaymentAppDatabase(); 52 ~PaymentAppDatabase();
51 53
52 void ReadAllPaymentApps(ReadAllPaymentAppsCallback callback); 54 void ReadAllPaymentApps(ReadAllPaymentAppsCallback callback);
53 55
54 void DeletePaymentInstrument(const GURL& scope, 56 void DeletePaymentInstrument(const GURL& scope,
55 const std::string& instrument_key, 57 const std::string& instrument_key,
56 DeletePaymentInstrumentCallback callback); 58 DeletePaymentInstrumentCallback callback);
57 void ReadPaymentInstrument(const GURL& scope, 59 void ReadPaymentInstrument(const GURL& scope,
58 const std::string& instrument_key, 60 const std::string& instrument_key,
59 ReadPaymentInstrumentCallback callback); 61 ReadPaymentInstrumentCallback callback);
60 void KeysOfPaymentInstruments(const GURL& scope, 62 void KeysOfPaymentInstruments(const GURL& scope,
61 KeysOfPaymentInstrumentsCallback callback); 63 KeysOfPaymentInstrumentsCallback callback);
62 void HasPaymentInstrument(const GURL& scope, 64 void HasPaymentInstrument(const GURL& scope,
63 const std::string& instrument_key, 65 const std::string& instrument_key,
64 HasPaymentInstrumentCallback callback); 66 HasPaymentInstrumentCallback callback);
65 void WritePaymentInstrument(const GURL& scope, 67 void WritePaymentInstrument(const GURL& scope,
66 const std::string& instrument_key, 68 const std::string& instrument_key,
67 payments::mojom::PaymentInstrumentPtr instrument, 69 payments::mojom::PaymentInstrumentPtr instrument,
68 WritePaymentInstrumentCallback callback); 70 WritePaymentInstrumentCallback callback);
71 void FetchAndWritePaymentAppInfo(
72 const GURL& context,
73 const GURL& scope,
74 FetchAndWritePaymentAppInfoCallback callback);
69 void ClearPaymentInstruments(const GURL& scope, 75 void ClearPaymentInstruments(const GURL& scope,
70 ClearPaymentInstrumentsCallback callback); 76 ClearPaymentInstrumentsCallback callback);
71 77
72 private: 78 private:
79 friend class PaymentAppContentUnitTestBase;
80 void SetSkipPaymentAppInfoFetchForTest();
81 bool skip_payment_app_info_fetch_for_test_;
82
73 // ReadAllPaymentApps callbacks 83 // ReadAllPaymentApps callbacks
74 void DidReadAllPaymentApps( 84 void DidReadAllPaymentApps(
75 ReadAllPaymentAppsCallback callback, 85 ReadAllPaymentAppsCallback callback,
76 const std::vector<std::pair<int64_t, std::string>>& raw_data, 86 const std::vector<std::pair<int64_t, std::string>>& raw_data,
77 ServiceWorkerStatusCode status); 87 ServiceWorkerStatusCode status);
88 void DidReadAllPaymentInstruments(
89 PaymentApps apps,
90 ReadAllPaymentAppsCallback callback,
91 const std::vector<std::pair<int64_t, std::string>>& raw_data,
92 ServiceWorkerStatusCode status);
78 93
79 // DeletePaymentInstrument callbacks 94 // DeletePaymentInstrument callbacks
80 void DidFindRegistrationToDeletePaymentInstrument( 95 void DidFindRegistrationToDeletePaymentInstrument(
81 const std::string& instrument_key, 96 const std::string& instrument_key,
82 DeletePaymentInstrumentCallback callback, 97 DeletePaymentInstrumentCallback callback,
83 ServiceWorkerStatusCode status, 98 ServiceWorkerStatusCode status,
84 scoped_refptr<ServiceWorkerRegistration> registration); 99 scoped_refptr<ServiceWorkerRegistration> registration);
85 void DidFindPaymentInstrument(int64_t registration_id, 100 void DidFindPaymentInstrument(int64_t registration_id,
86 const std::string& instrument_key, 101 const std::string& instrument_key,
87 DeletePaymentInstrumentCallback callback, 102 DeletePaymentInstrumentCallback callback,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 void DidFindRegistrationToWritePaymentInstrument( 138 void DidFindRegistrationToWritePaymentInstrument(
124 const std::string& instrument_key, 139 const std::string& instrument_key,
125 payments::mojom::PaymentInstrumentPtr instrument, 140 payments::mojom::PaymentInstrumentPtr instrument,
126 const std::string& decoded_instrument_icon, 141 const std::string& decoded_instrument_icon,
127 WritePaymentInstrumentCallback callback, 142 WritePaymentInstrumentCallback callback,
128 ServiceWorkerStatusCode status, 143 ServiceWorkerStatusCode status,
129 scoped_refptr<ServiceWorkerRegistration> registration); 144 scoped_refptr<ServiceWorkerRegistration> registration);
130 void DidWritePaymentInstrument(WritePaymentInstrumentCallback callback, 145 void DidWritePaymentInstrument(WritePaymentInstrumentCallback callback,
131 ServiceWorkerStatusCode status); 146 ServiceWorkerStatusCode status);
132 147
148 // FetchAndWritePaymentAppInfo callbacks.
149 void FetchPaymentAppInfoCallback(const GURL& scope,
150 FetchAndWritePaymentAppInfoCallback callback,
151 const std::string& name,
152 const std::string& icon);
153 void DidFindRegistrationToWritePaymentAppInfo(
154 FetchAndWritePaymentAppInfoCallback callback,
155 const std::string& name,
156 const std::string& icon,
157 ServiceWorkerStatusCode status,
158 scoped_refptr<ServiceWorkerRegistration> registration);
159 void DidWritePaymentApp(FetchAndWritePaymentAppInfoCallback callback,
160 ServiceWorkerStatusCode status);
161
133 // PaymentInstrumentIconFetcherCallback. 162 // PaymentInstrumentIconFetcherCallback.
134 void DidFetchedPaymentInstrumentIcon( 163 void DidFetchedPaymentInstrumentIcon(
135 const GURL& scope, 164 const GURL& scope,
136 const std::string& instrument_key, 165 const std::string& instrument_key,
137 payments::mojom::PaymentInstrumentPtr instrument, 166 payments::mojom::PaymentInstrumentPtr instrument,
138 WritePaymentInstrumentCallback callback, 167 WritePaymentInstrumentCallback callback,
139 const std::string& icon); 168 const std::string& icon);
140 169
141 // ClearPaymentInstruments callbacks 170 // ClearPaymentInstruments callbacks
142 void DidFindRegistrationToClearPaymentInstruments( 171 void DidFindRegistrationToClearPaymentInstruments(
143 const GURL& scope, 172 const GURL& scope,
144 ClearPaymentInstrumentsCallback callback, 173 ClearPaymentInstrumentsCallback callback,
145 ServiceWorkerStatusCode status, 174 ServiceWorkerStatusCode status,
146 scoped_refptr<ServiceWorkerRegistration> registration); 175 scoped_refptr<ServiceWorkerRegistration> registration);
147 void DidGetKeysToClearPaymentInstruments( 176 void DidGetKeysToClearPaymentInstruments(
148 int64_t registration_id, 177 scoped_refptr<ServiceWorkerRegistration> registration,
149 ClearPaymentInstrumentsCallback callback, 178 ClearPaymentInstrumentsCallback callback,
150 const std::vector<std::string>& keys, 179 const std::vector<std::string>& keys,
151 payments::mojom::PaymentHandlerStatus status); 180 payments::mojom::PaymentHandlerStatus status);
152 void DidClearPaymentInstruments(ClearPaymentInstrumentsCallback callback, 181 void DidClearPaymentInstruments(ClearPaymentInstrumentsCallback callback,
153 ServiceWorkerStatusCode status); 182 ServiceWorkerStatusCode status);
154 183
184 scoped_refptr<PaymentAppInfoFetcher> payment_app_info_fetcher_;
155 scoped_refptr<PaymentInstrumentIconFetcher> instrument_icon_fetcher_; 185 scoped_refptr<PaymentInstrumentIconFetcher> instrument_icon_fetcher_;
156 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; 186 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
157 base::WeakPtrFactory<PaymentAppDatabase> weak_ptr_factory_; 187 base::WeakPtrFactory<PaymentAppDatabase> weak_ptr_factory_;
158 188
159 DISALLOW_COPY_AND_ASSIGN(PaymentAppDatabase); 189 DISALLOW_COPY_AND_ASSIGN(PaymentAppDatabase);
160 }; 190 };
161 191
162 } // namespace content 192 } // namespace content
163 193
164 #endif // CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_DATABASE_H_ 194 #endif // CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698