Commit f255f21a authored by Tiger Oakes's avatar Tiger Oakes Committed by Commit Bot

Remove getApplicationContext from contextualsearch

Continuation of work in bug 646094.
Preparing to activate an errorprone check to flag
context#getApplicationContext calls. The goal is to prevent storing the
resulting context as a class property, and instead use ContextUtils.

Bug: 846456
Change-Id: I2c3efdf6c0de690ee8a9a06a523c773722c07196
Reviewed-on: https://chromium-review.googlesource.com/1095997Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Tiger Oakes <tigero@google.com>
Cr-Commit-Position: refs/heads/master@{#577202}
parent 7fbbd5f2
......@@ -237,7 +237,7 @@ public class ContextualSearchManager
mSelectionController = new ContextualSearchSelectionController(activity, this);
mNetworkCommunicator = this;
mPolicy = new ContextualSearchPolicy(mSelectionController, mNetworkCommunicator);
mTranslateController = new ContextualSearchTranslateController(activity, mPolicy, this);
mTranslateController = new ContextualSearchTranslateController(mPolicy, this);
mInternalStateController = new ContextualSearchInternalStateController(
mPolicy, getContextualSearchInternalStateHandler());
mTapSuppressionRankerLogger = new ContextualSearchRankerLoggerImpl();
......
......@@ -8,7 +8,7 @@ import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.base.ContextUtils;
import org.chromium.ui.UiUtils;
import java.util.ArrayList;
......@@ -23,7 +23,6 @@ import java.util.Locale;
public class ContextualSearchTranslateController {
private static final int LOCALE_MIN_LENGTH = 2;
private final ChromeActivity mActivity;
private final ContextualSearchPolicy mPolicy;
private final ContextualSearchTranslateInterface mHost;
......@@ -31,9 +30,8 @@ public class ContextualSearchTranslateController {
private String mTranslateServiceTargetLanguage;
private String mAcceptLanguages;
ContextualSearchTranslateController(ChromeActivity activity, ContextualSearchPolicy policy,
ContextualSearchTranslateInterface hostInterface) {
mActivity = activity;
ContextualSearchTranslateController(
ContextualSearchPolicy policy, ContextualSearchTranslateInterface hostInterface) {
mPolicy = policy;
mHost = hostInterface;
}
......@@ -140,7 +138,7 @@ public class ContextualSearchTranslateController {
uniqueLanguages.add(trimLocaleToLanguage(primaryLanguage));
}
// Merge in the IME locales, if possible.
Context context = mActivity.getApplicationContext();
Context context = ContextUtils.getApplicationContext();
if (context != null) {
for (String locale : UiUtils.getIMELocales(context)) {
if (isValidLocale(locale)) uniqueLanguages.add(trimLocaleToLanguage(locale));
......
......@@ -85,7 +85,7 @@ public class ContextualSearchTapEventTest {
selectionPopupController.setSelectionClient(this.getContextualSearchSelectionClient());
MockContextualSearchPolicy policy = new MockContextualSearchPolicy();
setContextualSearchPolicy(policy);
mTranslateController = new MockedCSTranslateController(activity, policy, null);
mTranslateController = new MockedCSTranslateController(policy, null);
}
@Override
......@@ -138,9 +138,9 @@ public class ContextualSearchTapEventTest {
private static final String ENGLISH_TARGET_LANGUAGE = "en";
private static final String ENGLISH_ACCEPT_LANGUAGES = "en-US,en";
MockedCSTranslateController(ChromeActivity activity, ContextualSearchPolicy policy,
ContextualSearchTranslateInterface hostInterface) {
super(activity, policy, hostInterface);
MockedCSTranslateController(
ContextualSearchPolicy policy, ContextualSearchTranslateInterface hostInterface) {
super(policy, hostInterface);
}
@Override
......
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