Add sync context dispatch restriction.

This adds a way to restrict on a per-channel basis that incoming messages may only be dispatched when that particular channel is sending a sync message (or in a message loop).

It does so to the PPAPI channels, which may not introduce a sync dependency circle.

BUG=chromiumos:13821
TEST=news.google.com with Pepper Flash (see bug)

Review URL: http://codereview.chromium.org/6810013

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80892 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/ipc/ipc_sync_channel.h b/ipc/ipc_sync_channel.h
index 0386b8f..e7ff051 100644
--- a/ipc/ipc_sync_channel.h
+++ b/ipc/ipc_sync_channel.h
@@ -51,6 +51,17 @@
     sync_messages_with_no_timeout_allowed_ = value;
   }
 
+  // Sets this channel to only dispatch its incoming unblocking messages when it
+  // is itself blocked on sending a sync message, not when other channels are.
+  //
+  // Normally, any unblocking message coming from any channel can be dispatched
+  // when any (possibly other) channel is blocked on sending a message. This is
+  // needed in some cases to unblock certain loops (e.g. necessary when some
+  // processes share a window hierarchy), but may cause re-entrancy issues in
+  // some cases where such loops are not possible. This flags allows the tagging
+  // of some particular channels to not re-enter in such cases.
+  void SetRestrictDispatchToSameChannel(bool value);
+
  protected:
   class ReceivedSyncMsgQueue;
   friend class ReceivedSyncMsgQueue;
@@ -98,6 +109,9 @@
       return received_sync_msgs_;
     }
 
+    void set_restrict_dispatch(bool value) { restrict_dispatch_ = value; }
+    bool restrict_dispatch() const { return restrict_dispatch_; }
+
    private:
     ~SyncContext();
     // ChannelProxy methods that we override.
@@ -125,6 +139,7 @@
 
     base::WaitableEvent* shutdown_event_;
     base::WaitableEventWatcher shutdown_watcher_;
+    bool restrict_dispatch_;
   };
 
  private: