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