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 @@
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.
......
......@@ -242,9 +242,7 @@ public class ContextualSearchRankerLoggerImpl implements ContextualSearchInterac
if (value instanceof Boolean) {
logToNative(feature, ((boolean) value ? 1 : 0));
} else if (value instanceof Integer) {
logToNative(feature, Long.valueOf((int) value));
} else if (value instanceof Long) {
logToNative(feature, (long) value);
logToNative(feature, (int) value);
} else if (value instanceof Character) {
logToNative(feature, Character.getNumericValue((char) value));
} else {
......@@ -259,10 +257,10 @@ public class ContextualSearchRankerLoggerImpl implements ContextualSearchInterac
* @param feature The feature 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);
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
// ============================================================================================
private native long nativeInit();
private native void nativeDestroy(long nativeContextualSearchRankerLoggerImpl);
private native void nativeLogLong(
long nativeContextualSearchRankerLoggerImpl, String featureString, long value);
private native void nativeLogInt32(
long nativeContextualSearchRankerLoggerImpl, String featureString, int value);
private native void nativeSetupLoggingAndRanker(
long nativeContextualSearchRankerLoggerImpl, WebContents basePageWebContents);
// Returns an AssistRankerPrediction integer value.
......
......@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.contextualsearch;
import android.net.Uri;
import android.support.annotation.Nullable;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.ChromeActivity;
......@@ -22,8 +23,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;
import javax.annotation.Nullable;
/**
* Implements a fake Contextual Search server, for testing purposes.
* TODO(donnd): add more functionality to this class once the overall approach has been validated.
......
......@@ -79,13 +79,13 @@ void ContextualSearchRankerLoggerImpl::LogFeature(
features[feature_name].set_int32_value(value);
}
void ContextualSearchRankerLoggerImpl::LogLong(
void ContextualSearchRankerLoggerImpl::LogInt32(
JNIEnv* env,
jobject obj,
const base::android::JavaParamRef<jstring>& j_feature,
jlong j_long) {
jint j_int) {
std::string feature = base::android::ConvertJavaStringToUTF8(env, j_feature);
LogFeature(feature, j_long);
LogFeature(feature, j_int);
}
AssistRankerPrediction ContextualSearchRankerLoggerImpl::RunInference(
......
......@@ -49,11 +49,11 @@ class ContextualSearchRankerLoggerImpl {
jobject obj,
const base::android::JavaParamRef<jobject>& java_web_contents);
// Logs a long value with the given feature name.
void LogLong(JNIEnv* env,
jobject obj,
const base::android::JavaParamRef<jstring>& j_feature,
jlong j_long);
// Logs an int32 value with the given feature name.
void LogInt32(JNIEnv* env,
jobject obj,
const base::android::JavaParamRef<jstring>& j_feature,
jint j_int);
// Runs the model and returns the inference result as an
// 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