Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1102)

Side by Side Diff: ipc/ipc_sync_channel.h

Issue 9917002: IPC: change sync channel dispatch restriction to allow dispatch to other channels within the same "… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 virtual ~SyncChannel(); 81 virtual ~SyncChannel();
82 82
83 virtual bool Send(Message* message) OVERRIDE; 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 the dispatch group for this channel, to only allow re-entrant dispatch
92 // is itself blocked on sending a sync message, not when other channels are. 92 // of messages to other channels in the same group.
93 // 93 //
94 // Normally, any unblocking message coming from any channel can be dispatched 94 // Normally, any unblocking message coming from any channel can be dispatched
95 // when any (possibly other) channel is blocked on sending a message. This is 95 // when any (possibly other) channel is blocked on sending a message. This is
96 // needed in some cases to unblock certain loops (e.g. necessary when some 96 // needed in some cases to unblock certain loops (e.g. necessary when some
97 // processes share a window hierarchy), but may cause re-entrancy issues in 97 // processes share a window hierarchy), but may cause re-entrancy issues in
98 // some cases where such loops are not possible. This flags allows the tagging 98 // some cases where such loops are not possible. This flags allows the tagging
99 // of some particular channels to not re-enter in such cases. 99 // of some particular channels to only re-enter in known correct cases.
100 void SetRestrictDispatchToSameChannel(bool value); 100 void SetRestrictDispatchChannelGroup(int group);
101 101
102 protected: 102 protected:
103 class ReceivedSyncMsgQueue; 103 class ReceivedSyncMsgQueue;
104 friend class ReceivedSyncMsgQueue; 104 friend class ReceivedSyncMsgQueue;
105 105
106 // SyncContext holds the per object data for SyncChannel, so that SyncChannel 106 // SyncContext holds the per object data for SyncChannel, so that SyncChannel
107 // can be deleted while it's being used in a different thread. See 107 // can be deleted while it's being used in a different thread. See
108 // ChannelProxy::Context for more information. 108 // ChannelProxy::Context for more information.
109 class SyncContext : public Context, 109 class SyncContext : public Context,
110 public base::WaitableEventWatcher::Delegate { 110 public base::WaitableEventWatcher::Delegate {
(...skipping 28 matching lines...) Expand all
139 // Called on the IPC thread when a sync send that runs a nested message loop 139 // Called on the IPC thread when a sync send that runs a nested message loop
140 // times out. 140 // times out.
141 void OnSendTimeout(int message_id); 141 void OnSendTimeout(int message_id);
142 142
143 base::WaitableEvent* shutdown_event() { return shutdown_event_; } 143 base::WaitableEvent* shutdown_event() { return shutdown_event_; }
144 144
145 ReceivedSyncMsgQueue* received_sync_msgs() { 145 ReceivedSyncMsgQueue* received_sync_msgs() {
146 return received_sync_msgs_; 146 return received_sync_msgs_;
147 } 147 }
148 148
149 void set_restrict_dispatch(bool value) { restrict_dispatch_ = value; } 149 void set_restrict_dispatch_group(int group) {
150 bool restrict_dispatch() const { return restrict_dispatch_; } 150 restrict_dispatch_group_ = group;
151 }
152
153 int restrict_dispatch_group() const {
154 return restrict_dispatch_group_;
155 }
151 156
152 private: 157 private:
153 virtual ~SyncContext(); 158 virtual ~SyncContext();
154 // ChannelProxy methods that we override. 159 // ChannelProxy methods that we override.
155 160
156 // Called on the listener thread. 161 // Called on the listener thread.
157 virtual void Clear() OVERRIDE; 162 virtual void Clear() OVERRIDE;
158 163
159 // Called on the IPC thread. 164 // Called on the IPC thread.
160 virtual bool OnMessageReceived(const Message& msg) OVERRIDE; 165 virtual bool OnMessageReceived(const Message& msg) OVERRIDE;
161 virtual void OnChannelError() OVERRIDE; 166 virtual void OnChannelError() OVERRIDE;
162 virtual void OnChannelOpened() OVERRIDE; 167 virtual void OnChannelOpened() OVERRIDE;
163 virtual void OnChannelClosed() OVERRIDE; 168 virtual void OnChannelClosed() OVERRIDE;
164 169
165 // Cancels all pending Send calls. 170 // Cancels all pending Send calls.
166 void CancelPendingSends(); 171 void CancelPendingSends();
167 172
168 // WaitableEventWatcher::Delegate implementation. 173 // WaitableEventWatcher::Delegate implementation.
169 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg) OVERRIDE; 174 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg) OVERRIDE;
170 175
171 typedef std::deque<PendingSyncMsg> PendingSyncMessageQueue; 176 typedef std::deque<PendingSyncMsg> PendingSyncMessageQueue;
172 PendingSyncMessageQueue deserializers_; 177 PendingSyncMessageQueue deserializers_;
173 base::Lock deserializers_lock_; 178 base::Lock deserializers_lock_;
174 179
175 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_; 180 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_;
176 181
177 base::WaitableEvent* shutdown_event_; 182 base::WaitableEvent* shutdown_event_;
178 base::WaitableEventWatcher shutdown_watcher_; 183 base::WaitableEventWatcher shutdown_watcher_;
179 bool restrict_dispatch_; 184 int restrict_dispatch_group_;
180 }; 185 };
181 186
182 private: 187 private:
183 // WaitableEventWatcher::Delegate implementation. 188 // WaitableEventWatcher::Delegate implementation.
184 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg) OVERRIDE; 189 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg) OVERRIDE;
185 190
186 SyncContext* sync_context() { 191 SyncContext* sync_context() {
187 return reinterpret_cast<SyncContext*>(context()); 192 return reinterpret_cast<SyncContext*>(context());
188 } 193 }
189 194
(...skipping 13 matching lines...) Expand all
203 208
204 // Used to signal events between the IPC and listener threads. 209 // Used to signal events between the IPC and listener threads.
205 base::WaitableEventWatcher dispatch_watcher_; 210 base::WaitableEventWatcher dispatch_watcher_;
206 211
207 DISALLOW_COPY_AND_ASSIGN(SyncChannel); 212 DISALLOW_COPY_AND_ASSIGN(SyncChannel);
208 }; 213 };
209 214
210 } // namespace IPC 215 } // namespace IPC
211 216
212 #endif // IPC_IPC_SYNC_CHANNEL_H_ 217 #endif // IPC_IPC_SYNC_CHANNEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698