| 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 "components/payments/mojom/payment_app.mojom.h" | 14 #include "components/payments/mojom/payment_app.mojom.h" |
| 15 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 15 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 16 #include "content/browser/service_worker/service_worker_registration.h" | 16 #include "content/browser/service_worker/service_worker_registration.h" |
| 17 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
| 18 #include "content/common/service_worker/service_worker_status_code.h" | 18 #include "content/common/service_worker/service_worker_status_code.h" |
| 19 #include "content/public/browser/stored_payment_instrument.h" | 19 #include "content/public/browser/stored_payment_instrument.h" |
| 20 #include "mojo/public/cpp/bindings/binding.h" | 20 #include "mojo/public/cpp/bindings/binding.h" |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 | 23 |
| 24 class ServiceWorkerRegistration; | 24 class ServiceWorkerRegistration; |
| 25 | 25 |
| 26 class CONTENT_EXPORT PaymentAppDatabase { | 26 class CONTENT_EXPORT PaymentAppDatabase { |
| 27 public: | 27 public: |
| 28 using WriteManifestCallback = | |
| 29 base::OnceCallback<void(payments::mojom::PaymentAppManifestError)>; | |
| 30 using ReadManifestCallback = | |
| 31 base::OnceCallback<void(payments::mojom::PaymentAppManifestPtr, | |
| 32 payments::mojom::PaymentAppManifestError)>; | |
| 33 using ManifestWithID = | |
| 34 std::pair<int64_t, payments::mojom::PaymentAppManifestPtr>; | |
| 35 using Manifests = std::vector<ManifestWithID>; | |
| 36 using ReadAllManifestsCallback = base::OnceCallback<void(Manifests)>; | |
| 37 | |
| 38 using Instruments = std::vector<std::unique_ptr<StoredPaymentInstrument>>; | 28 using Instruments = std::vector<std::unique_ptr<StoredPaymentInstrument>>; |
| 39 using PaymentApps = std::map<GURL, Instruments>; | 29 using PaymentApps = std::map<GURL, Instruments>; |
| 40 using ReadAllPaymentAppsCallback = base::OnceCallback<void(PaymentApps)>; | 30 using ReadAllPaymentAppsCallback = base::OnceCallback<void(PaymentApps)>; |
| 41 | 31 |
| 42 using DeletePaymentInstrumentCallback = | 32 using DeletePaymentInstrumentCallback = |
| 43 base::OnceCallback<void(payments::mojom::PaymentHandlerStatus)>; | 33 base::OnceCallback<void(payments::mojom::PaymentHandlerStatus)>; |
| 44 using ReadPaymentInstrumentCallback = | 34 using ReadPaymentInstrumentCallback = |
| 45 base::OnceCallback<void(payments::mojom::PaymentInstrumentPtr, | 35 base::OnceCallback<void(payments::mojom::PaymentInstrumentPtr, |
| 46 payments::mojom::PaymentHandlerStatus)>; | 36 payments::mojom::PaymentHandlerStatus)>; |
| 47 using KeysOfPaymentInstrumentsCallback = | 37 using KeysOfPaymentInstrumentsCallback = |
| 48 base::OnceCallback<void(const std::vector<std::string>&, | 38 base::OnceCallback<void(const std::vector<std::string>&, |
| 49 payments::mojom::PaymentHandlerStatus)>; | 39 payments::mojom::PaymentHandlerStatus)>; |
| 50 using HasPaymentInstrumentCallback = | 40 using HasPaymentInstrumentCallback = |
| 51 base::OnceCallback<void(payments::mojom::PaymentHandlerStatus)>; | 41 base::OnceCallback<void(payments::mojom::PaymentHandlerStatus)>; |
| 52 using WritePaymentInstrumentCallback = | 42 using WritePaymentInstrumentCallback = |
| 53 base::OnceCallback<void(payments::mojom::PaymentHandlerStatus)>; | 43 base::OnceCallback<void(payments::mojom::PaymentHandlerStatus)>; |
| 54 using ClearPaymentInstrumentsCallback = | 44 using ClearPaymentInstrumentsCallback = |
| 55 base::OnceCallback<void(payments::mojom::PaymentHandlerStatus)>; | 45 base::OnceCallback<void(payments::mojom::PaymentHandlerStatus)>; |
| 56 | 46 |
| 57 explicit PaymentAppDatabase( | 47 explicit PaymentAppDatabase( |
| 58 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context); | 48 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context); |
| 59 ~PaymentAppDatabase(); | 49 ~PaymentAppDatabase(); |
| 60 | 50 |
| 61 void WriteManifest(const GURL& scope, | |
| 62 payments::mojom::PaymentAppManifestPtr manifest, | |
| 63 WriteManifestCallback callback); | |
| 64 void ReadManifest(const GURL& scope, ReadManifestCallback callback); | |
| 65 void ReadAllManifests(ReadAllManifestsCallback callback); | |
| 66 | |
| 67 void ReadAllPaymentApps(ReadAllPaymentAppsCallback callback); | 51 void ReadAllPaymentApps(ReadAllPaymentAppsCallback callback); |
| 68 | 52 |
| 69 void DeletePaymentInstrument(const GURL& scope, | 53 void DeletePaymentInstrument(const GURL& scope, |
| 70 const std::string& instrument_key, | 54 const std::string& instrument_key, |
| 71 DeletePaymentInstrumentCallback callback); | 55 DeletePaymentInstrumentCallback callback); |
| 72 void ReadPaymentInstrument(const GURL& scope, | 56 void ReadPaymentInstrument(const GURL& scope, |
| 73 const std::string& instrument_key, | 57 const std::string& instrument_key, |
| 74 ReadPaymentInstrumentCallback callback); | 58 ReadPaymentInstrumentCallback callback); |
| 75 void KeysOfPaymentInstruments(const GURL& scope, | 59 void KeysOfPaymentInstruments(const GURL& scope, |
| 76 KeysOfPaymentInstrumentsCallback callback); | 60 KeysOfPaymentInstrumentsCallback callback); |
| 77 void HasPaymentInstrument(const GURL& scope, | 61 void HasPaymentInstrument(const GURL& scope, |
| 78 const std::string& instrument_key, | 62 const std::string& instrument_key, |
| 79 HasPaymentInstrumentCallback callback); | 63 HasPaymentInstrumentCallback callback); |
| 80 void WritePaymentInstrument(const GURL& scope, | 64 void WritePaymentInstrument(const GURL& scope, |
| 81 const std::string& instrument_key, | 65 const std::string& instrument_key, |
| 82 payments::mojom::PaymentInstrumentPtr instrument, | 66 payments::mojom::PaymentInstrumentPtr instrument, |
| 83 WritePaymentInstrumentCallback callback); | 67 WritePaymentInstrumentCallback callback); |
| 84 void ClearPaymentInstruments(const GURL& scope, | 68 void ClearPaymentInstruments(const GURL& scope, |
| 85 ClearPaymentInstrumentsCallback callback); | 69 ClearPaymentInstrumentsCallback callback); |
| 86 | 70 |
| 87 private: | 71 private: |
| 88 // WriteManifest callbacks | |
| 89 void DidFindRegistrationToWriteManifest( | |
| 90 payments::mojom::PaymentAppManifestPtr manifest, | |
| 91 WriteManifestCallback callback, | |
| 92 ServiceWorkerStatusCode status, | |
| 93 scoped_refptr<ServiceWorkerRegistration> registration); | |
| 94 void DidWriteManifest(WriteManifestCallback callback, | |
| 95 ServiceWorkerStatusCode status); | |
| 96 | |
| 97 // ReadManifest callbacks | |
| 98 void DidFindRegistrationToReadManifest( | |
| 99 ReadManifestCallback callback, | |
| 100 ServiceWorkerStatusCode status, | |
| 101 scoped_refptr<ServiceWorkerRegistration> registration); | |
| 102 void DidReadManifest(ReadManifestCallback callback, | |
| 103 const std::vector<std::string>& data, | |
| 104 ServiceWorkerStatusCode status); | |
| 105 | |
| 106 // ReadAllManifests callbacks | |
| 107 void DidReadAllManifests( | |
| 108 ReadAllManifestsCallback callback, | |
| 109 const std::vector<std::pair<int64_t, std::string>>& raw_data, | |
| 110 ServiceWorkerStatusCode status); | |
| 111 | |
| 112 // ReadAllPaymentApps callbacks | 72 // ReadAllPaymentApps callbacks |
| 113 void DidReadAllPaymentApps( | 73 void DidReadAllPaymentApps( |
| 114 ReadAllPaymentAppsCallback callback, | 74 ReadAllPaymentAppsCallback callback, |
| 115 const std::vector<std::pair<int64_t, std::string>>& raw_data, | 75 const std::vector<std::pair<int64_t, std::string>>& raw_data, |
| 116 ServiceWorkerStatusCode status); | 76 ServiceWorkerStatusCode status); |
| 117 | 77 |
| 118 // DeletePaymentInstrument callbacks | 78 // DeletePaymentInstrument callbacks |
| 119 void DidFindRegistrationToDeletePaymentInstrument( | 79 void DidFindRegistrationToDeletePaymentInstrument( |
| 120 const std::string& instrument_key, | 80 const std::string& instrument_key, |
| 121 DeletePaymentInstrumentCallback callback, | 81 DeletePaymentInstrumentCallback callback, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 146 |
| 187 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | 147 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
| 188 base::WeakPtrFactory<PaymentAppDatabase> weak_ptr_factory_; | 148 base::WeakPtrFactory<PaymentAppDatabase> weak_ptr_factory_; |
| 189 | 149 |
| 190 DISALLOW_COPY_AND_ASSIGN(PaymentAppDatabase); | 150 DISALLOW_COPY_AND_ASSIGN(PaymentAppDatabase); |
| 191 }; | 151 }; |
| 192 | 152 |
| 193 } // namespace content | 153 } // namespace content |
| 194 | 154 |
| 195 #endif // CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_DATABASE_H_ | 155 #endif // CONTENT_BROWSER_PAYMENTS_PAYMENT_APP_DATABASE_H_ |
| OLD | NEW |