Bug 1361259. P4 - enforce copy in NonExclusive mode for each listener must get a copy. r=gerald

MozReview-Commit-ID: Mqt0N2erP6

--HG--
extra : rebase_source : 29c5a468401cd8926d5bd636caa7f63ab50e00aa
extra : source : c685f9768d516ffac538cb7fc240aaf5e4844693
This commit is contained in:
JW Wang 2017-04-28 17:56:57 +08:00
Родитель 2b44a55d99
Коммит a1108d032e
2 изменённых файлов: 41 добавлений и 1 удалений

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

@ -405,7 +405,8 @@ class MediaEventProducer : public MediaEventSource<Es...> {
public:
template <typename... Ts>
void Notify(Ts&&... aEvents) {
this->NotifyInternal(Forward<Ts>(aEvents)...);
// Pass lvalues to prevent move in NonExclusive mode.
this->NotifyInternal(aEvents...);
}
};

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

@ -335,3 +335,42 @@ TEST(MediaEventSource, MoveOnly)
queue->AwaitShutdownAndIdle();
listener.Disconnect();
}
struct RefCounter
{
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RefCounter)
explicit RefCounter(int aVal) : mVal(aVal) { }
int mVal;
private:
~RefCounter() { }
};
/*
* Test we should copy instead of move in NonExclusive mode
* for each listener must get a copy.
*/
TEST(MediaEventSource, NoMove)
{
RefPtr<TaskQueue> queue = new TaskQueue(
GetMediaThreadPool(MediaThreadType::PLAYBACK));
MediaEventProducer<RefPtr<RefCounter>> source;
auto func1 = [] (RefPtr<RefCounter>&& aEvent) {
EXPECT_EQ(aEvent->mVal, 20);
};
auto func2 = [] (RefPtr<RefCounter>&& aEvent) {
EXPECT_EQ(aEvent->mVal, 20);
};
MediaEventListener listener1 = source.Connect(queue, func1);
MediaEventListener listener2 = source.Connect(queue, func2);
// We should copy this rvalue instead of move it in NonExclusive mode.
RefPtr<RefCounter> val = new RefCounter(20);
source.Notify(Move(val));
queue->BeginShutdown();
queue->AwaitShutdownAndIdle();
listener1.Disconnect();
listener2.Disconnect();
}