Bug 1255968 - Part 1: Let the callback of PeekMessages() to return a boolean to be able to break out the loop. r=dvander
authorTing-Yu Chou <janus926@gmail.com>
Mon, 28 Mar 2016 11:02:18 +0800
changeset 290941 f22a94ef47002817295c234225836dbe2595f5f3
parent 290940 f6306cddab36e0d0ef9b4ad11c3bde27e8d17e1e
child 290942 4de1094b41b27db10a5b0e5683ba4272c505ee9c
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander
bugs1255968
milestone48.0a1
Bug 1255968 - Part 1: Let the callback of PeekMessages() to return a boolean to be able to break out the loop. r=dvander
ipc/glue/MessageChannel.cpp
ipc/glue/MessageChannel.h
layout/base/nsLayoutUtils.cpp
--- a/ipc/glue/MessageChannel.cpp
+++ b/ipc/glue/MessageChannel.cpp
@@ -971,25 +971,25 @@ 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)
+MessageChannel::PeekMessages(msgid_t aMsgId, mozilla::function<bool(const Message& aMsg)> aInvoke)
 {
     MonitorAutoLock lock(*mMonitor);
 
     for (MessageQueue::iterator it = mPending.begin(); it != mPending.end(); it++) {
         Message &msg = *it;
 
-        if (msg.type() == aMsgId) {
-          aInvoke(msg);
+        if (msg.type() == aMsgId && !aInvoke(msg)) {
+            break;
         }
     }
 }
 
 void
 MessageChannel::ProcessPendingRequests(AutoEnterTransaction& aTransaction)
 {
     IPC_LOG("ProcessPendingRequests for seqno=%d, xid=%d",
--- a/ipc/glue/MessageChannel.h
+++ b/ipc/glue/MessageChannel.h
@@ -105,20 +105,20 @@ class MessageChannel : HasResultCodes
 
     void CloseWithTimeout();
 
     void SetAbortOnError(bool abort)
     {
         mAbortOnError = abort;
     }
 
-    // Call aInvoke for each pending message of type aId.
+    // Call aInvoke for each pending message of type aId until it returns false.
     // 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);
+    void PeekMessages(Message::msgid_t aId, mozilla::function<bool(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
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -9053,20 +9053,21 @@ static void UpdateDisplayPortMarginsForP
 }
 
 /* static */ void
 nsLayoutUtils::UpdateDisplayPortMarginsFromPendingMessages() {
   if (mozilla::dom::ContentChild::GetSingleton() &&
       mozilla::dom::ContentChild::GetSingleton()->GetIPCChannel()) {
     mozilla::dom::ContentChild::GetSingleton()->GetIPCChannel()->PeekMessages(
       mozilla::layers::PAPZ::Msg_UpdateFrame__ID,
-      [](const IPC::Message& aMsg) {
+      [](const IPC::Message& aMsg) -> bool {
         void* iter = nullptr;
         FrameMetrics frame;
         if (!IPC::ReadParam(&aMsg, &iter, &frame)) {
           MOZ_ASSERT(false);
-          return;
+          return true;
         }
 
         UpdateDisplayPortMarginsForPendingMetrics(frame);
+        return true;
       });
   }
 }