Chromium Code Reviews| 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(); |
|
Mathieu
2017/03/21 20:18:12
Does this need to be here?
please use gerrit instead
2017/03/21 20:34:51
Where do you propose to put it? This place seems s
| |
| 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. |
|
Mathieu
2017/03/21 20:18:12
Mention that it may have long startup time and sho
please use gerrit instead
2017/03/21 20:34:51
Done.
| |
| 41 void StopUtilityProcess(JNIEnv* env, | 36 void StartUtilityProcess(); |
| 42 const base::android::JavaParamRef<jobject>& jcaller); | 37 |
| 38 void ParsePaymentManifest(const std::string& content, Callback callback); | |
| 43 | 39 |
| 44 private: | 40 private: |
| 45 class ParseCallback; | 41 // The |callback_identifier| parameter is a pointer to one of the items in the |
| 46 | 42 // |pending_callbacks_| list. |
| 47 // The |callback_identifier| parameter is a pointer to one of the owned | 43 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); | 44 std::vector<mojom::PaymentManifestSectionPtr> manifest); |
| 51 | 45 |
| 52 void OnUtilityProcessStopped(); | 46 void OnUtilityProcessStopped(); |
| 53 | 47 |
| 54 std::unique_ptr< | 48 std::unique_ptr< |
| 55 content::UtilityProcessMojoClient<mojom::PaymentManifestParser>> | 49 content::UtilityProcessMojoClient<mojom::PaymentManifestParser>> |
| 56 mojo_client_; | 50 mojo_client_; |
| 57 std::vector<std::unique_ptr<ParseCallback>> pending_callbacks_; | |
| 58 | 51 |
| 59 DISALLOW_COPY_AND_ASSIGN(PaymentManifestParserAndroid); | 52 std::vector<Callback> pending_callbacks_; |
|
Mathieu
2017/03/21 20:18:12
Have you looked into base/callback_list.h?
https:
please use gerrit instead
2017/03/21 20:34:52
CallbackList works with base::Callback, which is c
| |
| 53 | |
| 54 DISALLOW_COPY_AND_ASSIGN(PaymentManifestParserHost); | |
| 60 }; | 55 }; |
| 61 | 56 |
| 62 bool RegisterPaymentManifestParser(JNIEnv* env); | |
| 63 | |
| 64 } // namespace payments | 57 } // namespace payments |
| 65 | 58 |
| 66 #endif // COMPONENTS_PAYMENTS_CONTENT_ANDROID_PAYMENT_MANIFEST_PARSER_ANDROID_H _ | 59 #endif // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_MANIFEST_PARSER_HOST_H_ |
| OLD | NEW |