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