File: web_payments_web_data_service_android.h

package info (click to toggle)
chromium 142.0.7444.175-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,295,352 kB
  • sloc: cpp: 35,488,378; ansic: 7,479,680; javascript: 4,259,373; python: 1,466,843; xml: 757,444; asm: 710,716; pascal: 187,980; sh: 89,247; perl: 88,690; objc: 79,984; sql: 56,984; cs: 42,192; fortran: 24,137; makefile: 22,913; tcl: 15,277; php: 14,018; yacc: 9,005; ruby: 7,553; awk: 3,720; lisp: 3,096; lex: 1,330; ada: 727; jsp: 228; sed: 36
file content (99 lines) | stat: -rw-r--r-- 3,704 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2017 The Chromium Authors
// 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_WEB_PAYMENTS_WEB_DATA_SERVICE_ANDROID_H_
#define COMPONENTS_PAYMENTS_CONTENT_ANDROID_WEB_PAYMENTS_WEB_DATA_SERVICE_ANDROID_H_

#include <map>
#include <memory>

#include "base/android/jni_weak_ref.h"
#include "base/android/scoped_java_ref.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "components/payments/content/web_payments_web_data_service.h"
#include "components/webdata/common/web_data_results.h"
#include "components/webdata/common/web_data_service_base.h"
#include "components/webdata/common/web_data_service_consumer.h"

namespace content {
class WebContents;
}

namespace payments {

// Android wrapper of the WebPaymentsWebDataService which provides access
// from the Java layer.
class WebPaymentsWebDataServiceAndroid {
 public:
  WebPaymentsWebDataServiceAndroid(JNIEnv* env,
                                   const jni_zero::JavaRef<jobject>& obj,
                                   content::WebContents* web_contents);

  WebPaymentsWebDataServiceAndroid(const WebPaymentsWebDataServiceAndroid&) =
      delete;
  WebPaymentsWebDataServiceAndroid& operator=(
      const WebPaymentsWebDataServiceAndroid&) = delete;

  ~WebPaymentsWebDataServiceAndroid();

  // Destroys this object.
  void Destroy(JNIEnv* env);

  // Adds the supported |japp_package_names| of the |jmethod_name| to the
  // cache.
  void AddPaymentMethodManifest(
      JNIEnv* env,
      const base::android::JavaParamRef<jstring>& jmethod_name,
      const base::android::JavaParamRef<jobjectArray>& japp_package_names);

  // Adds the web app |jmanifest_sections|.
  void AddPaymentWebAppManifest(
      JNIEnv* env,
      const base::android::JavaParamRef<jobjectArray>& jmanifest_sections);

  // Gets the payment |jmethod_name|'s manifest asynchronously from the web data
  // service. Return true if the result will be returned through |jcallback|.
  bool GetPaymentMethodManifest(
      JNIEnv* env,
      const base::android::JavaParamRef<jstring>& jmethod_name,
      const base::android::JavaParamRef<jobject>& jcallback);

  // Gets the payment |japp_package_name|'s manifest asynchronously from the web
  // data service. Return true if the result will be returned through
  // |jcallback|.
  bool GetPaymentWebAppManifest(
      JNIEnv* env,
      const base::android::JavaParamRef<jstring>& japp_package_name,
      const base::android::JavaParamRef<jobject>& jcallback);

 private:
  void OnWebDataServiceRequestDone(WebDataServiceBase::Handle h,
                                   std::unique_ptr<WDTypedResult> result);
  void OnWebAppManifestRequestDone(JNIEnv* env,
                                   WebDataServiceBase::Handle h,
                                   std::unique_ptr<WDTypedResult> result);
  void OnPaymentMethodManifestRequestDone(
      JNIEnv* env,
      WebDataServiceBase::Handle h,
      std::unique_ptr<WDTypedResult> result);
  scoped_refptr<WebPaymentsWebDataService> GetWebPaymentsWebDataService();

  base::WeakPtr<content::WebContents> web_contents_;

  // Pointer to the java counterpart.
  JavaObjectWeakGlobalRef weak_java_obj_;

  // Map of request handle and its correspond callback.
  std::map<WebDataServiceBase::Handle,
           std::unique_ptr<base::android::ScopedJavaGlobalRef<jobject>>>
      web_data_service_requests_;

  base::WeakPtrFactory<WebPaymentsWebDataServiceAndroid> weak_ptr_factory_{
      this};
};

}  // namespace payments

#endif  // COMPONENTS_PAYMENTS_CONTENT_ANDROID_WEB_PAYMENTS_WEB_DATA_SERVICE_ANDROID_H_