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.


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
protected Handler createHandler() {
HandlerThread thread =
new HandlerThread("InputConnectionHandlerThread", HandlerThread.NORM_PRIORITY);
return new Handler(thread.getLooper());
if (sHandlerThread == null) {
sHandlerThread =
new HandlerThread("InputConnectionHandlerThread", HandlerThread.NORM_PRIORITY);
return new Handler(sHandlerThread.getLooper());
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