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_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: |
73 // ReadAllPaymentApps callbacks | 79 // ReadAllPaymentApps callbacks |
74 void DidReadAllPaymentApps( | 80 void DidReadAllPaymentApps( |
75 ReadAllPaymentAppsCallback callback, | 81 ReadAllPaymentAppsCallback callback, |
76 const std::vector<std::pair<int64_t, std::string>>& raw_data, | 82 const std::vector<std::pair<int64_t, std::string>>& raw_data, |
77 ServiceWorkerStatusCode status); | 83 ServiceWorkerStatusCode status); |
| 84 void DidReadAllPaymentInstruments( |
| 85 PaymentApps apps, |
| 86 ReadAllPaymentAppsCallback callback, |
| 87 const std::vector<std::pair<int64_t, std::string>>& raw_data, |
| 88 ServiceWorkerStatusCode status); |
78 | 89 |
79 // DeletePaymentInstrument callbacks | 90 // DeletePaymentInstrument callbacks |
80 void DidFindRegistrationToDeletePaymentInstrument( | 91 void DidFindRegistrationToDeletePaymentInstrument( |
81 const std::string& instrument_key, | 92 const std::string& instrument_key, |
82 DeletePaymentInstrumentCallback callback, | 93 DeletePaymentInstrumentCallback callback, |
83 ServiceWorkerStatusCode status, | 94 ServiceWorkerStatusCode status, |
84 scoped_refptr<ServiceWorkerRegistration> registration); | 95 scoped_refptr<ServiceWorkerRegistration> registration); |
85 void DidFindPaymentInstrument(int64_t registration_id, | 96 void DidFindPaymentInstrument(int64_t registration_id, |
86 const std::string& instrument_key, | 97 const std::string& instrument_key, |
87 DeletePaymentInstrumentCallback callback, | 98 DeletePaymentInstrumentCallback callback, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 void DidFindRegistrationToWritePaymentInstrument( | 134 void DidFindRegistrationToWritePaymentInstrument( |
124 const std::string& instrument_key, | 135 const std::string& instrument_key, |
125 payments::mojom::PaymentInstrumentPtr instrument, | 136 payments::mojom::PaymentInstrumentPtr instrument, |
126 const std::string& decoded_instrument_icon, | 137 const std::string& decoded_instrument_icon, |
127 WritePaymentInstrumentCallback callback, | 138 WritePaymentInstrumentCallback callback, |
128 ServiceWorkerStatusCode status, | 139 ServiceWorkerStatusCode status, |
129 scoped_refptr<ServiceWorkerRegistration> registration); | 140 scoped_refptr<ServiceWorkerRegistration> registration); |
130 void DidWritePaymentInstrument(WritePaymentInstrumentCallback callback, | 141 void DidWritePaymentInstrument(WritePaymentInstrumentCallback callback, |
131 ServiceWorkerStatusCode status); | 142 ServiceWorkerStatusCode status); |
132 | 143 |
| 144 // FetchAndWritePaymentAppInfo callbacks. |
| 145 void FetchPaymentAppInfoCallback(const GURL& scope, |
| 146 FetchAndWritePaymentAppInfoCallback callback, |
| 147 const std::string& name, |
| 148 const std::string& icon); |
| 149 void DidFindRegistrationToWritePaymentAppInfo( |
| 150 FetchAndWritePaymentAppInfoCallback callback, |
| 151 const std::string& name, |
| 152 const std::string& icon, |
| 153 ServiceWorkerStatusCode status, |
| 154 scoped_refptr<ServiceWorkerRegistration> registration); |
| 155 void DidWritePaymentApp(FetchAndWritePaymentAppInfoCallback callback, |
| 156 bool fetch_app_info_failed, |
| 157 ServiceWorkerStatusCode status); |
| 158 |
133 // PaymentInstrumentIconFetcherCallback. | 159 // PaymentInstrumentIconFetcherCallback. |
134 void DidFetchedPaymentInstrumentIcon( | 160 void DidFetchedPaymentInstrumentIcon( |
135 const GURL& scope, | 161 const GURL& scope, |
136 const std::string& instrument_key, | 162 const std::string& instrument_key, |
137 payments::mojom::PaymentInstrumentPtr instrument, | 163 payments::mojom::PaymentInstrumentPtr instrument, |
138 WritePaymentInstrumentCallback callback, | 164 WritePaymentInstrumentCallback callback, |
139 const std::string& icon); | 165 const std::string& icon); |
140 | 166 |
141 // ClearPaymentInstruments callbacks | 167 // ClearPaymentInstruments callbacks |
142 void DidFindRegistrationToClearPaymentInstruments( | 168 void DidFindRegistrationToClearPaymentInstruments( |
143 const GURL& scope, | 169 const GURL& scope, |
144 ClearPaymentInstrumentsCallback callback, | 170 ClearPaymentInstrumentsCallback callback, |
145 ServiceWorkerStatusCode status, | 171 ServiceWorkerStatusCode status, |
146 scoped_refptr<ServiceWorkerRegistration> registration); | 172 scoped_refptr<ServiceWorkerRegistration> registration); |
147 void DidGetKeysToClearPaymentInstruments( | 173 void DidGetKeysToClearPaymentInstruments( |
148 int64_t registration_id, | 174 scoped_refptr<ServiceWorkerRegistration> registration, |
149 ClearPaymentInstrumentsCallback callback, | 175 ClearPaymentInstrumentsCallback callback, |
150 const std::vector<std::string>& keys, | 176 const std::vector<std::string>& keys, |
151 payments::mojom::PaymentHandlerStatus status); | 177 payments::mojom::PaymentHandlerStatus status); |
152 void DidClearPaymentInstruments(ClearPaymentInstrumentsCallback callback, | 178 void DidClearPaymentInstruments(ClearPaymentInstrumentsCallback callback, |
153 ServiceWorkerStatusCode status); | 179 ServiceWorkerStatusCode status); |
154 | 180 |
| 181 scoped_refptr<PaymentAppInfoFetcher> payment_app_info_fetcher_; |
155 scoped_refptr<PaymentInstrumentIconFetcher> instrument_icon_fetcher_; | 182 scoped_refptr<PaymentInstrumentIconFetcher> instrument_icon_fetcher_; |
156 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | 183 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
157 base::WeakPtrFactory<PaymentAppDatabase> weak_ptr_factory_; | 184 base::WeakPtrFactory<PaymentAppDatabase> weak_ptr_factory_; |
158 | 185 |
159 DISALLOW_COPY_AND_ASSIGN(PaymentAppDatabase); | 186 DISALLOW_COPY_AND_ASSIGN(PaymentAppDatabase); |
160 }; | 187 }; |
161 | 188 |
162 } // namespace content | 189 } // namespace content |
163 | 190 |
164 #endif // CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_DATABASE_H_ | 191 #endif // CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_DATABASE_H_ |
OLD | NEW |