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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchRankerLoggerImpl.java

Issue 2857333002: [TTS] Write initial Tap-features to Ranker. (Closed)
Patch Set: Reverted changes to translate_ranker_impl.cc and changed DVLOG(0) to DVLOG(3). Created 3 years, 7 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
Index: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchRankerLoggerImpl.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchRankerLoggerImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchRankerLoggerImpl.java
index f56846a9e1520392f10e63580250c007eebfb28f..5489b5a54c228ea547185d45548ab05ce816d069 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchRankerLoggerImpl.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchRankerLoggerImpl.java
@@ -6,16 +6,77 @@ package org.chromium.chrome.browser.contextualsearch;
import org.chromium.base.Log;
+import java.net.URL;
+
/**
* Implements the UMA logging for Ranker that's used for Contextual Search Tap Suppression.
*/
public class ContextualSearchRankerLoggerImpl implements ContextualSearchRankerLogger {
private static final String TAG = "ContextualSearch";
+ private static final int VERSION = 0;
+
+ // Pointer to the native instance of this class.
+ private long mNativePointer;
+
+ // The URL of the base page to log with Ranker.
+ private URL mBasePageUrl;
+
+ public ContextualSearchRankerLoggerImpl() {
+ if (ContextualSearchFieldTrial.isRankerLoggingEnabled()) {
+ mNativePointer = nativeInit();
+ if (mBasePageUrl != null) {
+ nativeSetUkmServiceAndUrls(
+ mNativePointer, mBasePageUrl.toString(), getContextualSearchRankerUrl());
+ }
+ }
+ }
+
+ /**
+ * This method should be called to clean up storage when an instance of this class is
+ * no longer in use. The nativeDestroy will call the destructor on the native instance.
+ */
+ void destroy() {
+ if (ContextualSearchFieldTrial.isRankerLoggingEnabled()) {
+ assert mNativePointer != 0;
+ writeLogAndReset();
+ nativeDestroy(mNativePointer);
+ mNativePointer = 0;
+ }
+ }
+
+ @Override
+ public void setBasePageUrl(URL basePageUrl) {
+ mBasePageUrl = basePageUrl;
+ if (mBasePageUrl != null) {
+ nativeSetUkmServiceAndUrls(
+ mNativePointer, mBasePageUrl.toString(), getContextualSearchRankerUrl());
+ }
+ }
+
@Override
public void log(Feature feature, Object value) {
- // TODO(donnd): log to an actual persistent proto ASAP!
- Log.v(TAG, "log %s with value %s", feature.toString(), value);
+ if (ContextualSearchFieldTrial.isRankerLoggingEnabled()) {
+ if (value instanceof String) {
+ nativeLogString(mNativePointer, feature.toString(), value.toString());
+ } else if (value instanceof Boolean) {
+ nativeLogLong(mNativePointer, feature.toString(), ((boolean) value ? 1 : 0));
+ } else if (value instanceof Integer) {
+ Integer i = (int) value;
+ nativeLogLong(mNativePointer, feature.toString(), Long.valueOf(i));
+ } else if (value instanceof Long) {
+ nativeLogLong(mNativePointer, feature.toString(), (long) value);
+ } else if (value instanceof Character) {
+ nativeLogLong(mNativePointer, feature.toString(),
+ Character.getNumericValue((char) value));
+ } else {
+ Log.w(TAG,
+ "Could not log feature to Ranker: " + feature.toString() + " of class "
+ + value.getClass());
+ }
+ } else {
+ Log.v(TAG, "Ranker data %s: %s", feature, value);
+ }
}
@Override
@@ -25,6 +86,23 @@ public class ContextualSearchRankerLoggerImpl implements ContextualSearchRankerL
@Override
public void writeLogAndReset() {
- Log.v(TAG, "Reset!\n");
+ nativeWriteLogAndReset(mNativePointer);
}
+
+ private String getContextualSearchRankerUrl() {
+ return "org.chromium.chrome.browser.contextualsearch.v" + VERSION;
+ }
+
+ // ============================================================================================
+ // Native methods.
+ // ============================================================================================
+ private native long nativeInit();
+ private native void nativeDestroy(long nativeContextualSearchRankerLoggerImpl);
+ private native void nativeLogLong(
+ long nativeContextualSearchRankerLoggerImpl, String featureString, long value);
+ private native void nativeLogString(
+ long nativeContextualSearchRankerLoggerImpl, String featureString, String value);
+ private native void nativeSetUkmServiceAndUrls(
+ long nativeContextualSearchRankerLoggerImpl, String basePageUrl, String modelUrl);
+ private native void nativeWriteLogAndReset(long nativeContextualSearchRankerLoggerImpl);
}

Powered by Google App Engine
This is Rietveld 408576698