Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2659)

Unified Diff: base/android/java/src/org/chromium/base/metrics/RecordUserAction.java

Issue 2956283002: Expose Add/RemoveActionCallback to java (Closed)
Patch Set: Use assert instead of an exception Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/BUILD.gn ('k') | base/android/record_user_action.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/java/src/org/chromium/base/metrics/RecordUserAction.java
diff --git a/base/android/java/src/org/chromium/base/metrics/RecordUserAction.java b/base/android/java/src/org/chromium/base/metrics/RecordUserAction.java
index 5334746d918caa1076f91318231516809f3322cf..0d2ba548d2ff48fe9eee7a44606d00bfeff25367 100644
--- a/base/android/java/src/org/chromium/base/metrics/RecordUserAction.java
+++ b/base/android/java/src/org/chromium/base/metrics/RecordUserAction.java
@@ -6,6 +6,7 @@ package org.chromium.base.metrics;
import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
+import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
/**
@@ -49,5 +50,36 @@ public class RecordUserAction {
});
}
+ /**
+ * Interface to a class that receives a callback for each UserAction that is recorded.
+ */
+ public interface UserActionCallback {
+ @CalledByNative("UserActionCallback")
+ void onActionRecorded(String action);
+ }
+
+ private static long sNativeActionCallback;
+
+ /**
+ * Register a callback that is executed for each recorded UserAction.
+ * Only one callback can be registered at a time.
+ * The callback has to be unregistered using removeActionCallbackForTesting().
+ */
+ public static void setActionCallbackForTesting(UserActionCallback callback) {
+ assert sNativeActionCallback == 0;
+ sNativeActionCallback = nativeAddActionCallbackForTesting(callback);
+ }
+
+ /**
+ * Unregister the UserActionCallback.
+ */
+ public static void removeActionCallbackForTesting() {
+ assert sNativeActionCallback != 0;
+ nativeRemoveActionCallbackForTesting(sNativeActionCallback);
+ sNativeActionCallback = 0;
+ }
+
private static native void nativeRecordUserAction(String action);
+ private static native long nativeAddActionCallbackForTesting(UserActionCallback callback);
+ private static native void nativeRemoveActionCallbackForTesting(long callbackId);
}
« no previous file with comments | « base/BUILD.gn ('k') | base/android/record_user_action.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698