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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
// 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.
#include "components/payments/content/android/journey_logger_android.h"
#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
#include "content/public/browser/web_contents.h"
// Must come after all headers that specialize FromJniType() / ToJniType().
#include "components/payments/content/android/jni_headers/JourneyLogger_jni.h"
namespace payments {
namespace {
using ::base::android::ConvertJavaStringToUTF8;
using ::base::android::JavaParamRef;
using base::android::JavaRef;
} // namespace
JourneyLoggerAndroid::JourneyLoggerAndroid(ukm::SourceId source_id)
: journey_logger_(source_id) {}
JourneyLoggerAndroid::~JourneyLoggerAndroid() = default;
void JourneyLoggerAndroid::Destroy(JNIEnv* env,
const JavaParamRef<jobject>& jcaller) {
delete this;
}
void JourneyLoggerAndroid::SetNumberOfSuggestionsShown(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller,
jint jsection,
jint jnumber,
jboolean jhas_complete_suggestion) {
DCHECK_GE(jsection, 0);
DCHECK_LT(jsection, JourneyLogger::Section::SECTION_MAX);
journey_logger_.SetNumberOfSuggestionsShown(
static_cast<JourneyLogger::Section>(jsection), jnumber,
jhas_complete_suggestion);
}
void JourneyLoggerAndroid::SetOptOutOffered(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller) {
journey_logger_.SetOptOutOffered();
}
void JourneyLoggerAndroid::SetActivationlessShow(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller) {
journey_logger_.SetActivationlessShow();
}
void JourneyLoggerAndroid::SetSkippedShow(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller) {
journey_logger_.SetSkippedShow();
}
void JourneyLoggerAndroid::SetShown(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller) {
journey_logger_.SetShown();
}
void JourneyLoggerAndroid::SetPayClicked(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller) {
journey_logger_.SetPayClicked();
}
void JourneyLoggerAndroid::SetSelectedMethod(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller,
jint jPaymentMethodCategory) {
DCHECK_GE(jPaymentMethodCategory, 0);
DCHECK_LE(static_cast<unsigned int>(jPaymentMethodCategory),
static_cast<unsigned int>(
JourneyLogger::PaymentMethodCategory::kMaxValue));
journey_logger_.SetSelectedMethod(
static_cast<JourneyLogger::PaymentMethodCategory>(
jPaymentMethodCategory));
}
void JourneyLoggerAndroid::SetRequestedInformation(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller,
jboolean requested_shipping,
jboolean requested_email,
jboolean requested_phone,
jboolean requested_name) {
journey_logger_.SetRequestedInformation(requested_shipping, requested_email,
requested_phone, requested_name);
}
void JourneyLoggerAndroid::SetRequestedPaymentMethods(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller,
const base::android::JavaParamRef<jintArray>& jmethods) {
std::vector<int> int_methods;
base::android::JavaIntArrayToIntVector(env, jmethods, &int_methods);
std::vector<JourneyLogger::PaymentMethodCategory> method_categories;
for (auto& int_method : int_methods) {
method_categories.push_back(
static_cast<JourneyLogger::PaymentMethodCategory>(int_method));
}
journey_logger_.SetRequestedPaymentMethods(method_categories);
}
void JourneyLoggerAndroid::SetCompleted(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller) {
journey_logger_.SetCompleted();
}
void JourneyLoggerAndroid::SetAborted(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller,
jint jreason) {
DCHECK_GE(jreason, 0);
DCHECK_LT(jreason, JourneyLogger::AbortReason::ABORT_REASON_MAX);
journey_logger_.SetAborted(static_cast<JourneyLogger::AbortReason>(jreason));
}
void JourneyLoggerAndroid::SetNotShown(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller) {
journey_logger_.SetNotShown();
}
void JourneyLoggerAndroid::SetNoMatchingCredentialsShown(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller) {
journey_logger_.SetNoMatchingCredentialsShown();
}
void JourneyLoggerAndroid::RecordCheckoutStep(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller,
jint jstep) {
journey_logger_.RecordCheckoutStep(
static_cast<JourneyLogger::CheckoutFunnelStep>(jstep));
}
void JourneyLoggerAndroid::SetPaymentAppUkmSourceId(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller,
ukm::SourceId source_id) {
journey_logger_.SetPaymentAppUkmSourceId(source_id);
}
static jlong JNI_JourneyLogger_InitJourneyLoggerAndroid(
JNIEnv* env,
const JavaParamRef<jobject>& jcaller,
const JavaParamRef<jobject>& jweb_contents) {
content::WebContents* web_contents =
content::WebContents::FromJavaWebContents(jweb_contents);
DCHECK(web_contents); // Verified in Java before invoking this function.
return reinterpret_cast<jlong>(new JourneyLoggerAndroid(
web_contents->GetPrimaryMainFrame()->GetPageUkmSourceId()));
}
} // namespace payments
|