| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 COMPONENTS_PAYMENTS_CONTENT_ANDROID_PAYMENT_MANIFEST_PARSER_ANDROID_H_ | 5 #ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_MANIFEST_PARSER_HOST_H_ |
| 6 #define COMPONENTS_PAYMENTS_CONTENT_ANDROID_PAYMENT_MANIFEST_PARSER_ANDROID_H_ | 6 #define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_MANIFEST_PARSER_HOST_H_ |
| 7 | |
| 8 #include <jni.h> | |
| 9 | 7 |
| 10 #include <memory> | 8 #include <memory> |
| 11 #include <vector> | 9 #include <vector> |
| 12 | 10 |
| 13 #include "base/android/jni_android.h" | 11 #include "base/callback_forward.h" |
| 14 #include "base/android/scoped_java_ref.h" | |
| 15 #include "base/macros.h" | 12 #include "base/macros.h" |
| 16 #include "components/payments/content/android/payment_manifest_parser.mojom.h" | 13 #include "components/payments/content/payment_manifest_parser.mojom.h" |
| 17 | 14 |
| 18 namespace content { | 15 namespace content { |
| 19 template <class MojoInterface> | 16 template <class MojoInterface> |
| 20 class UtilityProcessMojoClient; | 17 class UtilityProcessMojoClient; |
| 21 } | 18 } |
| 22 | 19 |
| 23 namespace payments { | 20 namespace payments { |
| 24 | 21 |
| 25 // Host of the utility process that parses manifest contents. | 22 // Host of the utility process that parses manifest contents. |
| 26 class PaymentManifestParserAndroid { | 23 class PaymentManifestParserHost { |
| 27 public: | 24 public: |
| 28 PaymentManifestParserAndroid(); | 25 // Called on successful parsing. The result is a move-only vector, which is |
| 29 ~PaymentManifestParserAndroid(); | 26 // empty on parse failure. |
| 27 using Callback = |
| 28 base::OnceCallback<void(std::vector<mojom::PaymentManifestSectionPtr>)>; |
| 30 | 29 |
| 31 void StartUtilityProcess(JNIEnv* env, | 30 PaymentManifestParserHost(); |
| 32 const base::android::JavaParamRef<jobject>& jcaller); | |
| 33 | 31 |
| 34 void ParsePaymentManifest( | 32 // Stops the utility process. |
| 35 JNIEnv* env, | 33 ~PaymentManifestParserHost(); |
| 36 const base::android::JavaParamRef<jobject>& jcaller, | |
| 37 const base::android::JavaParamRef<jstring>& jcontent, | |
| 38 const base::android::JavaParamRef<jobject>& jcallback); | |
| 39 | 34 |
| 40 // Deletes this object. | 35 // Starts the utility process. This can take up to 2 seconds and should be |
| 41 void StopUtilityProcess(JNIEnv* env, | 36 // done as soon as it is known that the parser will be needed. |
| 42 const base::android::JavaParamRef<jobject>& jcaller); | 37 void StartUtilityProcess(); |
| 38 |
| 39 void ParsePaymentManifest(const std::string& content, Callback callback); |
| 43 | 40 |
| 44 private: | 41 private: |
| 45 class ParseCallback; | 42 // The |callback_identifier| parameter is a pointer to one of the items in the |
| 46 | 43 // |pending_callbacks_| list. |
| 47 // The |callback_identifier| parameter is a pointer to one of the owned | 44 void OnParse(const Callback* callback_identifier, |
| 48 // elements in the |pending_callbacks_| list. | |
| 49 void OnParse(ParseCallback* callback_identifier, | |
| 50 std::vector<mojom::PaymentManifestSectionPtr> manifest); | 45 std::vector<mojom::PaymentManifestSectionPtr> manifest); |
| 51 | 46 |
| 52 void OnUtilityProcessStopped(); | 47 void OnUtilityProcessStopped(); |
| 53 | 48 |
| 54 std::unique_ptr< | 49 std::unique_ptr< |
| 55 content::UtilityProcessMojoClient<mojom::PaymentManifestParser>> | 50 content::UtilityProcessMojoClient<mojom::PaymentManifestParser>> |
| 56 mojo_client_; | 51 mojo_client_; |
| 57 std::vector<std::unique_ptr<ParseCallback>> pending_callbacks_; | |
| 58 | 52 |
| 59 DISALLOW_COPY_AND_ASSIGN(PaymentManifestParserAndroid); | 53 std::vector<Callback> pending_callbacks_; |
| 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(PaymentManifestParserHost); |
| 60 }; | 56 }; |
| 61 | 57 |
| 62 bool RegisterPaymentManifestParser(JNIEnv* env); | |
| 63 | |
| 64 } // namespace payments | 58 } // namespace payments |
| 65 | 59 |
| 66 #endif // COMPONENTS_PAYMENTS_CONTENT_ANDROID_PAYMENT_MANIFEST_PARSER_ANDROID_H
_ | 60 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_MANIFEST_PARSER_HOST_H_ |
| OLD | NEW |