| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 kRestrictDispatchGroup_None = 0, | 65 kRestrictDispatchGroup_None = 0, |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 // Creates and initializes a sync channel. If create_pipe_now is specified, | 68 // Creates and initializes a sync channel. If create_pipe_now is specified, |
| 69 // the channel will be initialized synchronously. | 69 // the channel will be initialized synchronously. |
| 70 // The naming pattern follows IPC::Channel. | 70 // The naming pattern follows IPC::Channel. |
| 71 static scoped_ptr<SyncChannel> Create( | 71 static scoped_ptr<SyncChannel> Create( |
| 72 const IPC::ChannelHandle& channel_handle, | 72 const IPC::ChannelHandle& channel_handle, |
| 73 IPC::Channel::Mode mode, | 73 IPC::Channel::Mode mode, |
| 74 Listener* listener, | 74 Listener* listener, |
| 75 base::SingleThreadTaskRunner* ipc_task_runner, | 75 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner, |
| 76 bool create_pipe_now, | 76 bool create_pipe_now, |
| 77 base::WaitableEvent* shutdown_event); | 77 base::WaitableEvent* shutdown_event); |
| 78 | 78 |
| 79 static scoped_ptr<SyncChannel> Create( | 79 static scoped_ptr<SyncChannel> Create( |
| 80 scoped_ptr<ChannelFactory> factory, | 80 scoped_ptr<ChannelFactory> factory, |
| 81 Listener* listener, | 81 Listener* listener, |
| 82 base::SingleThreadTaskRunner* ipc_task_runner, | 82 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner, |
| 83 bool create_pipe_now, | 83 bool create_pipe_now, |
| 84 base::WaitableEvent* shutdown_event); | 84 base::WaitableEvent* shutdown_event); |
| 85 | 85 |
| 86 // Creates an uninitialized sync channel. Call ChannelProxy::Init to | 86 // Creates an uninitialized sync channel. Call ChannelProxy::Init to |
| 87 // initialize the channel. This two-step setup allows message filters to be | 87 // initialize the channel. This two-step setup allows message filters to be |
| 88 // added before any messages are sent or received. | 88 // added before any messages are sent or received. |
| 89 static scoped_ptr<SyncChannel> Create( | 89 static scoped_ptr<SyncChannel> Create( |
| 90 Listener* listener, | 90 Listener* listener, |
| 91 base::SingleThreadTaskRunner* ipc_task_runner, | 91 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner, |
| 92 base::WaitableEvent* shutdown_event); | 92 base::WaitableEvent* shutdown_event); |
| 93 | 93 |
| 94 virtual ~SyncChannel(); | 94 virtual ~SyncChannel(); |
| 95 | 95 |
| 96 virtual bool Send(Message* message) OVERRIDE; | 96 virtual bool Send(Message* message) OVERRIDE; |
| 97 | 97 |
| 98 // Sets the dispatch group for this channel, to only allow re-entrant dispatch | 98 // Sets the dispatch group for this channel, to only allow re-entrant dispatch |
| 99 // of messages to other channels in the same group. | 99 // of messages to other channels in the same group. |
| 100 // | 100 // |
| 101 // Normally, any unblocking message coming from any channel can be dispatched | 101 // Normally, any unblocking message coming from any channel can be dispatched |
| (...skipping 12 matching lines...) Expand all Loading... |
| 114 | 114 |
| 115 protected: | 115 protected: |
| 116 class ReceivedSyncMsgQueue; | 116 class ReceivedSyncMsgQueue; |
| 117 friend class ReceivedSyncMsgQueue; | 117 friend class ReceivedSyncMsgQueue; |
| 118 | 118 |
| 119 // SyncContext holds the per object data for SyncChannel, so that SyncChannel | 119 // SyncContext holds the per object data for SyncChannel, so that SyncChannel |
| 120 // can be deleted while it's being used in a different thread. See | 120 // can be deleted while it's being used in a different thread. See |
| 121 // ChannelProxy::Context for more information. | 121 // ChannelProxy::Context for more information. |
| 122 class SyncContext : public Context { | 122 class SyncContext : public Context { |
| 123 public: | 123 public: |
| 124 SyncContext(Listener* listener, | 124 SyncContext( |
| 125 base::SingleThreadTaskRunner* ipc_task_runner, | 125 Listener* listener, |
| 126 base::WaitableEvent* shutdown_event); | 126 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner, |
| 127 base::WaitableEvent* shutdown_event); |
| 127 | 128 |
| 128 // Adds information about an outgoing sync message to the context so that | 129 // Adds information about an outgoing sync message to the context so that |
| 129 // we know how to deserialize the reply. | 130 // we know how to deserialize the reply. |
| 130 void Push(SyncMessage* sync_msg); | 131 void Push(SyncMessage* sync_msg); |
| 131 | 132 |
| 132 // Cleanly remove the top deserializer (and throw it away). Returns the | 133 // Cleanly remove the top deserializer (and throw it away). Returns the |
| 133 // result of the Send call for that message. | 134 // result of the Send call for that message. |
| 134 bool Pop(); | 135 bool Pop(); |
| 135 | 136 |
| 136 // Returns an event that's set when the send is complete, timed out or the | 137 // Returns an event that's set when the send is complete, timed out or the |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 | 193 |
| 193 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_; | 194 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_; |
| 194 | 195 |
| 195 base::WaitableEvent* shutdown_event_; | 196 base::WaitableEvent* shutdown_event_; |
| 196 base::WaitableEventWatcher shutdown_watcher_; | 197 base::WaitableEventWatcher shutdown_watcher_; |
| 197 base::WaitableEventWatcher::EventCallback shutdown_watcher_callback_; | 198 base::WaitableEventWatcher::EventCallback shutdown_watcher_callback_; |
| 198 int restrict_dispatch_group_; | 199 int restrict_dispatch_group_; |
| 199 }; | 200 }; |
| 200 | 201 |
| 201 private: | 202 private: |
| 202 SyncChannel(Listener* listener, | 203 SyncChannel( |
| 203 base::SingleThreadTaskRunner* ipc_task_runner, | 204 Listener* listener, |
| 204 base::WaitableEvent* shutdown_event); | 205 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner, |
| 206 base::WaitableEvent* shutdown_event); |
| 205 | 207 |
| 206 void OnWaitableEventSignaled(base::WaitableEvent* arg); | 208 void OnWaitableEventSignaled(base::WaitableEvent* arg); |
| 207 | 209 |
| 208 SyncContext* sync_context() { | 210 SyncContext* sync_context() { |
| 209 return reinterpret_cast<SyncContext*>(context()); | 211 return reinterpret_cast<SyncContext*>(context()); |
| 210 } | 212 } |
| 211 | 213 |
| 212 // Both these functions wait for a reply, timeout or process shutdown. The | 214 // Both these functions wait for a reply, timeout or process shutdown. The |
| 213 // latter one also runs a nested message loop in the meantime. | 215 // latter one also runs a nested message loop in the meantime. |
| 214 static void WaitForReply( | 216 static void WaitForReply( |
| 215 SyncContext* context, base::WaitableEvent* pump_messages_event); | 217 SyncContext* context, base::WaitableEvent* pump_messages_event); |
| 216 | 218 |
| 217 // Runs a nested message loop until a reply arrives, times out, or the process | 219 // Runs a nested message loop until a reply arrives, times out, or the process |
| 218 // shuts down. | 220 // shuts down. |
| 219 static void WaitForReplyWithNestedMessageLoop(SyncContext* context); | 221 static void WaitForReplyWithNestedMessageLoop(SyncContext* context); |
| 220 | 222 |
| 221 // Starts the dispatch watcher. | 223 // Starts the dispatch watcher. |
| 222 void StartWatching(); | 224 void StartWatching(); |
| 223 | 225 |
| 224 // Used to signal events between the IPC and listener threads. | 226 // Used to signal events between the IPC and listener threads. |
| 225 base::WaitableEventWatcher dispatch_watcher_; | 227 base::WaitableEventWatcher dispatch_watcher_; |
| 226 base::WaitableEventWatcher::EventCallback dispatch_watcher_callback_; | 228 base::WaitableEventWatcher::EventCallback dispatch_watcher_callback_; |
| 227 | 229 |
| 228 DISALLOW_COPY_AND_ASSIGN(SyncChannel); | 230 DISALLOW_COPY_AND_ASSIGN(SyncChannel); |
| 229 }; | 231 }; |
| 230 | 232 |
| 231 } // namespace IPC | 233 } // namespace IPC |
| 232 | 234 |
| 233 #endif // IPC_IPC_SYNC_CHANNEL_H_ | 235 #endif // IPC_IPC_SYNC_CHANNEL_H_ |
| OLD | NEW |