Commit 43fae897 authored by changwan's avatar changwan Committed by Commit bot

Reuse InputConnectionHandlerThread

This can prevent the number of threads from growing when an app creates
and destroys webviews.

BUG=668692

Review-Url: https://codereview.chromium.org/2543893002
Cr-Commit-Position: refs/heads/master@{#435557}
parent c5c66361
......@@ -11,6 +11,7 @@ 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
......@@ -30,6 +31,10 @@ 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;
......@@ -61,11 +66,14 @@ public class ThreadedInputConnectionFactory implements ChromiumBaseInputConnecti
}
@VisibleForTesting
@SuppressFBWarnings("LI_LAZY_INIT_UPDATE_STATIC")
protected Handler createHandler() {
HandlerThread thread =
new HandlerThread("InputConnectionHandlerThread", HandlerThread.NORM_PRIORITY);
thread.start();
return new Handler(thread.getLooper());
if (sHandlerThread == null) {
sHandlerThread =
new HandlerThread("InputConnectionHandlerThread", HandlerThread.NORM_PRIORITY);
sHandlerThread.start();
}
return new Handler(sHandlerThread.getLooper());
}
@VisibleForTesting
......
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