Bug 1109883 - Allow urgent prio messages to be sent to child (r=dvander)

This commit is contained in:
Bill McCloskey 2014-12-18 17:35:48 -08:00
Родитель 73c276ef13
Коммит 2d185c3202
2 изменённых файлов: 29 добавлений и 4 удалений

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

@ -291,6 +291,8 @@ MessageChannel::MessageChannel(MessageListener *aListener)
mAwaitingSyncReplyPriority(0),
mDispatchingSyncMessage(false),
mDispatchingSyncMessagePriority(0),
mDispatchingAsyncMessage(false),
mDispatchingAsyncMessagePriority(0),
mCurrentTransaction(0),
mTimedOutMessageSeqno(0),
mRecvdErrors(0),
@ -554,10 +556,8 @@ MessageChannel::ShouldDeferMessage(const Message& aMsg)
// Never defer messages that have the highest priority, even async
// ones. This is safe because only the child can send these messages, so
// they can never nest.
if (aMsg.priority() == IPC::Message::PRIORITY_URGENT) {
MOZ_ASSERT(mSide == ParentSide);
if (aMsg.priority() == IPC::Message::PRIORITY_URGENT)
return false;
}
// Unless they're urgent, we always defer async messages.
if (!aMsg.is_sync()) {
@ -736,6 +736,11 @@ MessageChannel::Send(Message* aMsg, Message* aReply)
IPC_ASSERT(mAwaitingSyncReplyPriority <= aMsg->priority(),
"nested sync message sends must be of increasing priority");
IPC_ASSERT(DispatchingSyncMessagePriority() != IPC::Message::PRIORITY_URGENT,
"not allowed to send messages while dispatching urgent messages");
IPC_ASSERT(DispatchingAsyncMessagePriority() != IPC::Message::PRIORITY_URGENT,
"not allowed to send messages while dispatching urgent messages");
nsAutoPtr<Message> msg(aMsg);
if (!Connected()) {
@ -1168,7 +1173,14 @@ MessageChannel::DispatchAsyncMessage(const Message& aMsg)
NS_RUNTIMEABORT("unhandled special message!");
}
MaybeHandleError(mListener->OnMessageReceived(aMsg), aMsg, "DispatchAsyncMessage");
Result rv;
{
int prio = aMsg.priority();
AutoSetValue<bool> async(mDispatchingAsyncMessage, true);
AutoSetValue<int> prioSet(mDispatchingAsyncMessagePriority, prio);
rv = mListener->OnMessageReceived(aMsg);
}
MaybeHandleError(rv, aMsg, "DispatchAsyncMessage");
}
void

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

@ -331,6 +331,16 @@ class MessageChannel : HasResultCodes
return mDispatchingSyncMessagePriority;
}
bool DispatchingAsyncMessage() const {
AssertWorkerThread();
return mDispatchingAsyncMessage;
}
int DispatchingAsyncMessagePriority() const {
AssertWorkerThread();
return mDispatchingAsyncMessagePriority;
}
bool Connected() const;
private:
@ -465,6 +475,9 @@ class MessageChannel : HasResultCodes
bool mDispatchingSyncMessage;
int mDispatchingSyncMessagePriority;
bool mDispatchingAsyncMessage;
int mDispatchingAsyncMessagePriority;
// When we send an urgent request from the parent process, we could race
// with an RPC message that was issued by the child beforehand. In this
// case, if the parent were to wake up while waiting for the urgent reply,