Bug 947632 - Assert that we don't sendSyncMessage while processing a CPOW request (r=dvander)

This commit is contained in:
Bill McCloskey 2013-12-14 15:50:22 -08:00
parent e6246f9341
commit c5e4f93598
2 changed files with 15 additions and 1 deletions

View File

@ -57,6 +57,7 @@ MessageChannel::MessageChannel(MessageListener *aListener)
mPendingRPCReplies(0),
mCurrentRPCTransaction(0),
mDispatchingSyncMessage(false),
mDispatchingUrgentMessageCount(0),
mRemoteStackDepthGuess(false),
mSawInterruptOutMsg(false)
{
@ -416,6 +417,7 @@ MessageChannel::Send(Message* aMsg, Message* aReply)
IPC_ASSERT(aMsg->is_sync(), "can only Send() sync messages here");
IPC_ASSERT(!DispatchingSyncMessage(), "violation of sync handler invariant");
IPC_ASSERT(!DispatchingUrgentMessage(), "sync messages forbidden while handling urgent message");
IPC_ASSERT(!AwaitingSyncReply(), "nested sync messages are not supported");
AutoEnterPendingReply replies(mPendingSyncReplies);
@ -937,7 +939,11 @@ MessageChannel::DispatchUrgentMessage(const Message& aMsg)
Message *reply = nullptr;
if (!MaybeHandleError(mListener->OnCallReceived(aMsg, reply), "DispatchUrgentMessage")) {
mDispatchingUrgentMessageCount++;
Result rv = mListener->OnCallReceived(aMsg, reply);
mDispatchingUrgentMessageCount--;
if (!MaybeHandleError(rv, "DispatchUrgentMessage")) {
delete reply;
reply = new Message();
reply->set_urgent();

View File

@ -384,6 +384,11 @@ class MessageChannel : HasResultCodes
return mDispatchingSyncMessage;
}
// Returns true if we're dispatching an urgent message's callback.
bool DispatchingUrgentMessage() const {
return mDispatchingUrgentMessageCount > 0;
}
bool Connected() const;
private:
@ -576,6 +581,9 @@ class MessageChannel : HasResultCodes
// Set while we are dispatching a synchronous message.
bool mDispatchingSyncMessage;
// Count of the recursion depth of dispatching urgent messages.
size_t mDispatchingUrgentMessageCount;
// Queue of all incoming messages, except for replies to sync and urgent
// messages, which are delivered directly to mRecvd, and any pending urgent
// incall, which is stored in mPendingUrgentRequest.