| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef IPC_IPC_SYNC_SENDER_H__ | 5 #ifndef IPC_IPC_SYNC_SENDER_H__ |
| 6 #define IPC_IPC_SYNC_SENDER_H__ | 6 #define IPC_IPC_SYNC_SENDER_H__ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <deque> | 10 #include <deque> |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 virtual ~SyncChannel(); | 44 virtual ~SyncChannel(); |
| 45 | 45 |
| 46 virtual bool Send(Message* message); | 46 virtual bool Send(Message* message); |
| 47 virtual bool SendWithTimeout(Message* message, int timeout_ms); | 47 virtual bool SendWithTimeout(Message* message, int timeout_ms); |
| 48 | 48 |
| 49 // Whether we allow sending messages with no time-out. | 49 // Whether we allow sending messages with no time-out. |
| 50 void set_sync_messages_with_no_timeout_allowed(bool value) { | 50 void set_sync_messages_with_no_timeout_allowed(bool value) { |
| 51 sync_messages_with_no_timeout_allowed_ = value; | 51 sync_messages_with_no_timeout_allowed_ = value; |
| 52 } | 52 } |
| 53 | 53 |
| 54 // Sets this channel to only dispatch its incoming unblocking messages when it |
| 55 // is itself blocked on sending a sync message, not when other channels are. |
| 56 // |
| 57 // Normally, any unblocking message coming from any channel can be dispatched |
| 58 // when any (possibly other) channel is blocked on sending a message. This is |
| 59 // needed in some cases to unblock certain loops (e.g. necessary when some |
| 60 // processes share a window hierarchy), but may cause re-entrancy issues in |
| 61 // some cases where such loops are not possible. This flags allows the tagging |
| 62 // of some particular channels to not re-enter in such cases. |
| 63 void SetRestrictDispatchToSameChannel(bool value); |
| 64 |
| 54 protected: | 65 protected: |
| 55 class ReceivedSyncMsgQueue; | 66 class ReceivedSyncMsgQueue; |
| 56 friend class ReceivedSyncMsgQueue; | 67 friend class ReceivedSyncMsgQueue; |
| 57 | 68 |
| 58 // SyncContext holds the per object data for SyncChannel, so that SyncChannel | 69 // SyncContext holds the per object data for SyncChannel, so that SyncChannel |
| 59 // can be deleted while it's being used in a different thread. See | 70 // can be deleted while it's being used in a different thread. See |
| 60 // ChannelProxy::Context for more information. | 71 // ChannelProxy::Context for more information. |
| 61 class SyncContext : public Context, | 72 class SyncContext : public Context, |
| 62 public base::WaitableEventWatcher::Delegate { | 73 public base::WaitableEventWatcher::Delegate { |
| 63 public: | 74 public: |
| (...skipping 27 matching lines...) Expand all Loading... |
| 91 // Called on the IPC thread when a sync send that runs a nested message loop | 102 // Called on the IPC thread when a sync send that runs a nested message loop |
| 92 // times out. | 103 // times out. |
| 93 void OnSendTimeout(int message_id); | 104 void OnSendTimeout(int message_id); |
| 94 | 105 |
| 95 base::WaitableEvent* shutdown_event() { return shutdown_event_; } | 106 base::WaitableEvent* shutdown_event() { return shutdown_event_; } |
| 96 | 107 |
| 97 ReceivedSyncMsgQueue* received_sync_msgs() { | 108 ReceivedSyncMsgQueue* received_sync_msgs() { |
| 98 return received_sync_msgs_; | 109 return received_sync_msgs_; |
| 99 } | 110 } |
| 100 | 111 |
| 112 void set_restrict_dispatch(bool value) { restrict_dispatch_ = value; } |
| 113 bool restrict_dispatch() const { return restrict_dispatch_; } |
| 114 |
| 101 private: | 115 private: |
| 102 ~SyncContext(); | 116 ~SyncContext(); |
| 103 // ChannelProxy methods that we override. | 117 // ChannelProxy methods that we override. |
| 104 | 118 |
| 105 // Called on the listener thread. | 119 // Called on the listener thread. |
| 106 virtual void Clear(); | 120 virtual void Clear(); |
| 107 | 121 |
| 108 // Called on the IPC thread. | 122 // Called on the IPC thread. |
| 109 virtual bool OnMessageReceived(const Message& msg); | 123 virtual bool OnMessageReceived(const Message& msg); |
| 110 virtual void OnChannelError(); | 124 virtual void OnChannelError(); |
| 111 virtual void OnChannelOpened(); | 125 virtual void OnChannelOpened(); |
| 112 virtual void OnChannelClosed(); | 126 virtual void OnChannelClosed(); |
| 113 | 127 |
| 114 // Cancels all pending Send calls. | 128 // Cancels all pending Send calls. |
| 115 void CancelPendingSends(); | 129 void CancelPendingSends(); |
| 116 | 130 |
| 117 // WaitableEventWatcher::Delegate implementation. | 131 // WaitableEventWatcher::Delegate implementation. |
| 118 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg); | 132 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg); |
| 119 | 133 |
| 120 typedef std::deque<PendingSyncMsg> PendingSyncMessageQueue; | 134 typedef std::deque<PendingSyncMsg> PendingSyncMessageQueue; |
| 121 PendingSyncMessageQueue deserializers_; | 135 PendingSyncMessageQueue deserializers_; |
| 122 base::Lock deserializers_lock_; | 136 base::Lock deserializers_lock_; |
| 123 | 137 |
| 124 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_; | 138 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_; |
| 125 | 139 |
| 126 base::WaitableEvent* shutdown_event_; | 140 base::WaitableEvent* shutdown_event_; |
| 127 base::WaitableEventWatcher shutdown_watcher_; | 141 base::WaitableEventWatcher shutdown_watcher_; |
| 142 bool restrict_dispatch_; |
| 128 }; | 143 }; |
| 129 | 144 |
| 130 private: | 145 private: |
| 131 // WaitableEventWatcher::Delegate implementation. | 146 // WaitableEventWatcher::Delegate implementation. |
| 132 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg); | 147 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg); |
| 133 | 148 |
| 134 SyncContext* sync_context() { | 149 SyncContext* sync_context() { |
| 135 return reinterpret_cast<SyncContext*>(context()); | 150 return reinterpret_cast<SyncContext*>(context()); |
| 136 } | 151 } |
| 137 | 152 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 148 | 163 |
| 149 // Used to signal events between the IPC and listener threads. | 164 // Used to signal events between the IPC and listener threads. |
| 150 base::WaitableEventWatcher dispatch_watcher_; | 165 base::WaitableEventWatcher dispatch_watcher_; |
| 151 | 166 |
| 152 DISALLOW_COPY_AND_ASSIGN(SyncChannel); | 167 DISALLOW_COPY_AND_ASSIGN(SyncChannel); |
| 153 }; | 168 }; |
| 154 | 169 |
| 155 } // namespace IPC | 170 } // namespace IPC |
| 156 | 171 |
| 157 #endif // IPC_IPC_SYNC_SENDER_H__ | 172 #endif // IPC_IPC_SYNC_SENDER_H__ |
| OLD | NEW |