| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 CHROME_COMMON_IPC_SYNC_SENDER_H__ | 5 #ifndef CHROME_COMMON_IPC_SYNC_SENDER_H__ |
| 6 #define CHROME_COMMON_IPC_SYNC_SENDER_H__ | 6 #define CHROME_COMMON_IPC_SYNC_SENDER_H__ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <deque> | 9 #include <deque> |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // process shut down. | 72 // process shut down. |
| 73 base::WaitableEvent* GetSendDoneEvent(); | 73 base::WaitableEvent* GetSendDoneEvent(); |
| 74 | 74 |
| 75 // Returns an event that's set when an incoming message that's not the reply | 75 // Returns an event that's set when an incoming message that's not the reply |
| 76 // needs to get dispatched (by calling SyncContext::DispatchMessages). | 76 // needs to get dispatched (by calling SyncContext::DispatchMessages). |
| 77 base::WaitableEvent* GetDispatchEvent(); | 77 base::WaitableEvent* GetDispatchEvent(); |
| 78 | 78 |
| 79 void DispatchMessages(); | 79 void DispatchMessages(); |
| 80 | 80 |
| 81 // Checks if the given message is blocking the listener thread because of a | 81 // Checks if the given message is blocking the listener thread because of a |
| 82 // synchronous send. If it is, the thread is unblocked and true is returned
. | 82 // synchronous send. If it is, the thread is unblocked and true is |
| 83 // Otherwise the function returns false. | 83 // returned. Otherwise the function returns false. |
| 84 bool TryToUnblockListener(const Message* msg); | 84 bool TryToUnblockListener(const Message* msg); |
| 85 | 85 |
| 86 // Called on the IPC thread when a sync send that runs a nested message loop | 86 // Called on the IPC thread when a sync send that runs a nested message loop |
| 87 // times out. | 87 // times out. |
| 88 void OnSendTimeout(int message_id); | 88 void OnSendTimeout(int message_id); |
| 89 | 89 |
| 90 base::WaitableEvent* shutdown_event() { return shutdown_event_; } | 90 base::WaitableEvent* shutdown_event() { return shutdown_event_; } |
| 91 | 91 |
| 92 private: | 92 private: |
| 93 // IPC::ChannelProxy methods that we override. | 93 // IPC::ChannelProxy methods that we override. |
| 94 | 94 |
| 95 // Called on the listener thread. | 95 // Called on the listener thread. |
| 96 virtual void Clear(); | 96 virtual void Clear(); |
| 97 | 97 |
| 98 // Called on the IPC thread. | 98 // Called on the IPC thread. |
| 99 virtual void OnMessageReceived(const Message& msg); | 99 virtual void OnMessageReceived(const Message& msg); |
| 100 virtual void OnChannelError(); | 100 virtual void OnChannelError(); |
| 101 virtual void OnChannelOpened(); | 101 virtual void OnChannelOpened(); |
| 102 virtual void OnChannelClosed(); | 102 virtual void OnChannelClosed(); |
| 103 | 103 |
| 104 // Cancels all pending Send calls. | 104 // Cancels all pending Send calls. |
| 105 void CancelPendingSends(); | 105 void CancelPendingSends(); |
| 106 | 106 |
| 107 // WaitableEventWatcher::Delegate implementation. | 107 // WaitableEventWatcher::Delegate implementation. |
| 108 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg); | 108 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg); |
| 109 | 109 |
| 110 // When sending a synchronous message, this structure contains an object tha
t | 110 // When sending a synchronous message, this structure contains an object |
| 111 // knows how to deserialize the response. | 111 // that knows how to deserialize the response. |
| 112 struct PendingSyncMsg { | 112 struct PendingSyncMsg { |
| 113 PendingSyncMsg(int id, IPC::MessageReplyDeserializer* d, | 113 PendingSyncMsg(int id, IPC::MessageReplyDeserializer* d, |
| 114 base::WaitableEvent* e) : | 114 base::WaitableEvent* e) : |
| 115 id(id), deserializer(d), done_event(e), send_result(false) { } | 115 id(id), deserializer(d), done_event(e), send_result(false) { } |
| 116 int id; | 116 int id; |
| 117 IPC::MessageReplyDeserializer* deserializer; | 117 IPC::MessageReplyDeserializer* deserializer; |
| 118 base::WaitableEvent* done_event; | 118 base::WaitableEvent* done_event; |
| 119 bool send_result; | 119 bool send_result; |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 typedef std::deque<PendingSyncMsg> PendingSyncMessageQueue; | 122 typedef std::deque<PendingSyncMsg> PendingSyncMessageQueue; |
| 123 PendingSyncMessageQueue deserializers_; | 123 PendingSyncMessageQueue deserializers_; |
| 124 Lock deserializers_lock_; | 124 Lock deserializers_lock_; |
| 125 | 125 |
| 126 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_; | 126 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_; |
| 127 | 127 |
| 128 base::WaitableEvent* shutdown_event_; | 128 base::WaitableEvent* shutdown_event_; |
| 129 base::WaitableEventWatcher shutdown_watcher_; | 129 base::WaitableEventWatcher shutdown_watcher_; |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 private: | 132 private: |
| 133 // WaitableEventWatcher::Delegate implementation. | 133 // WaitableEventWatcher::Delegate implementation. |
| 134 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg); | 134 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg); |
| 135 | 135 |
| 136 SyncContext* sync_context() { return reinterpret_cast<SyncContext*>(context())
; } | 136 SyncContext* sync_context() { |
| 137 return reinterpret_cast<SyncContext*>(context()); |
| 138 } |
| 137 | 139 |
| 138 // Both these functions wait for a reply, timeout or process shutdown. The | 140 // Both these functions wait for a reply, timeout or process shutdown. The |
| 139 // latter one also runs a nested message loop in the meantime. | 141 // latter one also runs a nested message loop in the meantime. |
| 140 void WaitForReply(base::WaitableEvent* pump_messages_event); | 142 void WaitForReply(base::WaitableEvent* pump_messages_event); |
| 141 | 143 |
| 142 // Runs a nested message loop until a reply arrives, times out, or the process | 144 // Runs a nested message loop until a reply arrives, times out, or the process |
| 143 // shuts down. | 145 // shuts down. |
| 144 void WaitForReplyWithNestedMessageLoop(); | 146 void WaitForReplyWithNestedMessageLoop(); |
| 145 | 147 |
| 146 bool sync_messages_with_no_timeout_allowed_; | 148 bool sync_messages_with_no_timeout_allowed_; |
| 147 | 149 |
| 148 // Used to signal events between the IPC and listener threads. | 150 // Used to signal events between the IPC and listener threads. |
| 149 base::WaitableEventWatcher send_done_watcher_; | 151 base::WaitableEventWatcher send_done_watcher_; |
| 150 base::WaitableEventWatcher dispatch_watcher_; | 152 base::WaitableEventWatcher dispatch_watcher_; |
| 151 | 153 |
| 152 DISALLOW_EVIL_CONSTRUCTORS(SyncChannel); | 154 DISALLOW_EVIL_CONSTRUCTORS(SyncChannel); |
| 153 }; | 155 }; |
| 154 | 156 |
| 155 } // namespace IPC | 157 } // namespace IPC |
| 156 | 158 |
| 157 #endif // CHROME_COMMON_IPC_SYNC_SENDER_H__ | 159 #endif // CHROME_COMMON_IPC_SYNC_SENDER_H__ |
| 158 | 160 |
| OLD | NEW |