Bug 1445662 - Ensure the keyboard map access is threadsafe. r=rhunt

- The change in APZCTreeManagerParent is functionally a no-op because it
  only ever runs in the GPU process on the controller thread. But it
  allows moving the controller thread to some other thread.
- The change in nsBaseWidget is a no-op for desktop platforms, because
  in the UI process the main thread is the controller thread. But on
  Android it moves the call from the main thread to the Java UI thread.
This commit is contained in:
Kartikaya Gupta 2018-03-15 15:25:08 -04:00
Родитель 58ea959557
Коммит d59c0946db
4 изменённых файлов: 16 добавлений и 2 удалений

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

@ -1878,6 +1878,8 @@ APZCTreeManager::ProcessTouchVelocity(uint32_t aTimestampMs, float aSpeedY)
void
APZCTreeManager::SetKeyboardMap(const KeyboardMap& aKeyboardMap)
{
APZThreadUtils::AssertOnControllerThread();
mKeyboardMap = aKeyboardMap;
}

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

@ -699,6 +699,7 @@ private:
std::unordered_map<ScrollableLayerGuid, ZoomConstraints, ScrollableLayerGuidHash> mZoomConstraints;
/* A list of keyboard shortcuts to use for translating keyboard inputs into
* keyboard actions. This is gathered on the main thread from XBL bindings.
* This must only be accessed on the controller thread.
*/
KeyboardMap mKeyboardMap;
/* This tracks the focus targets of chrome and content and whether we have

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

@ -166,7 +166,11 @@ APZCTreeManagerParent::RecvReceiveKeyboardInputEvent(
mozilla::ipc::IPCResult
APZCTreeManagerParent::RecvSetKeyboardMap(const KeyboardMap& aKeyboardMap)
{
mTreeManager->SetKeyboardMap(aKeyboardMap);
APZThreadUtils::RunOnControllerThread(NewRunnableMethod<KeyboardMap>(
"layers::IAPZCTreeManager::SetKeyboardMap",
mTreeManager,
&IAPZCTreeManager::SetKeyboardMap,
aKeyboardMap));
return IPC_OK();
}

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

@ -933,6 +933,7 @@ nsBaseWidget::CreateRootContentController()
void nsBaseWidget::ConfigureAPZCTreeManager()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mAPZC);
ConfigureAPZControllerThread();
@ -940,7 +941,13 @@ void nsBaseWidget::ConfigureAPZCTreeManager()
mAPZC->SetDPI(GetDPI());
if (gfxPrefs::APZKeyboardEnabled()) {
mAPZC->SetKeyboardMap(nsXBLWindowKeyHandler::CollectKeyboardShortcuts());
KeyboardMap map = nsXBLWindowKeyHandler::CollectKeyboardShortcuts();
// On Android the main thread is not the controller thread
APZThreadUtils::RunOnControllerThread(NewRunnableMethod<KeyboardMap>(
"layers::IAPZCTreeManager::SetKeyboardMap",
mAPZC,
&IAPZCTreeManager::SetKeyboardMap,
map));
}
RefPtr<IAPZCTreeManager> treeManager = mAPZC; // for capture by the lambdas