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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 // is running and it's used to send a message, then it will use the invalid | 59 // is running and it's used to send a message, then it will use the invalid |
60 // message loop pointer to proxy it to the ipc thread. | 60 // message loop pointer to proxy it to the ipc thread. |
61 class IPC_EXPORT SyncChannel : public ChannelProxy { | 61 class IPC_EXPORT SyncChannel : public ChannelProxy { |
62 public: | 62 public: |
63 enum RestrictDispatchGroup { | 63 enum RestrictDispatchGroup { |
64 kRestrictDispatchGroup_None = 0, | 64 kRestrictDispatchGroup_None = 0, |
65 }; | 65 }; |
66 | 66 |
67 // Creates and initializes a sync channel. If create_pipe_now is specified, | 67 // Creates and initializes a sync channel. If create_pipe_now is specified, |
68 // the channel will be initialized synchronously. | 68 // the channel will be initialized synchronously. |
69 // The naming pattern follows IPC::Channel. | 69 SyncChannel(const IPC::ChannelHandle& channel_handle, |
70 static scoped_ptr<SyncChannel> CreateClient( | 70 Channel::Mode mode, |
71 const IPC::ChannelHandle& channel_handle, | 71 Listener* listener, |
72 Listener* listener, | 72 base::SingleThreadTaskRunner* ipc_task_runner, |
73 base::SingleThreadTaskRunner* ipc_task_runner, | 73 bool create_pipe_now, |
74 bool create_pipe_now, | 74 base::WaitableEvent* shutdown_event); |
75 base::WaitableEvent* shutdown_event); | |
76 | |
77 static scoped_ptr<SyncChannel> CreateServer( | |
78 const IPC::ChannelHandle& channel_handle, | |
79 Listener* listener, | |
80 base::SingleThreadTaskRunner* ipc_task_runner, | |
81 bool create_pipe_now, | |
82 base::WaitableEvent* shutdown_event); | |
83 | |
84 static scoped_ptr<SyncChannel> CreateNamedClient( | |
85 const IPC::ChannelHandle& channel_handle, | |
86 Listener* listener, | |
87 base::SingleThreadTaskRunner* ipc_task_runner, | |
88 bool create_pipe_now, | |
89 base::WaitableEvent* shutdown_event); | |
90 | |
91 static scoped_ptr<SyncChannel> CreateNamedServer( | |
92 const IPC::ChannelHandle& channel_handle, | |
93 Listener* listener, | |
94 base::SingleThreadTaskRunner* ipc_task_runner, | |
95 bool create_pipe_now, | |
96 base::WaitableEvent* shutdown_event); | |
97 | 75 |
98 // Creates an uninitialized sync channel. Call ChannelProxy::Init to | 76 // Creates an uninitialized sync channel. Call ChannelProxy::Init to |
99 // 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 |
100 // added before any messages are sent or received. | 78 // added before any messages are sent or received. |
101 static scoped_ptr<SyncChannel> Create( | 79 SyncChannel(Listener* listener, |
102 Listener* listener, | 80 base::SingleThreadTaskRunner* ipc_task_runner, |
103 base::SingleThreadTaskRunner* ipc_task_runner, | 81 base::WaitableEvent* shutdown_event); |
104 base::WaitableEvent* shutdown_event); | |
105 | 82 |
106 virtual ~SyncChannel(); | 83 virtual ~SyncChannel(); |
107 | 84 |
108 virtual bool Send(Message* message) OVERRIDE; | 85 virtual bool Send(Message* message) OVERRIDE; |
109 | 86 |
110 // 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 |
111 // of messages to other channels in the same group. | 88 // of messages to other channels in the same group. |
112 // | 89 // |
113 // Normally, any unblocking message coming from any channel can be dispatched | 90 // Normally, any unblocking message coming from any channel can be dispatched |
114 // 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 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 181 |
205 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_; | 182 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_; |
206 | 183 |
207 base::WaitableEvent* shutdown_event_; | 184 base::WaitableEvent* shutdown_event_; |
208 base::WaitableEventWatcher shutdown_watcher_; | 185 base::WaitableEventWatcher shutdown_watcher_; |
209 base::WaitableEventWatcher::EventCallback shutdown_watcher_callback_; | 186 base::WaitableEventWatcher::EventCallback shutdown_watcher_callback_; |
210 int restrict_dispatch_group_; | 187 int restrict_dispatch_group_; |
211 }; | 188 }; |
212 | 189 |
213 private: | 190 private: |
214 SyncChannel(Listener* listener, | |
215 base::SingleThreadTaskRunner* ipc_task_runner, | |
216 base::WaitableEvent* shutdown_event); | |
217 | |
218 void OnWaitableEventSignaled(base::WaitableEvent* arg); | 191 void OnWaitableEventSignaled(base::WaitableEvent* arg); |
219 | 192 |
220 SyncContext* sync_context() { | 193 SyncContext* sync_context() { |
221 return reinterpret_cast<SyncContext*>(context()); | 194 return reinterpret_cast<SyncContext*>(context()); |
222 } | 195 } |
223 | 196 |
224 // 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 |
225 // latter one also runs a nested message loop in the meantime. | 198 // latter one also runs a nested message loop in the meantime. |
226 static void WaitForReply( | 199 static void WaitForReply( |
227 SyncContext* context, base::WaitableEvent* pump_messages_event); | 200 SyncContext* context, base::WaitableEvent* pump_messages_event); |
228 | 201 |
229 // 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 |
230 // shuts down. | 203 // shuts down. |
231 static void WaitForReplyWithNestedMessageLoop(SyncContext* context); | 204 static void WaitForReplyWithNestedMessageLoop(SyncContext* context); |
232 | 205 |
233 // Starts the dispatch watcher. | 206 // Starts the dispatch watcher. |
234 void StartWatching(); | 207 void StartWatching(); |
235 | 208 |
236 // Used to signal events between the IPC and listener threads. | 209 // Used to signal events between the IPC and listener threads. |
237 base::WaitableEventWatcher dispatch_watcher_; | 210 base::WaitableEventWatcher dispatch_watcher_; |
238 base::WaitableEventWatcher::EventCallback dispatch_watcher_callback_; | 211 base::WaitableEventWatcher::EventCallback dispatch_watcher_callback_; |
239 | 212 |
240 DISALLOW_COPY_AND_ASSIGN(SyncChannel); | 213 DISALLOW_COPY_AND_ASSIGN(SyncChannel); |
241 }; | 214 }; |
242 | 215 |
243 } // namespace IPC | 216 } // namespace IPC |
244 | 217 |
245 #endif // IPC_IPC_SYNC_CHANNEL_H_ | 218 #endif // IPC_IPC_SYNC_CHANNEL_H_ |
OLD | NEW |