Index: components/payments/content/payment_manifest_parser_host.h |
diff --git a/components/payments/content/android/payment_manifest_parser_android.h b/components/payments/content/payment_manifest_parser_host.h |
similarity index 35% |
copy from components/payments/content/android/payment_manifest_parser_android.h |
copy to components/payments/content/payment_manifest_parser_host.h |
index 0b6250af74a27a514a2c4e4463280f749b5d4e8a..be95d8e4d9fbc4fd15dbc7a3af402c046b9a091b 100644 |
--- a/components/payments/content/android/payment_manifest_parser_android.h |
+++ b/components/payments/content/payment_manifest_parser_host.h |
@@ -2,18 +2,15 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#ifndef COMPONENTS_PAYMENTS_CONTENT_ANDROID_PAYMENT_MANIFEST_PARSER_ANDROID_H_ |
-#define COMPONENTS_PAYMENTS_CONTENT_ANDROID_PAYMENT_MANIFEST_PARSER_ANDROID_H_ |
- |
-#include <jni.h> |
+#ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_MANIFEST_PARSER_HOST_H_ |
+#define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_MANIFEST_PARSER_HOST_H_ |
#include <memory> |
#include <vector> |
-#include "base/android/jni_android.h" |
-#include "base/android/scoped_java_ref.h" |
+#include "base/callback_forward.h" |
#include "base/macros.h" |
-#include "components/payments/content/android/payment_manifest_parser.mojom.h" |
+#include "components/payments/content/payment_manifest_parser.mojom.h" |
namespace content { |
template <class MojoInterface> |
@@ -23,30 +20,28 @@ class UtilityProcessMojoClient; |
namespace payments { |
// Host of the utility process that parses manifest contents. |
-class PaymentManifestParserAndroid { |
+class PaymentManifestParserHost { |
public: |
- PaymentManifestParserAndroid(); |
- ~PaymentManifestParserAndroid(); |
+ // Called on successful parsing. The result is a move-only vector, which is |
+ // empty on parse failure. |
+ using Callback = |
+ base::OnceCallback<void(std::vector<mojom::PaymentManifestSectionPtr>)>; |
- void StartUtilityProcess(JNIEnv* env, |
- const base::android::JavaParamRef<jobject>& jcaller); |
+ PaymentManifestParserHost(); |
- void ParsePaymentManifest( |
- JNIEnv* env, |
- const base::android::JavaParamRef<jobject>& jcaller, |
- const base::android::JavaParamRef<jstring>& jcontent, |
- const base::android::JavaParamRef<jobject>& jcallback); |
+ // Stops the utility process. |
+ ~PaymentManifestParserHost(); |
- // Deletes this object. |
- void StopUtilityProcess(JNIEnv* env, |
- const base::android::JavaParamRef<jobject>& jcaller); |
+ // Starts the utility process. This can take up to 2 seconds and should be |
+ // done as soon as it is known that the parser will be needed. |
+ void StartUtilityProcess(); |
- private: |
- class ParseCallback; |
+ void ParsePaymentManifest(const std::string& content, Callback callback); |
- // The |callback_identifier| parameter is a pointer to one of the owned |
- // elements in the |pending_callbacks_| list. |
- void OnParse(ParseCallback* callback_identifier, |
+ private: |
+ // The |callback_identifier| parameter is a pointer to one of the items in the |
+ // |pending_callbacks_| list. |
+ void OnParse(const Callback* callback_identifier, |
std::vector<mojom::PaymentManifestSectionPtr> manifest); |
void OnUtilityProcessStopped(); |
@@ -54,13 +49,12 @@ class PaymentManifestParserAndroid { |
std::unique_ptr< |
content::UtilityProcessMojoClient<mojom::PaymentManifestParser>> |
mojo_client_; |
- std::vector<std::unique_ptr<ParseCallback>> pending_callbacks_; |
- DISALLOW_COPY_AND_ASSIGN(PaymentManifestParserAndroid); |
-}; |
+ std::vector<Callback> pending_callbacks_; |
-bool RegisterPaymentManifestParser(JNIEnv* env); |
+ DISALLOW_COPY_AND_ASSIGN(PaymentManifestParserHost); |
+}; |
} // namespace payments |
-#endif // COMPONENTS_PAYMENTS_CONTENT_ANDROID_PAYMENT_MANIFEST_PARSER_ANDROID_H_ |
+#endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_MANIFEST_PARSER_HOST_H_ |