Commit b884937f authored by Donn Denman's avatar Donn Denman Committed by Commit Bot

[TTS] Minor cleanup to CS usage of Ranker

Fixes a bug in the existing Ranker code: the native logger cannot log
64-bit values, so we rename some misleading methods. Also fix some
references to @Nullable.

BUG=872902

Change-Id: I496c8140293200d7f8041fba1a5ede8fac26646a
Reviewed-on: https://chromium-review.googlesource.com/c/1321670Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Donn Denman <donnd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606578}
parent 50efb070
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
package org.chromium.chrome.browser.contextualsearch; package org.chromium.chrome.browser.contextualsearch;
import java.net.URL; import android.support.annotation.Nullable;
import javax.annotation.Nullable; import java.net.URL;
/** /**
* An interface for network communication between the Contextual Search client and server. * An interface for network communication between the Contextual Search client and server.
......
...@@ -242,9 +242,7 @@ public class ContextualSearchRankerLoggerImpl implements ContextualSearchInterac ...@@ -242,9 +242,7 @@ public class ContextualSearchRankerLoggerImpl implements ContextualSearchInterac
if (value instanceof Boolean) { if (value instanceof Boolean) {
logToNative(feature, ((boolean) value ? 1 : 0)); logToNative(feature, ((boolean) value ? 1 : 0));
} else if (value instanceof Integer) { } else if (value instanceof Integer) {
logToNative(feature, Long.valueOf((int) value)); logToNative(feature, (int) value);
} else if (value instanceof Long) {
logToNative(feature, (long) value);
} else if (value instanceof Character) { } else if (value instanceof Character) {
logToNative(feature, Character.getNumericValue((char) value)); logToNative(feature, Character.getNumericValue((char) value));
} else { } else {
...@@ -259,10 +257,10 @@ public class ContextualSearchRankerLoggerImpl implements ContextualSearchInterac ...@@ -259,10 +257,10 @@ public class ContextualSearchRankerLoggerImpl implements ContextualSearchInterac
* @param feature The feature to log. * @param feature The feature to log.
* @param value The value to log. * @param value The value to log.
*/ */
private void logToNative(@Feature int feature, long value) { private void logToNative(@Feature int feature, int value) {
String featureName = getFeatureName(feature); String featureName = getFeatureName(feature);
assert featureName != null : "No Name for feature " + feature; assert featureName != null : "No Name for feature " + feature;
nativeLogLong(mNativePointer, featureName, value); nativeLogInt32(mNativePointer, featureName, value);
} }
/** /**
...@@ -299,8 +297,8 @@ public class ContextualSearchRankerLoggerImpl implements ContextualSearchInterac ...@@ -299,8 +297,8 @@ public class ContextualSearchRankerLoggerImpl implements ContextualSearchInterac
// ============================================================================================ // ============================================================================================
private native long nativeInit(); private native long nativeInit();
private native void nativeDestroy(long nativeContextualSearchRankerLoggerImpl); private native void nativeDestroy(long nativeContextualSearchRankerLoggerImpl);
private native void nativeLogLong( private native void nativeLogInt32(
long nativeContextualSearchRankerLoggerImpl, String featureString, long value); long nativeContextualSearchRankerLoggerImpl, String featureString, int value);
private native void nativeSetupLoggingAndRanker( private native void nativeSetupLoggingAndRanker(
long nativeContextualSearchRankerLoggerImpl, WebContents basePageWebContents); long nativeContextualSearchRankerLoggerImpl, WebContents basePageWebContents);
// Returns an AssistRankerPrediction integer value. // Returns an AssistRankerPrediction integer value.
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.contextualsearch; package org.chromium.chrome.browser.contextualsearch;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.Nullable;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
...@@ -22,8 +23,6 @@ import java.util.HashMap; ...@@ -22,8 +23,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import javax.annotation.Nullable;
/** /**
* Implements a fake Contextual Search server, for testing purposes. * Implements a fake Contextual Search server, for testing purposes.
* TODO(donnd): add more functionality to this class once the overall approach has been validated. * TODO(donnd): add more functionality to this class once the overall approach has been validated.
......
...@@ -79,13 +79,13 @@ void ContextualSearchRankerLoggerImpl::LogFeature( ...@@ -79,13 +79,13 @@ void ContextualSearchRankerLoggerImpl::LogFeature(
features[feature_name].set_int32_value(value); features[feature_name].set_int32_value(value);
} }
void ContextualSearchRankerLoggerImpl::LogLong( void ContextualSearchRankerLoggerImpl::LogInt32(
JNIEnv* env, JNIEnv* env,
jobject obj, jobject obj,
const base::android::JavaParamRef<jstring>& j_feature, const base::android::JavaParamRef<jstring>& j_feature,
jlong j_long) { jint j_int) {
std::string feature = base::android::ConvertJavaStringToUTF8(env, j_feature); std::string feature = base::android::ConvertJavaStringToUTF8(env, j_feature);
LogFeature(feature, j_long); LogFeature(feature, j_int);
} }
AssistRankerPrediction ContextualSearchRankerLoggerImpl::RunInference( AssistRankerPrediction ContextualSearchRankerLoggerImpl::RunInference(
......
...@@ -49,11 +49,11 @@ class ContextualSearchRankerLoggerImpl { ...@@ -49,11 +49,11 @@ class ContextualSearchRankerLoggerImpl {
jobject obj, jobject obj,
const base::android::JavaParamRef<jobject>& java_web_contents); const base::android::JavaParamRef<jobject>& java_web_contents);
// Logs a long value with the given feature name. // Logs an int32 value with the given feature name.
void LogLong(JNIEnv* env, void LogInt32(JNIEnv* env,
jobject obj, jobject obj,
const base::android::JavaParamRef<jstring>& j_feature, const base::android::JavaParamRef<jstring>& j_feature,
jlong j_long); jint j_int);
// Runs the model and returns the inference result as an // Runs the model and returns the inference result as an
// AssistRankerPrediction enum. // AssistRankerPrediction enum.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment