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 SyncChannel(const IPC::ChannelHandle& channel_handle, | 69 // The naming pattern follows IPC::Channel. |
70 Channel::Mode mode, | 70 static scoped_ptr<SyncChannel> CreateClient( |
71 Listener* listener, | 71 const IPC::ChannelHandle& channel_handle, |
72 base::SingleThreadTaskRunner* ipc_task_runner, | 72 Listener* listener, |
73 bool create_pipe_now, | 73 base::SingleThreadTaskRunner* ipc_task_runner, |
74 base::WaitableEvent* shutdown_event); | 74 bool create_pipe_now, |
| 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); |
75 | 97 |
76 // Creates an uninitialized sync channel. Call ChannelProxy::Init to | 98 // Creates an uninitialized sync channel. Call ChannelProxy::Init to |
77 // initialize the channel. This two-step setup allows message filters to be | 99 // initialize the channel. This two-step setup allows message filters to be |
78 // added before any messages are sent or received. | 100 // added before any messages are sent or received. |
79 SyncChannel(Listener* listener, | 101 static scoped_ptr<SyncChannel> Create( |
80 base::SingleThreadTaskRunner* ipc_task_runner, | 102 Listener* listener, |
81 base::WaitableEvent* shutdown_event); | 103 base::SingleThreadTaskRunner* ipc_task_runner, |
| 104 base::WaitableEvent* shutdown_event); |
82 | 105 |
83 virtual ~SyncChannel(); | 106 virtual ~SyncChannel(); |
84 | 107 |
85 virtual bool Send(Message* message) OVERRIDE; | 108 virtual bool Send(Message* message) OVERRIDE; |
86 | 109 |
87 // Sets the dispatch group for this channel, to only allow re-entrant dispatch | 110 // Sets the dispatch group for this channel, to only allow re-entrant dispatch |
88 // of messages to other channels in the same group. | 111 // of messages to other channels in the same group. |
89 // | 112 // |
90 // Normally, any unblocking message coming from any channel can be dispatched | 113 // Normally, any unblocking message coming from any channel can be dispatched |
91 // when any (possibly other) channel is blocked on sending a message. This is | 114 // 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... |
181 | 204 |
182 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_; | 205 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_; |
183 | 206 |
184 base::WaitableEvent* shutdown_event_; | 207 base::WaitableEvent* shutdown_event_; |
185 base::WaitableEventWatcher shutdown_watcher_; | 208 base::WaitableEventWatcher shutdown_watcher_; |
186 base::WaitableEventWatcher::EventCallback shutdown_watcher_callback_; | 209 base::WaitableEventWatcher::EventCallback shutdown_watcher_callback_; |
187 int restrict_dispatch_group_; | 210 int restrict_dispatch_group_; |
188 }; | 211 }; |
189 | 212 |
190 private: | 213 private: |
| 214 SyncChannel(Listener* listener, |
| 215 base::SingleThreadTaskRunner* ipc_task_runner, |
| 216 base::WaitableEvent* shutdown_event); |
| 217 |
191 void OnWaitableEventSignaled(base::WaitableEvent* arg); | 218 void OnWaitableEventSignaled(base::WaitableEvent* arg); |
192 | 219 |
193 SyncContext* sync_context() { | 220 SyncContext* sync_context() { |
194 return reinterpret_cast<SyncContext*>(context()); | 221 return reinterpret_cast<SyncContext*>(context()); |
195 } | 222 } |
196 | 223 |
197 // Both these functions wait for a reply, timeout or process shutdown. The | 224 // Both these functions wait for a reply, timeout or process shutdown. The |
198 // latter one also runs a nested message loop in the meantime. | 225 // latter one also runs a nested message loop in the meantime. |
199 static void WaitForReply( | 226 static void WaitForReply( |
200 SyncContext* context, base::WaitableEvent* pump_messages_event); | 227 SyncContext* context, base::WaitableEvent* pump_messages_event); |
201 | 228 |
202 // Runs a nested message loop until a reply arrives, times out, or the process | 229 // Runs a nested message loop until a reply arrives, times out, or the process |
203 // shuts down. | 230 // shuts down. |
204 static void WaitForReplyWithNestedMessageLoop(SyncContext* context); | 231 static void WaitForReplyWithNestedMessageLoop(SyncContext* context); |
205 | 232 |
206 // Starts the dispatch watcher. | 233 // Starts the dispatch watcher. |
207 void StartWatching(); | 234 void StartWatching(); |
208 | 235 |
209 // Used to signal events between the IPC and listener threads. | 236 // Used to signal events between the IPC and listener threads. |
210 base::WaitableEventWatcher dispatch_watcher_; | 237 base::WaitableEventWatcher dispatch_watcher_; |
211 base::WaitableEventWatcher::EventCallback dispatch_watcher_callback_; | 238 base::WaitableEventWatcher::EventCallback dispatch_watcher_callback_; |
212 | 239 |
213 DISALLOW_COPY_AND_ASSIGN(SyncChannel); | 240 DISALLOW_COPY_AND_ASSIGN(SyncChannel); |
214 }; | 241 }; |
215 | 242 |
216 } // namespace IPC | 243 } // namespace IPC |
217 | 244 |
218 #endif // IPC_IPC_SYNC_CHANNEL_H_ | 245 #endif // IPC_IPC_SYNC_CHANNEL_H_ |
OLD | NEW |