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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 // is itself blocked on sending a sync message, not when other channels are. | 83 // is itself blocked on sending a sync message, not when other channels are. |
84 // | 84 // |
85 // Normally, any unblocking message coming from any channel can be dispatched | 85 // Normally, any unblocking message coming from any channel can be dispatched |
86 // when any (possibly other) channel is blocked on sending a message. This is | 86 // when any (possibly other) channel is blocked on sending a message. This is |
87 // needed in some cases to unblock certain loops (e.g. necessary when some | 87 // needed in some cases to unblock certain loops (e.g. necessary when some |
88 // processes share a window hierarchy), but may cause re-entrancy issues in | 88 // processes share a window hierarchy), but may cause re-entrancy issues in |
89 // some cases where such loops are not possible. This flags allows the tagging | 89 // some cases where such loops are not possible. This flags allows the tagging |
90 // of some particular channels to not re-enter in such cases. | 90 // of some particular channels to not re-enter in such cases. |
91 void SetRestrictDispatchToSameChannel(bool value); | 91 void SetRestrictDispatchToSameChannel(bool value); |
92 | 92 |
93 // Interface for a filter to be imposed on outgoing messages which can | |
94 // re-write the message. Used mainly for testing. | |
95 class OutgoingMessageFilter { | |
96 public: | |
97 virtual ~OutgoingMessageFilter() = 0; | |
98 | |
99 // Returns a re-written message, freeing the original, or simply the | |
100 // original unchanged if no rewrite indicated. | |
101 virtual Message *Rewrite(Message *message) = 0; | |
102 }; | |
103 | |
104 void set_outgoing_message_filter(OutgoingMessageFilter *filter) { | |
105 outgoing_message_filter_ = filter; | |
106 } | |
107 | |
93 protected: | 108 protected: |
94 class ReceivedSyncMsgQueue; | 109 class ReceivedSyncMsgQueue; |
95 friend class ReceivedSyncMsgQueue; | 110 friend class ReceivedSyncMsgQueue; |
96 | 111 |
97 // SyncContext holds the per object data for SyncChannel, so that SyncChannel | 112 // SyncContext holds the per object data for SyncChannel, so that SyncChannel |
98 // can be deleted while it's being used in a different thread. See | 113 // can be deleted while it's being used in a different thread. See |
99 // ChannelProxy::Context for more information. | 114 // ChannelProxy::Context for more information. |
100 class SyncContext : public Context, | 115 class SyncContext : public Context, |
101 public base::WaitableEventWatcher::Delegate { | 116 public base::WaitableEventWatcher::Delegate { |
102 public: | 117 public: |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 | 176 |
162 typedef std::deque<PendingSyncMsg> PendingSyncMessageQueue; | 177 typedef std::deque<PendingSyncMsg> PendingSyncMessageQueue; |
163 PendingSyncMessageQueue deserializers_; | 178 PendingSyncMessageQueue deserializers_; |
164 base::Lock deserializers_lock_; | 179 base::Lock deserializers_lock_; |
165 | 180 |
166 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_; | 181 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_; |
167 | 182 |
168 base::WaitableEvent* shutdown_event_; | 183 base::WaitableEvent* shutdown_event_; |
169 base::WaitableEventWatcher shutdown_watcher_; | 184 base::WaitableEventWatcher shutdown_watcher_; |
170 bool restrict_dispatch_; | 185 bool restrict_dispatch_; |
186 | |
jam
2011/04/27 21:58:07
nit
| |
171 }; | 187 }; |
172 | 188 |
173 private: | 189 private: |
174 // WaitableEventWatcher::Delegate implementation. | 190 // WaitableEventWatcher::Delegate implementation. |
175 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg); | 191 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg); |
176 | 192 |
177 SyncContext* sync_context() { | 193 SyncContext* sync_context() { |
178 return reinterpret_cast<SyncContext*>(context()); | 194 return reinterpret_cast<SyncContext*>(context()); |
179 } | 195 } |
180 | 196 |
181 // Both these functions wait for a reply, timeout or process shutdown. The | 197 // Both these functions wait for a reply, timeout or process shutdown. The |
182 // latter one also runs a nested message loop in the meantime. | 198 // latter one also runs a nested message loop in the meantime. |
183 static void WaitForReply( | 199 static void WaitForReply( |
184 SyncContext* context, base::WaitableEvent* pump_messages_event); | 200 SyncContext* context, base::WaitableEvent* pump_messages_event); |
185 | 201 |
186 // Runs a nested message loop until a reply arrives, times out, or the process | 202 // Runs a nested message loop until a reply arrives, times out, or the process |
187 // shuts down. | 203 // shuts down. |
188 static void WaitForReplyWithNestedMessageLoop(SyncContext* context); | 204 static void WaitForReplyWithNestedMessageLoop(SyncContext* context); |
189 | 205 |
190 bool sync_messages_with_no_timeout_allowed_; | 206 bool sync_messages_with_no_timeout_allowed_; |
207 OutgoingMessageFilter *outgoing_message_filter_; | |
191 | 208 |
192 // Used to signal events between the IPC and listener threads. | 209 // Used to signal events between the IPC and listener threads. |
193 base::WaitableEventWatcher dispatch_watcher_; | 210 base::WaitableEventWatcher dispatch_watcher_; |
194 | 211 |
195 DISALLOW_COPY_AND_ASSIGN(SyncChannel); | 212 DISALLOW_COPY_AND_ASSIGN(SyncChannel); |
196 }; | 213 }; |
197 | 214 |
198 } // namespace IPC | 215 } // namespace IPC |
199 | 216 |
200 #endif // IPC_IPC_SYNC_SENDER_H__ | 217 #endif // IPC_IPC_SYNC_SENDER_H__ |
OLD | NEW |