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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 // Creates an uninitialized sync channel. Call ChannelProxy::Init to | 74 // Creates an uninitialized sync channel. Call ChannelProxy::Init to |
75 // initialize the channel. This two-step setup allows message filters to be | 75 // initialize the channel. This two-step setup allows message filters to be |
76 // added before any messages are sent or received. | 76 // added before any messages are sent or received. |
77 SyncChannel(Channel::Listener* listener, | 77 SyncChannel(Channel::Listener* listener, |
78 base::MessageLoopProxy* ipc_message_loop, | 78 base::MessageLoopProxy* ipc_message_loop, |
79 base::WaitableEvent* shutdown_event); | 79 base::WaitableEvent* shutdown_event); |
80 | 80 |
81 virtual ~SyncChannel(); | 81 virtual ~SyncChannel(); |
82 | 82 |
83 virtual bool Send(Message* message); | 83 virtual bool Send(Message* message) OVERRIDE; |
84 virtual bool SendWithTimeout(Message* message, int timeout_ms); | 84 virtual bool SendWithTimeout(Message* message, int timeout_ms); |
85 | 85 |
86 // Whether we allow sending messages with no time-out. | 86 // Whether we allow sending messages with no time-out. |
87 void set_sync_messages_with_no_timeout_allowed(bool value) { | 87 void set_sync_messages_with_no_timeout_allowed(bool value) { |
88 sync_messages_with_no_timeout_allowed_ = value; | 88 sync_messages_with_no_timeout_allowed_ = value; |
89 } | 89 } |
90 | 90 |
91 // Sets this channel to only dispatch its incoming unblocking messages when it | 91 // Sets this channel to only dispatch its incoming unblocking messages when it |
92 // is itself blocked on sending a sync message, not when other channels are. | 92 // is itself blocked on sending a sync message, not when other channels are. |
93 // | 93 // |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 } | 147 } |
148 | 148 |
149 void set_restrict_dispatch(bool value) { restrict_dispatch_ = value; } | 149 void set_restrict_dispatch(bool value) { restrict_dispatch_ = value; } |
150 bool restrict_dispatch() const { return restrict_dispatch_; } | 150 bool restrict_dispatch() const { return restrict_dispatch_; } |
151 | 151 |
152 private: | 152 private: |
153 virtual ~SyncContext(); | 153 virtual ~SyncContext(); |
154 // ChannelProxy methods that we override. | 154 // ChannelProxy methods that we override. |
155 | 155 |
156 // Called on the listener thread. | 156 // Called on the listener thread. |
157 virtual void Clear(); | 157 virtual void Clear() OVERRIDE; |
158 | 158 |
159 // Called on the IPC thread. | 159 // Called on the IPC thread. |
160 virtual bool OnMessageReceived(const Message& msg); | 160 virtual bool OnMessageReceived(const Message& msg) OVERRIDE; |
161 virtual void OnChannelError(); | 161 virtual void OnChannelError() OVERRIDE; |
162 virtual void OnChannelOpened(); | 162 virtual void OnChannelOpened() OVERRIDE; |
163 virtual void OnChannelClosed(); | 163 virtual void OnChannelClosed() OVERRIDE; |
164 | 164 |
165 // Cancels all pending Send calls. | 165 // Cancels all pending Send calls. |
166 void CancelPendingSends(); | 166 void CancelPendingSends(); |
167 | 167 |
168 // WaitableEventWatcher::Delegate implementation. | 168 // WaitableEventWatcher::Delegate implementation. |
169 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg); | 169 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg) OVERRIDE; |
170 | 170 |
171 typedef std::deque<PendingSyncMsg> PendingSyncMessageQueue; | 171 typedef std::deque<PendingSyncMsg> PendingSyncMessageQueue; |
172 PendingSyncMessageQueue deserializers_; | 172 PendingSyncMessageQueue deserializers_; |
173 base::Lock deserializers_lock_; | 173 base::Lock deserializers_lock_; |
174 | 174 |
175 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_; | 175 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_; |
176 | 176 |
177 base::WaitableEvent* shutdown_event_; | 177 base::WaitableEvent* shutdown_event_; |
178 base::WaitableEventWatcher shutdown_watcher_; | 178 base::WaitableEventWatcher shutdown_watcher_; |
179 bool restrict_dispatch_; | 179 bool restrict_dispatch_; |
180 }; | 180 }; |
181 | 181 |
182 private: | 182 private: |
183 // WaitableEventWatcher::Delegate implementation. | 183 // WaitableEventWatcher::Delegate implementation. |
184 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg); | 184 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg) OVERRIDE; |
185 | 185 |
186 SyncContext* sync_context() { | 186 SyncContext* sync_context() { |
187 return reinterpret_cast<SyncContext*>(context()); | 187 return reinterpret_cast<SyncContext*>(context()); |
188 } | 188 } |
189 | 189 |
190 // 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 |
191 // latter one also runs a nested message loop in the meantime. | 191 // latter one also runs a nested message loop in the meantime. |
192 static void WaitForReply( | 192 static void WaitForReply( |
193 SyncContext* context, base::WaitableEvent* pump_messages_event); | 193 SyncContext* context, base::WaitableEvent* pump_messages_event); |
194 | 194 |
195 // 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 |
196 // shuts down. | 196 // shuts down. |
197 static void WaitForReplyWithNestedMessageLoop(SyncContext* context); | 197 static void WaitForReplyWithNestedMessageLoop(SyncContext* context); |
198 | 198 |
199 // Starts the dispatch watcher. | 199 // Starts the dispatch watcher. |
200 void StartWatching(); | 200 void StartWatching(); |
201 | 201 |
202 bool sync_messages_with_no_timeout_allowed_; | 202 bool sync_messages_with_no_timeout_allowed_; |
203 | 203 |
204 // Used to signal events between the IPC and listener threads. | 204 // Used to signal events between the IPC and listener threads. |
205 base::WaitableEventWatcher dispatch_watcher_; | 205 base::WaitableEventWatcher dispatch_watcher_; |
206 | 206 |
207 DISALLOW_COPY_AND_ASSIGN(SyncChannel); | 207 DISALLOW_COPY_AND_ASSIGN(SyncChannel); |
208 }; | 208 }; |
209 | 209 |
210 } // namespace IPC | 210 } // namespace IPC |
211 | 211 |
212 #endif // IPC_IPC_SYNC_CHANNEL_H_ | 212 #endif // IPC_IPC_SYNC_CHANNEL_H_ |
OLD | NEW |