OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_CHANNEL_H_ | 5 #ifndef IPC_IPC_SYNC_CHANNEL_H_ |
6 #define IPC_IPC_SYNC_CHANNEL_H_ | 6 #define IPC_IPC_SYNC_CHANNEL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <deque> | 9 #include <deque> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 namespace IPC { | 23 namespace IPC { |
24 | 24 |
25 class SyncMessage; | 25 class SyncMessage; |
26 | 26 |
27 // This is similar to ChannelProxy, with the added feature of supporting sending | 27 // This is similar to ChannelProxy, with the added feature of supporting sending |
28 // synchronous messages. | 28 // synchronous messages. |
29 // | 29 // |
30 // Overview of how the sync channel works | 30 // Overview of how the sync channel works |
31 // -------------------------------------- | 31 // -------------------------------------- |
32 // When the sending thread sends a synchronous message, we create a bunch | 32 // When the sending thread sends a synchronous message, we create a bunch |
33 // of tracking info (created in SendWithTimeout, stored in the PendingSyncMsg | 33 // of tracking info (created in Send, stored in the PendingSyncMsg |
34 // structure) associated with the message that we identify by the unique | 34 // structure) associated with the message that we identify by the unique |
35 // "MessageId" on the SyncMessage. Among the things we save is the | 35 // "MessageId" on the SyncMessage. Among the things we save is the |
36 // "Deserializer" which is provided by the sync message. This object is in | 36 // "Deserializer" which is provided by the sync message. This object is in |
37 // charge of reading the parameters from the reply message and putting them in | 37 // charge of reading the parameters from the reply message and putting them in |
38 // the output variables provided by its caller. | 38 // the output variables provided by its caller. |
39 // | 39 // |
40 // The info gets stashed in a queue since we could have a nested stack of sync | 40 // The info gets stashed in a queue since we could have a nested stack of sync |
41 // messages (each side could send sync messages in response to sync messages, | 41 // messages (each side could send sync messages in response to sync messages, |
42 // so it works like calling a function). The message is sent to the I/O thread | 42 // so it works like calling a function). The message is sent to the I/O thread |
43 // for dispatch and the original thread blocks waiting for the reply. | 43 // for dispatch and the original thread blocks waiting for the reply. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 // Creates an uninitialized sync channel. Call ChannelProxy::Init to | 76 // Creates an uninitialized sync channel. Call ChannelProxy::Init to |
77 // initialize the channel. This two-step setup allows message filters to be | 77 // initialize the channel. This two-step setup allows message filters to be |
78 // added before any messages are sent or received. | 78 // added before any messages are sent or received. |
79 SyncChannel(Listener* listener, | 79 SyncChannel(Listener* listener, |
80 base::SingleThreadTaskRunner* ipc_task_runner, | 80 base::SingleThreadTaskRunner* ipc_task_runner, |
81 base::WaitableEvent* shutdown_event); | 81 base::WaitableEvent* shutdown_event); |
82 | 82 |
83 virtual ~SyncChannel(); | 83 virtual ~SyncChannel(); |
84 | 84 |
85 virtual bool Send(Message* message) OVERRIDE; | 85 virtual bool Send(Message* message) OVERRIDE; |
86 virtual bool SendWithTimeout(Message* message, int timeout_ms); | |
87 | |
88 // Whether we allow sending messages with no time-out. | |
89 void set_sync_messages_with_no_timeout_allowed(bool value) { | |
90 sync_messages_with_no_timeout_allowed_ = value; | |
91 } | |
92 | 86 |
93 // Sets the dispatch group for this channel, to only allow re-entrant dispatch | 87 // Sets the dispatch group for this channel, to only allow re-entrant dispatch |
94 // of messages to other channels in the same group. | 88 // of messages to other channels in the same group. |
95 // | 89 // |
96 // Normally, any unblocking message coming from any channel can be dispatched | 90 // Normally, any unblocking message coming from any channel can be dispatched |
97 // when any (possibly other) channel is blocked on sending a message. This is | 91 // when any (possibly other) channel is blocked on sending a message. This is |
98 // needed in some cases to unblock certain loops (e.g. necessary when some | 92 // needed in some cases to unblock certain loops (e.g. necessary when some |
99 // processes share a window hierarchy), but may cause re-entrancy issues in | 93 // processes share a window hierarchy), but may cause re-entrancy issues in |
100 // some cases where such loops are not possible. This flags allows the tagging | 94 // some cases where such loops are not possible. This flags allows the tagging |
101 // of some particular channels to only re-enter in known correct cases. | 95 // of some particular channels to only re-enter in known correct cases. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 static void WaitForReply( | 199 static void WaitForReply( |
206 SyncContext* context, base::WaitableEvent* pump_messages_event); | 200 SyncContext* context, base::WaitableEvent* pump_messages_event); |
207 | 201 |
208 // 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 |
209 // shuts down. | 203 // shuts down. |
210 static void WaitForReplyWithNestedMessageLoop(SyncContext* context); | 204 static void WaitForReplyWithNestedMessageLoop(SyncContext* context); |
211 | 205 |
212 // Starts the dispatch watcher. | 206 // Starts the dispatch watcher. |
213 void StartWatching(); | 207 void StartWatching(); |
214 | 208 |
215 bool sync_messages_with_no_timeout_allowed_; | |
216 | |
217 // Used to signal events between the IPC and listener threads. | 209 // Used to signal events between the IPC and listener threads. |
218 base::WaitableEventWatcher dispatch_watcher_; | 210 base::WaitableEventWatcher dispatch_watcher_; |
219 base::WaitableEventWatcher::EventCallback dispatch_watcher_callback_; | 211 base::WaitableEventWatcher::EventCallback dispatch_watcher_callback_; |
220 | 212 |
221 DISALLOW_COPY_AND_ASSIGN(SyncChannel); | 213 DISALLOW_COPY_AND_ASSIGN(SyncChannel); |
222 }; | 214 }; |
223 | 215 |
224 } // namespace IPC | 216 } // namespace IPC |
225 | 217 |
226 #endif // IPC_IPC_SYNC_CHANNEL_H_ | 218 #endif // IPC_IPC_SYNC_CHANNEL_H_ |
OLD | NEW |