Bug 857413 - Use only one copy of GeckoInputConnection.InputThreadUtils; r=cpeterson

This commit is contained in:
Jim Chen 2013-04-11 10:54:14 -04:00
Родитель 5bbfaa296a
Коммит 50089bfa08
1 изменённых файлов: 14 добавлений и 11 удалений

Просмотреть файл

@ -47,14 +47,18 @@ class GeckoInputConnection
private static Handler sBackgroundHandler;
private class InputThreadUtils {
private static class InputThreadUtils {
// We only want one UI editable around to keep synchronization simple,
// so we make InputThreadUtils a singleton
public static final InputThreadUtils sInstance = new InputThreadUtils();
private Editable mUiEditable;
private Object mUiEditableReturn;
private Exception mUiEditableException;
private final SynchronousQueue<Runnable> mIcRunnableSync;
private final Runnable mIcSignalRunnable;
public InputThreadUtils() {
private InputThreadUtils() {
mIcRunnableSync = new SynchronousQueue<Runnable>();
mIcSignalRunnable = new Runnable() {
@Override public void run() {
@ -120,13 +124,14 @@ class GeckoInputConnection
}
public Editable getEditableForUiThread(final Handler uiHandler,
final Handler icHandler) {
final GeckoEditableClient client) {
if (DEBUG) {
ThreadUtils.assertOnThread(uiHandler.getLooper().getThread());
}
final Handler icHandler = client.getInputConnectionHandler();
if (icHandler.getLooper() == uiHandler.getLooper()) {
// IC thread is UI thread; safe to use Editable directly
return getEditable();
return client.getEditable();
}
// IC thread is not UI thread; we need to return a proxy Editable in order
// to safely use the Editable from the UI thread
@ -152,7 +157,7 @@ class GeckoInputConnection
synchronized (icHandler) {
try {
mUiEditableReturn = method.invoke(
mEditableClient.getEditable(), args);
client.getEditable(), args);
} catch (Exception e) {
mUiEditableException = e;
}
@ -179,8 +184,6 @@ class GeckoInputConnection
}
}
private final InputThreadUtils mThreadUtils = new InputThreadUtils();
// Managed only by notifyIMEContext; see comments in notifyIMEContext
private int mIMEState;
private String mIMETypeHint = "";
@ -664,10 +667,10 @@ class GeckoInputConnection
// that point the key event has already been processed.
mainHandler.post(new Runnable() {
@Override public void run() {
mThreadUtils.endWaitForUiThread();
InputThreadUtils.sInstance.endWaitForUiThread();
}
});
mThreadUtils.waitForUiThread(icHandler);
InputThreadUtils.sInstance.waitForUiThread(icHandler);
}
return false; // seems to always return false
}
@ -738,8 +741,8 @@ class GeckoInputConnection
// safe to use on the UI thread; therefore we need to pass a proxy Editable to it
KeyListener keyListener = TextKeyListener.getInstance();
Handler uiHandler = view.getRootView().getHandler();
Handler icHandler = mEditableClient.getInputConnectionHandler();
Editable uiEditable = mThreadUtils.getEditableForUiThread(uiHandler, icHandler);
Editable uiEditable = InputThreadUtils.sInstance.
getEditableForUiThread(uiHandler, mEditableClient);
boolean skip = shouldSkipKeyListener(keyCode, event);
if (down) {
mEditableClient.setSuppressKeyUp(true);