Commit 7bd2df28 authored by amaralp's avatar amaralp Committed by Commit Bot

Fixing SelectionPopupController.isInsertion() race condition

After my context menu refactor (crrev.com/2785853002),
SelectionPopupController.createActionMenu() and the setting of mIsInsertion
happened on two different threads. This lead to a race-condition in
SelectionPopupController.createActionMenu() since it relied on isInsertion().
This CL removes the race-condition by relying on hasSelection() instead of
isInsertion().

BUG=730996

Review-Url: https://codereview.chromium.org/2954023002
Cr-Commit-Position: refs/heads/master@{#481789}
parent b01b9a7f
......@@ -111,7 +111,7 @@ public class SelectionPopupController extends ActionModeCallbackHelper {
private boolean mEditable;
private boolean mIsPasswordType;
private boolean mIsInsertion;
private boolean mIsInsertionForTesting;
private boolean mCanSelectAllForPastePopup;
private boolean mCanEditRichly;
......@@ -502,7 +502,7 @@ public class SelectionPopupController extends ActionModeCallbackHelper {
"paste_as_plain_text", "string", "android"));
}
if (isInsertion() || isSelectionPassword()) return;
if (!hasSelection() || isSelectionPassword()) return;
initializeTextProcessingMenu(menu);
}
......@@ -888,8 +888,8 @@ public class SelectionPopupController extends ActionModeCallbackHelper {
* @return true if the current selection is an insertion point.
*/
@VisibleForTesting
public boolean isInsertion() {
return mIsInsertion;
public boolean isInsertionForTesting() {
return mIsInsertionForTesting;
}
/**
......@@ -991,7 +991,7 @@ public class SelectionPopupController extends ActionModeCallbackHelper {
case SelectionEventType.INSERTION_HANDLE_SHOWN:
mSelectionRect.set(left, top, right, bottom);
mIsInsertion = true;
mIsInsertionForTesting = true;
break;
case SelectionEventType.INSERTION_HANDLE_MOVED:
......@@ -1015,7 +1015,7 @@ public class SelectionPopupController extends ActionModeCallbackHelper {
case SelectionEventType.INSERTION_HANDLE_CLEARED:
destroyPastePopup();
mIsInsertion = false;
mIsInsertionForTesting = false;
mSelectionRect.setEmpty();
break;
......
......@@ -867,7 +867,7 @@ public class ContentViewCoreSelectionTest {
CriteriaHelper.pollUiThread(Criteria.equals(show, new Callable<Boolean>() {
@Override
public Boolean call() {
return mSelectionPopupController.isInsertion();
return mSelectionPopupController.isInsertionForTesting();
}
}));
}
......
......@@ -1186,7 +1186,7 @@ public class ImeTest {
@Override
public boolean isSatisfied() {
return mRule.getSelectionPopupController().isPastePopupShowing()
&& mRule.getSelectionPopupController().isInsertion();
&& mRule.getSelectionPopupController().isInsertionForTesting();
}
});
......@@ -1197,7 +1197,7 @@ public class ImeTest {
return !mRule.getSelectionPopupController().isPastePopupShowing();
}
});
Assert.assertFalse(mRule.getSelectionPopupController().isInsertion());
Assert.assertFalse(mRule.getSelectionPopupController().isInsertionForTesting());
}
@Test
......
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