Bug 1242609 - Implement PeekMessage to get some messages earlier. r?billm
MozReview-Commit-ID: KbRiPTDRJmp
--- a/ipc/glue/MessageChannel.cpp
+++ b/ipc/glue/MessageChannel.cpp
@@ -971,16 +971,27 @@ MessageChannel::OnMessageReceivedFromLin
// If we compressed away the previous message, we'll re-use
// its pending task.
mWorkerLoop->PostTask(FROM_HERE, new DequeueTask(mDequeueOneTask));
}
}
}
void
+MessageChannel::PeekMessages(msgid_t aMsgId, mozilla::function<void(const Message& aMsg)> aInvoke) {
+ for (MessageQueue::iterator it = mPending.begin(); it != mPending.end(); it++) {
+ Message &msg = *it;
+
+ if (msg.type() == aMsgId) {
+ aInvoke(msg);
+ }
+ }
+}
+
+void
MessageChannel::ProcessPendingRequests(AutoEnterTransaction& aTransaction)
{
IPC_LOG("ProcessPendingRequests for seqno=%d, xid=%d",
aTransaction.SequenceNumber(), aTransaction.TransactionID());
// Loop until there aren't any more priority messages to process.
for (;;) {
// If we canceled during ProcessPendingRequest, then we need to leave
--- a/ipc/glue/MessageChannel.h
+++ b/ipc/glue/MessageChannel.h
@@ -6,16 +6,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef ipc_glue_MessageChannel_h
#define ipc_glue_MessageChannel_h 1
#include "base/basictypes.h"
#include "base/message_loop.h"
+#include "mozilla/Function.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/Monitor.h"
#include "mozilla/Vector.h"
#include "mozilla/WeakPtr.h"
#if defined(OS_WIN)
#include "mozilla/ipc/Neutering.h"
#endif // defined(OS_WIN)
#include "mozilla/ipc/Transport.h"
@@ -104,16 +105,21 @@ class MessageChannel : HasResultCodes
void CloseWithTimeout();
void SetAbortOnError(bool abort)
{
mAbortOnError = abort;
}
+ // Call aInvoke for each pending message of type aId.
+ // XXX: You must get permission from an IPC peer to use this function
+ // since it requires custom deserialization and re-orders events.
+ void PeekMessages(Message::msgid_t aId, mozilla::function<void(const Message& aMsg)> aInvoke);
+
// Misc. behavioral traits consumers can request for this channel
enum ChannelFlags {
REQUIRE_DEFAULT = 0,
// Windows: if this channel operates on the UI thread, indicates
// WindowsMessageLoop code should enable deferred native message
// handling to prevent deadlocks. Should only be used for protocols
// that manage child processes which might create native UI, like
// plugins.