Bug 1242609 - Implement PeekMessage to get some messages earlier. r?billm draft
authorBenoit Girard <b56girard@gmail.com>
Mon, 14 Mar 2016 11:22:32 -0400
changeset 339958 07b2350165636e9eddeb9904e7571fa6218a744e
parent 339874 f0c0480732d36153e8839c7f17394d45f679f87d
child 339959 6a7c97e14cae28ae06372a83b6266ae5c2ae8f25
child 339972 7ac16df5c769fb60f438f4087f760d4d00af56a9
push id12849
push userb56girard@gmail.com
push dateMon, 14 Mar 2016 15:39:33 +0000
reviewersbillm
bugs1242609
milestone48.0a1
Bug 1242609 - Implement PeekMessage to get some messages earlier. r?billm MozReview-Commit-ID: KbRiPTDRJmp
ipc/glue/MessageChannel.cpp
ipc/glue/MessageChannel.h
--- 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.