Chromium Code Reviews| 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_SENDER_H__ | 5 #ifndef IPC_IPC_SYNC_SENDER_H__ |
| 6 #define IPC_IPC_SYNC_SENDER_H__ | 6 #define IPC_IPC_SYNC_SENDER_H__ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <deque> | 10 #include <deque> |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 virtual ~SyncChannel(); | 44 virtual ~SyncChannel(); |
| 45 | 45 |
| 46 virtual bool Send(Message* message); | 46 virtual bool Send(Message* message); |
| 47 virtual bool SendWithTimeout(Message* message, int timeout_ms); | 47 virtual bool SendWithTimeout(Message* message, int timeout_ms); |
| 48 | 48 |
| 49 // Whether we allow sending messages with no time-out. | 49 // Whether we allow sending messages with no time-out. |
| 50 void set_sync_messages_with_no_timeout_allowed(bool value) { | 50 void set_sync_messages_with_no_timeout_allowed(bool value) { |
| 51 sync_messages_with_no_timeout_allowed_ = value; | 51 sync_messages_with_no_timeout_allowed_ = value; |
| 52 } | 52 } |
| 53 | 53 |
| 54 // Sets this channel to only dispatch its incoming unblocking messages when it | |
| 55 // is itself blocked on sending a sync message, not when other channels are. | |
| 56 // | |
| 57 // Normally, any unblocking message coming from any channel can be dispatched | |
| 58 // when any (possibly other) channel is blocked on sending a message. This is | |
| 59 // needed in some cases to unblock certain loops (e.g. | |
| 60 // renderer->browser->plugin->renderer), but may cause re-entrancy issues in | |
| 61 // some cases where loops are not possible (e.g. dispatching a ppapi message | |
| 62 // while the renderer is blocked on the gpu). This flags allows the tagging of | |
| 63 // some particular channels (e.g. ppapi) to not re-enter in such cases. | |
|
jam
2011/04/07 21:25:19
nit: we've usually tried to stay away from talking
| |
| 64 void SetRestrictDispatchToSameChannel(bool value); | |
| 65 | |
| 54 protected: | 66 protected: |
| 55 class ReceivedSyncMsgQueue; | 67 class ReceivedSyncMsgQueue; |
| 56 friend class ReceivedSyncMsgQueue; | 68 friend class ReceivedSyncMsgQueue; |
| 57 | 69 |
| 58 // SyncContext holds the per object data for SyncChannel, so that SyncChannel | 70 // SyncContext holds the per object data for SyncChannel, so that SyncChannel |
| 59 // can be deleted while it's being used in a different thread. See | 71 // can be deleted while it's being used in a different thread. See |
| 60 // ChannelProxy::Context for more information. | 72 // ChannelProxy::Context for more information. |
| 61 class SyncContext : public Context, | 73 class SyncContext : public Context, |
| 62 public base::WaitableEventWatcher::Delegate { | 74 public base::WaitableEventWatcher::Delegate { |
| 63 public: | 75 public: |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 91 // Called on the IPC thread when a sync send that runs a nested message loop | 103 // Called on the IPC thread when a sync send that runs a nested message loop |
| 92 // times out. | 104 // times out. |
| 93 void OnSendTimeout(int message_id); | 105 void OnSendTimeout(int message_id); |
| 94 | 106 |
| 95 base::WaitableEvent* shutdown_event() { return shutdown_event_; } | 107 base::WaitableEvent* shutdown_event() { return shutdown_event_; } |
| 96 | 108 |
| 97 ReceivedSyncMsgQueue* received_sync_msgs() { | 109 ReceivedSyncMsgQueue* received_sync_msgs() { |
| 98 return received_sync_msgs_; | 110 return received_sync_msgs_; |
| 99 } | 111 } |
| 100 | 112 |
| 113 void set_restrict_dispatch(bool value) { restrict_dispatch_ = value; } | |
| 114 bool restrict_dispatch() const { return restrict_dispatch_; } | |
| 115 | |
| 101 private: | 116 private: |
| 102 ~SyncContext(); | 117 ~SyncContext(); |
| 103 // ChannelProxy methods that we override. | 118 // ChannelProxy methods that we override. |
| 104 | 119 |
| 105 // Called on the listener thread. | 120 // Called on the listener thread. |
| 106 virtual void Clear(); | 121 virtual void Clear(); |
| 107 | 122 |
| 108 // Called on the IPC thread. | 123 // Called on the IPC thread. |
| 109 virtual bool OnMessageReceived(const Message& msg); | 124 virtual bool OnMessageReceived(const Message& msg); |
| 110 virtual void OnChannelError(); | 125 virtual void OnChannelError(); |
| 111 virtual void OnChannelOpened(); | 126 virtual void OnChannelOpened(); |
| 112 virtual void OnChannelClosed(); | 127 virtual void OnChannelClosed(); |
| 113 | 128 |
| 114 // Cancels all pending Send calls. | 129 // Cancels all pending Send calls. |
| 115 void CancelPendingSends(); | 130 void CancelPendingSends(); |
| 116 | 131 |
| 117 // WaitableEventWatcher::Delegate implementation. | 132 // WaitableEventWatcher::Delegate implementation. |
| 118 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg); | 133 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg); |
| 119 | 134 |
| 120 typedef std::deque<PendingSyncMsg> PendingSyncMessageQueue; | 135 typedef std::deque<PendingSyncMsg> PendingSyncMessageQueue; |
| 121 PendingSyncMessageQueue deserializers_; | 136 PendingSyncMessageQueue deserializers_; |
| 122 base::Lock deserializers_lock_; | 137 base::Lock deserializers_lock_; |
| 123 | 138 |
| 124 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_; | 139 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_; |
| 125 | 140 |
| 126 base::WaitableEvent* shutdown_event_; | 141 base::WaitableEvent* shutdown_event_; |
| 127 base::WaitableEventWatcher shutdown_watcher_; | 142 base::WaitableEventWatcher shutdown_watcher_; |
| 143 bool restrict_dispatch_; | |
| 128 }; | 144 }; |
| 129 | 145 |
| 130 private: | 146 private: |
| 131 // WaitableEventWatcher::Delegate implementation. | 147 // WaitableEventWatcher::Delegate implementation. |
| 132 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg); | 148 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg); |
| 133 | 149 |
| 134 SyncContext* sync_context() { | 150 SyncContext* sync_context() { |
| 135 return reinterpret_cast<SyncContext*>(context()); | 151 return reinterpret_cast<SyncContext*>(context()); |
| 136 } | 152 } |
| 137 | 153 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 148 | 164 |
| 149 // Used to signal events between the IPC and listener threads. | 165 // Used to signal events between the IPC and listener threads. |
| 150 base::WaitableEventWatcher dispatch_watcher_; | 166 base::WaitableEventWatcher dispatch_watcher_; |
| 151 | 167 |
| 152 DISALLOW_COPY_AND_ASSIGN(SyncChannel); | 168 DISALLOW_COPY_AND_ASSIGN(SyncChannel); |
| 153 }; | 169 }; |
| 154 | 170 |
| 155 } // namespace IPC | 171 } // namespace IPC |
| 156 | 172 |
| 157 #endif // IPC_IPC_SYNC_SENDER_H__ | 173 #endif // IPC_IPC_SYNC_SENDER_H__ |
| OLD | NEW |