| Index: components/payments/content/android/java/src/org/chromium/components/payments/JourneyLogger.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestJourneyLogger.java b/components/payments/content/android/java/src/org/chromium/components/payments/JourneyLogger.java
|
| similarity index 32%
|
| rename from chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestJourneyLogger.java
|
| rename to components/payments/content/android/java/src/org/chromium/components/payments/JourneyLogger.java
|
| index 1c81eccdeffe7e7f9565c979058859f61082b4f1..e20036076a150e8b1c25c305d1601158b350d3ac 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestJourneyLogger.java
|
| +++ b/components/payments/content/android/java/src/org/chromium/components/payments/JourneyLogger.java
|
| @@ -2,14 +2,17 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -package org.chromium.chrome.browser.payments;
|
| +package org.chromium.components.payments;
|
|
|
| -import org.chromium.base.metrics.RecordHistogram;
|
| +import org.chromium.base.annotations.JNINamespace;
|
|
|
| /**
|
| * A class used to record journey metrics for the Payment Request feature.
|
| */
|
| -public class PaymentRequestJourneyLogger {
|
| +@JNINamespace("payments")
|
| +public class JourneyLogger {
|
| + // Note: The constants should always be in sync with those in the
|
| + // components/payments/core/journey_logger.h file.
|
| // The index of the different sections of a Payment Request. Used to record journey stats.
|
| public static final int SECTION_CONTACT_INFO = 0;
|
| public static final int SECTION_CREDIT_CARDS = 1;
|
| @@ -23,8 +26,9 @@ public class PaymentRequestJourneyLogger {
|
|
|
| // Used to log different parameters' effect on whether the transaction was completed.
|
| public static final int COMPLETION_STATUS_COMPLETED = 0;
|
| - public static final int COMPLETION_STATUS_ABORTED = 1;
|
| - public static final int COMPLETION_STATUS_MAX = 2;
|
| + public static final int COMPLETION_STATUS_USER_ABORTED = 1;
|
| + public static final int COMPLETION_STATUS_OTHER_ABORTED = 2;
|
| + public static final int COMPLETION_STATUS_MAX = 3;
|
|
|
| // Used to mesure the impact of the CanMakePayment return value on whether the Payment Request
|
| // is shown to the user.
|
| @@ -39,24 +43,22 @@ public class PaymentRequestJourneyLogger {
|
| private static final int MAX_EXPECTED_SAMPLE = 49;
|
| private static final int NUMBER_BUCKETS = 50;
|
|
|
| - private static class SectionStats {
|
| - private int mNumberSuggestionsShown;
|
| - private int mNumberSelectionChanges;
|
| - private int mNumberSelectionEdits;
|
| - private int mNumberSelectionAdds;
|
| - private boolean mIsRequested;
|
| - }
|
| -
|
| - private SectionStats[] mSections;
|
| + /**
|
| + * Pointer to the native implementation.
|
| + */
|
| + private long mJourneyLoggerAndroid;
|
|
|
| - private boolean mWasCanMakePaymentUsed;
|
| - private boolean mCouldMakePayment;
|
| - private boolean mWasShowCalled;
|
| + public JourneyLogger() {
|
| + // Note that this pointer could leak the native object. The called must call destroy() to
|
| + // ensure that the native object is destroyed.
|
| + mJourneyLoggerAndroid = nativeInitJourneyLoggerAndroid();
|
| + }
|
|
|
| - public PaymentRequestJourneyLogger() {
|
| - mSections = new SectionStats[SECTION_MAX];
|
| - for (int i = 0; i < mSections.length; ++i) {
|
| - mSections[i] = new SectionStats();
|
| + /** Will destroy the native object. This class shouldn't be used afterwards. */
|
| + public void destroy() {
|
| + if (mJourneyLoggerAndroid != 0) {
|
| + nativeDestroy(mJourneyLoggerAndroid);
|
| + mJourneyLoggerAndroid = 0;
|
| }
|
| }
|
|
|
| @@ -68,8 +70,7 @@ public class PaymentRequestJourneyLogger {
|
| */
|
| public void setNumberOfSuggestionsShown(int section, int number) {
|
| assert section < SECTION_MAX;
|
| - mSections[section].mNumberSuggestionsShown = number;
|
| - mSections[section].mIsRequested = true;
|
| + nativeSetNumberOfSuggestionsShown(mJourneyLoggerAndroid, section, number);
|
| }
|
|
|
| /**
|
| @@ -79,7 +80,7 @@ public class PaymentRequestJourneyLogger {
|
| */
|
| public void incrementSelectionChanges(int section) {
|
| assert section < SECTION_MAX;
|
| - mSections[section].mNumberSelectionChanges++;
|
| + nativeIncrementSelectionChanges(mJourneyLoggerAndroid, section);
|
| }
|
|
|
| /**
|
| @@ -89,7 +90,7 @@ public class PaymentRequestJourneyLogger {
|
| */
|
| public void incrementSelectionEdits(int section) {
|
| assert section < SECTION_MAX;
|
| - mSections[section].mNumberSelectionEdits++;
|
| + nativeIncrementSelectionEdits(mJourneyLoggerAndroid, section);
|
| }
|
|
|
| /**
|
| @@ -99,7 +100,7 @@ public class PaymentRequestJourneyLogger {
|
| */
|
| public void incrementSelectionAdds(int section) {
|
| assert section < SECTION_MAX;
|
| - mSections[section].mNumberSelectionAdds++;
|
| + nativeIncrementSelectionAdds(mJourneyLoggerAndroid, section);
|
| }
|
|
|
| /**
|
| @@ -108,15 +109,14 @@ public class PaymentRequestJourneyLogger {
|
| * @param value The return value of the CanMakePayment call.
|
| */
|
| public void setCanMakePaymentValue(boolean value) {
|
| - mWasCanMakePaymentUsed = true;
|
| - mCouldMakePayment |= value;
|
| + nativeSetCanMakePaymentValue(mJourneyLoggerAndroid, value);
|
| }
|
|
|
| /**
|
| * Records the fact that the Payment Request was shown to the user.
|
| */
|
| public void setShowCalled() {
|
| - mWasShowCalled = true;
|
| + nativeSetShowCalled(mJourneyLoggerAndroid);
|
| }
|
|
|
| /*
|
| @@ -124,133 +124,23 @@ public class PaymentRequestJourneyLogger {
|
| * usage of the CanMakePayment method and its effect on the transaction. This method should be
|
| * called when the payment request has either been completed or aborted.
|
| *
|
| - * @param submissionType A string indicating the way the payment request was concluded.
|
| - */
|
| - public void recordJourneyStatsHistograms(String submissionType) {
|
| - recordSectionSpecificStats(submissionType);
|
| -
|
| - // Record the CanMakePayment metrics based on whether the transaction was completed or
|
| - // aborted by the user (UserAborted) or otherwise (OtherAborted).
|
| - recordCanMakePaymentStats(submissionType.contains("Abort") ? COMPLETION_STATUS_ABORTED
|
| - : COMPLETION_STATUS_COMPLETED);
|
| - }
|
| -
|
| - /**
|
| - * Records the histograms for all the sections that were requested by the merchant.
|
| - *
|
| - * @param submissionType A string indicating the way the payment request was concluded.
|
| - */
|
| - private void recordSectionSpecificStats(String submissionType) {
|
| - // Record whether the user had suggestions for each requested information.
|
| - boolean userHadAllRequestedInformation = true;
|
| -
|
| - for (int i = 0; i < mSections.length; ++i) {
|
| - String nameSuffix = "";
|
| - switch (i) {
|
| - case SECTION_SHIPPING_ADDRESS:
|
| - nameSuffix = "ShippingAddress." + submissionType;
|
| - break;
|
| - case SECTION_CONTACT_INFO:
|
| - nameSuffix = "ContactInfo." + submissionType;
|
| - break;
|
| - case SECTION_CREDIT_CARDS:
|
| - nameSuffix = "CreditCards." + submissionType;
|
| - break;
|
| - default:
|
| - break;
|
| - }
|
| -
|
| - assert !nameSuffix.isEmpty();
|
| -
|
| - // Only log the metrics for a section if it was requested by the merchant.
|
| - if (mSections[i].mIsRequested) {
|
| - RecordHistogram.recordCustomCountHistogram(
|
| - "PaymentRequest.NumberOfSelectionAdds." + nameSuffix,
|
| - Math.min(mSections[i].mNumberSelectionAdds, MAX_EXPECTED_SAMPLE),
|
| - MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS);
|
| - RecordHistogram.recordCustomCountHistogram(
|
| - "PaymentRequest.NumberOfSelectionChanges." + nameSuffix,
|
| - Math.min(mSections[i].mNumberSelectionChanges, MAX_EXPECTED_SAMPLE),
|
| - MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS);
|
| - RecordHistogram.recordCustomCountHistogram(
|
| - "PaymentRequest.NumberOfSelectionEdits." + nameSuffix,
|
| - Math.min(mSections[i].mNumberSelectionEdits, MAX_EXPECTED_SAMPLE),
|
| - MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS);
|
| - RecordHistogram.recordCustomCountHistogram(
|
| - "PaymentRequest.NumberOfSuggestionsShown." + nameSuffix,
|
| - Math.min(mSections[i].mNumberSuggestionsShown, MAX_EXPECTED_SAMPLE),
|
| - MIN_EXPECTED_SAMPLE, MAX_EXPECTED_SAMPLE, NUMBER_BUCKETS);
|
| -
|
| - if (mSections[i].mNumberSuggestionsShown == 0) {
|
| - userHadAllRequestedInformation = false;
|
| - }
|
| - }
|
| - }
|
| -
|
| - // Record metrics about completion based on whether the user had suggestions for each
|
| - // requested information.
|
| - int completionStatus = submissionType.contains("Abort") ? COMPLETION_STATUS_ABORTED
|
| - : COMPLETION_STATUS_COMPLETED;
|
| - if (userHadAllRequestedInformation) {
|
| - RecordHistogram.recordEnumeratedHistogram(
|
| - "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion",
|
| - completionStatus, COMPLETION_STATUS_MAX);
|
| - } else {
|
| - RecordHistogram.recordEnumeratedHistogram(
|
| - "PaymentRequest.UserDidNotHaveSuggestionsForEverything.EffectOnCompletion",
|
| - completionStatus, COMPLETION_STATUS_MAX);
|
| - }
|
| - }
|
| -
|
| - /**
|
| - * Records the metrics related the the CanMakePayment method.
|
| - *
|
| - * @param completionStatus Whether the transaction was completed or aborted.
|
| + * @param submissionType An int indicating the way the payment request was concluded.
|
| */
|
| - private void recordCanMakePaymentStats(int completionStatus) {
|
| - // Record CanMakePayment usage.
|
| - RecordHistogram.recordEnumeratedHistogram("PaymentRequest.CanMakePayment.Usage",
|
| - mWasCanMakePaymentUsed ? CAN_MAKE_PAYMENT_USED : CAN_MAKE_PAYMENT_NOT_USED,
|
| - CAN_MAKE_PAYMENT_USE_MAX);
|
| -
|
| - recordCanMakePaymentEffectOnShow();
|
| - recordCanMakePaymentEffectOnCompletion(completionStatus);
|
| + public void recordJourneyStatsHistograms(int completionStatus) {
|
| + nativeRecordJourneyStatsHistograms(mJourneyLoggerAndroid, completionStatus);
|
| }
|
|
|
| - /**
|
| - * Records CanMakePayment's return value effect on whether the Payment Request was shown or not.
|
| - */
|
| - private void recordCanMakePaymentEffectOnShow() {
|
| - if (!mWasCanMakePaymentUsed) return;
|
| -
|
| - int effectOnShow = 0;
|
| - if (mWasShowCalled) effectOnShow |= CMP_SHOW_DID_SHOW;
|
| - if (mCouldMakePayment) effectOnShow |= CMP_SHOW_COULD_MAKE_PAYMENT;
|
| -
|
| - RecordHistogram.recordEnumeratedHistogram(
|
| - "PaymentRequest.CanMakePayment.Used.EffetOnShow", effectOnShow, CMP_SHOW_MAX);
|
| - }
|
| -
|
| - /**
|
| - * Records the completion status depending on the the usage and return value of the
|
| - * CanMakePaymentMethod.
|
| - *
|
| - * @param completionStatus Whether the transaction was completed or aborted.
|
| - */
|
| - private void recordCanMakePaymentEffectOnCompletion(int completionStatus) {
|
| - if (!mWasShowCalled) return;
|
| -
|
| - String histogramName = "PaymentRequest.CanMakePayment.";
|
| -
|
| - if (!mWasCanMakePaymentUsed) {
|
| - histogramName += "NotUsed.WithShowEffectOnCompletion";
|
| - } else if (mCouldMakePayment) {
|
| - histogramName += "Used.TrueWithShowEffectOnCompletion";
|
| - } else {
|
| - histogramName += "Used.FalseWithShowEffectOnCompletion";
|
| - }
|
| -
|
| - RecordHistogram.recordEnumeratedHistogram(
|
| - histogramName, completionStatus, COMPLETION_STATUS_MAX);
|
| - }
|
| + private native long nativeInitJourneyLoggerAndroid();
|
| + private native void nativeDestroy(long nativeJourneyLoggerAndroid);
|
| + private native void nativeSetNumberOfSuggestionsShown(
|
| + long nativeJourneyLoggerAndroid, int section, int number);
|
| + private native void nativeIncrementSelectionChanges(
|
| + long nativeJourneyLoggerAndroid, int section);
|
| + private native void nativeIncrementSelectionEdits(long nativeJourneyLoggerAndroid, int section);
|
| + private native void nativeIncrementSelectionAdds(long nativeJourneyLoggerAndroid, int section);
|
| + private native void nativeSetCanMakePaymentValue(
|
| + long nativeJourneyLoggerAndroid, boolean value);
|
| + private native void nativeSetShowCalled(long nativeJourneyLoggerAndroid);
|
| + private native void nativeRecordJourneyStatsHistograms(
|
| + long nativeJourneyLoggerAndroid, int completionStatus);
|
| }
|
|
|