| Index: content/public/android/java/src/org/chromium/content/browser/input/ThreadedInputConnectionFactory.java
|
| diff --git a/content/public/android/java/src/org/chromium/content/browser/input/ThreadedInputConnectionFactory.java b/content/public/android/java/src/org/chromium/content/browser/input/ThreadedInputConnectionFactory.java
|
| index c3ea38dcd4f2351ab9d9f946728f8db1afeea93a..d3ed0fc2fc21afff95b6654cc804cb731e4b9ed6 100644
|
| --- a/content/public/android/java/src/org/chromium/content/browser/input/ThreadedInputConnectionFactory.java
|
| +++ b/content/public/android/java/src/org/chromium/content/browser/input/ThreadedInputConnectionFactory.java
|
| @@ -11,7 +11,6 @@ import android.view.inputmethod.EditorInfo;
|
|
|
| import org.chromium.base.Log;
|
| import org.chromium.base.VisibleForTesting;
|
| -import org.chromium.base.annotations.SuppressFBWarnings;
|
|
|
| /**
|
| * A factory class for {@link ThreadedInputConnection}. The class also includes triggering
|
| @@ -31,11 +30,6 @@ public class ThreadedInputConnectionFactory implements ChromiumBaseInputConnecti
|
| // UI message loop until View#hasWindowFocus() is aligned with what IMMS sees.
|
| private static final int CHECK_REGISTER_RETRY = 1;
|
|
|
| - // Reused for multiple WebView instances. TODO(changwan): check if we need to quit the loop
|
| - // for the last webview instance.
|
| - private static HandlerThread sHandlerThread;
|
| -
|
| - private final Handler mHandler;
|
| private final InputMethodManagerWrapper mInputMethodManagerWrapper;
|
| private final InputMethodUma mInputMethodUma;
|
| private ThreadedInputConnectionProxyView mProxyView;
|
| @@ -43,6 +37,18 @@ public class ThreadedInputConnectionFactory implements ChromiumBaseInputConnecti
|
| private CheckInvalidator mCheckInvalidator;
|
| private boolean mReentrantTriggering;
|
|
|
| + // Initialization-on-demand holder for Handler.
|
| + private static class LazyHandlerHolder {
|
| + // Note that we never exit this thread to avoid lifetime or thread-safety issues.
|
| + private static final Handler sHandler;
|
| + static {
|
| + HandlerThread handlerThread =
|
| + new HandlerThread("InputConnectionHandlerThread", HandlerThread.NORM_PRIORITY);
|
| + handlerThread.start();
|
| + sHandler = new Handler(handlerThread.getLooper());
|
| + }
|
| + }
|
| +
|
| // A small class that can be updated to invalidate the check when there is an external event
|
| // such as window focus loss or view focus loss.
|
| private static class CheckInvalidator {
|
| @@ -61,19 +67,12 @@ public class ThreadedInputConnectionFactory implements ChromiumBaseInputConnecti
|
|
|
| ThreadedInputConnectionFactory(InputMethodManagerWrapper inputMethodManagerWrapper) {
|
| mInputMethodManagerWrapper = inputMethodManagerWrapper;
|
| - mHandler = createHandler();
|
| mInputMethodUma = createInputMethodUma();
|
| }
|
|
|
| - @VisibleForTesting
|
| - @SuppressFBWarnings("LI_LAZY_INIT_UPDATE_STATIC")
|
| - protected Handler createHandler() {
|
| - if (sHandlerThread == null) {
|
| - sHandlerThread =
|
| - new HandlerThread("InputConnectionHandlerThread", HandlerThread.NORM_PRIORITY);
|
| - sHandlerThread.start();
|
| - }
|
| - return new Handler(sHandlerThread.getLooper());
|
| + @Override
|
| + public Handler getHandler() {
|
| + return LazyHandlerHolder.sHandler;
|
| }
|
|
|
| @VisibleForTesting
|
| @@ -133,7 +132,7 @@ public class ThreadedInputConnectionFactory implements ChromiumBaseInputConnecti
|
|
|
| if (mThreadedInputConnection == null) {
|
| if (DEBUG_LOGS) Log.w(TAG, "Creating ThreadedInputConnection...");
|
| - mThreadedInputConnection = new ThreadedInputConnection(view, imeAdapter, mHandler);
|
| + mThreadedInputConnection = new ThreadedInputConnection(view, imeAdapter, getHandler());
|
| } else {
|
| mThreadedInputConnection.resetOnUiThread();
|
| }
|
| @@ -154,7 +153,7 @@ public class ThreadedInputConnectionFactory implements ChromiumBaseInputConnecti
|
| if (!view.hasWindowFocus()) mCheckInvalidator.invalidate();
|
|
|
| // We cannot reuse the existing proxy view, if any, due to crbug.com/664402.
|
| - mProxyView = createProxyView(mHandler, view);
|
| + mProxyView = createProxyView(getHandler(), view);
|
|
|
| mReentrantTriggering = true;
|
| // This does not affect view focus of the real views.
|
| @@ -181,7 +180,7 @@ public class ThreadedInputConnectionFactory implements ChromiumBaseInputConnecti
|
|
|
| // Step 3: Check that the above hack worked.
|
| // Do not check until activation finishes inside InputMethodManager (on IME thread).
|
| - mHandler.post(new Runnable() {
|
| + getHandler().post(new Runnable() {
|
| @Override
|
| public void run() {
|
| postCheckRegisterResultOnUiThread(view, mCheckInvalidator,
|
| @@ -237,11 +236,6 @@ public class ThreadedInputConnectionFactory implements ChromiumBaseInputConnecti
|
| }
|
|
|
| @Override
|
| - public Handler getHandler() {
|
| - return mHandler;
|
| - }
|
| -
|
| - @Override
|
| public void onWindowFocusChanged(boolean gainFocus) {
|
| if (DEBUG_LOGS) Log.d(TAG, "onWindowFocusChanged: " + gainFocus);
|
| if (!gainFocus && mCheckInvalidator != null) mCheckInvalidator.invalidate();
|
|
|