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_CHANNEL_H_ | 5 #ifndef IPC_IPC_SYNC_CHANNEL_H_ |
6 #define IPC_IPC_SYNC_CHANNEL_H_ | 6 #define IPC_IPC_SYNC_CHANNEL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <deque> | 10 #include <deque> |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // be dispatched in a reentrant manner to avoid deadlock. | 55 // be dispatched in a reentrant manner to avoid deadlock. |
56 // | 56 // |
57 // | 57 // |
58 // Note that care must be taken that the lifetime of the ipc_thread argument | 58 // Note that care must be taken that the lifetime of the ipc_thread argument |
59 // is more than this object. If the message loop goes away while this object | 59 // is more than this object. If the message loop goes away while this object |
60 // is running and it's used to send a message, then it will use the invalid | 60 // is running and it's used to send a message, then it will use the invalid |
61 // message loop pointer to proxy it to the ipc thread. | 61 // message loop pointer to proxy it to the ipc thread. |
62 class IPC_EXPORT SyncChannel : public ChannelProxy, | 62 class IPC_EXPORT SyncChannel : public ChannelProxy, |
63 public base::WaitableEventWatcher::Delegate { | 63 public base::WaitableEventWatcher::Delegate { |
64 public: | 64 public: |
| 65 // Creates and initializes a sync channel. If create_pipe_now is specified, |
| 66 // the channel will be initialized synchronously. |
65 SyncChannel(const IPC::ChannelHandle& channel_handle, | 67 SyncChannel(const IPC::ChannelHandle& channel_handle, |
66 Channel::Mode mode, | 68 Channel::Mode mode, |
67 Channel::Listener* listener, | 69 Channel::Listener* listener, |
68 base::MessageLoopProxy* ipc_message_loop, | 70 base::MessageLoopProxy* ipc_message_loop, |
69 bool create_pipe_now, | 71 bool create_pipe_now, |
70 base::WaitableEvent* shutdown_event); | 72 base::WaitableEvent* shutdown_event); |
| 73 |
| 74 // Creates an uninitialized sync channel. Call ChannelProxy::Init to |
| 75 // initialize the channel. This two-step setup allows message filters to be |
| 76 // added before any messages are sent or received. |
| 77 SyncChannel(Channel::Listener* listener, |
| 78 base::MessageLoopProxy* ipc_message_loop, |
| 79 base::WaitableEvent* shutdown_event); |
| 80 |
71 virtual ~SyncChannel(); | 81 virtual ~SyncChannel(); |
72 | 82 |
73 virtual bool Send(Message* message); | 83 virtual bool Send(Message* message); |
74 virtual bool SendWithTimeout(Message* message, int timeout_ms); | 84 virtual bool SendWithTimeout(Message* message, int timeout_ms); |
75 | 85 |
76 // Whether we allow sending messages with no time-out. | 86 // Whether we allow sending messages with no time-out. |
77 void set_sync_messages_with_no_timeout_allowed(bool value) { | 87 void set_sync_messages_with_no_timeout_allowed(bool value) { |
78 sync_messages_with_no_timeout_allowed_ = value; | 88 sync_messages_with_no_timeout_allowed_ = value; |
79 } | 89 } |
80 | 90 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 189 |
180 // Both these functions wait for a reply, timeout or process shutdown. The | 190 // Both these functions wait for a reply, timeout or process shutdown. The |
181 // latter one also runs a nested message loop in the meantime. | 191 // latter one also runs a nested message loop in the meantime. |
182 static void WaitForReply( | 192 static void WaitForReply( |
183 SyncContext* context, base::WaitableEvent* pump_messages_event); | 193 SyncContext* context, base::WaitableEvent* pump_messages_event); |
184 | 194 |
185 // Runs a nested message loop until a reply arrives, times out, or the process | 195 // Runs a nested message loop until a reply arrives, times out, or the process |
186 // shuts down. | 196 // shuts down. |
187 static void WaitForReplyWithNestedMessageLoop(SyncContext* context); | 197 static void WaitForReplyWithNestedMessageLoop(SyncContext* context); |
188 | 198 |
| 199 // Starts the dispatch watcher. |
| 200 void StartWatching(); |
| 201 |
189 bool sync_messages_with_no_timeout_allowed_; | 202 bool sync_messages_with_no_timeout_allowed_; |
190 | 203 |
191 // Used to signal events between the IPC and listener threads. | 204 // Used to signal events between the IPC and listener threads. |
192 base::WaitableEventWatcher dispatch_watcher_; | 205 base::WaitableEventWatcher dispatch_watcher_; |
193 | 206 |
194 DISALLOW_COPY_AND_ASSIGN(SyncChannel); | 207 DISALLOW_COPY_AND_ASSIGN(SyncChannel); |
195 }; | 208 }; |
196 | 209 |
197 } // namespace IPC | 210 } // namespace IPC |
198 | 211 |
199 #endif // IPC_IPC_SYNC_CHANNEL_H_ | 212 #endif // IPC_IPC_SYNC_CHANNEL_H_ |
OLD | NEW |