Bug 1811901 - part1 : implement conditional forward method on MediaEventForwarder. r=jolin

Differential Revision: https://phabricator.services.mozilla.com/D168013
This commit is contained in:
alwu 2023-02-02 00:01:09 +00:00
Родитель 7d268f85ca
Коммит 2fc0f48bca
1 изменённых файлов: 13 добавлений и 0 удалений

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

@ -564,6 +564,19 @@ class MediaEventForwarder : public MediaEventSource<Es...> {
}));
}
template <typename Function>
void ForwardIf(MediaEventSource<Es...>& aSource, Function&& aFunction) {
// Forwarding a rawptr `this` here is fine, since DisconnectAll disconnect
// all mListeners synchronously and prevents this handler from running.
mListeners.AppendElement(aSource.Connect(
mEventTarget, [this, func = aFunction](ArgType<Es>&&... aEvents) {
if (!func()) {
return;
}
this->NotifyInternal(std::forward<ArgType<Es>...>(aEvents)...);
}));
}
void DisconnectAll() {
for (auto& l : mListeners) {
l.Disconnect();