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

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: docs 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
« no previous file with comments | « content/renderer/renderer_restrict_dispatch_group.h ('k') | ipc/ipc_sync_channel.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // be dispatched in a reentrant manner to avoid deadlock. 55 // be dispatched in a reentrant manner to avoid deadlock.
56 // 56 //
57 // 57 //
58 // Note that care must be taken that the lifetime of the ipc_thread argument 58 // Note that care must be taken that the lifetime of the ipc_thread argument
59 // is more than this object. If the message loop goes away while this object 59 // is more than this object. If the message loop goes away while this object
60 // is running and it's used to send a message, then it will use the invalid 60 // is running and it's used to send a message, then it will use the invalid
61 // message loop pointer to proxy it to the ipc thread. 61 // message loop pointer to proxy it to the ipc thread.
62 class IPC_EXPORT SyncChannel : public ChannelProxy, 62 class IPC_EXPORT SyncChannel : public ChannelProxy,
63 public base::WaitableEventWatcher::Delegate { 63 public base::WaitableEventWatcher::Delegate {
64 public: 64 public:
65 enum RestrictDispatchGroup {
66 kRestrictDispatchGroup_None = 0,
67 };
68
65 // Creates and initializes a sync channel. If create_pipe_now is specified, 69 // Creates and initializes a sync channel. If create_pipe_now is specified,
66 // the channel will be initialized synchronously. 70 // the channel will be initialized synchronously.
67 SyncChannel(const IPC::ChannelHandle& channel_handle, 71 SyncChannel(const IPC::ChannelHandle& channel_handle,
68 Channel::Mode mode, 72 Channel::Mode mode,
69 Channel::Listener* listener, 73 Channel::Listener* listener,
70 base::MessageLoopProxy* ipc_message_loop, 74 base::MessageLoopProxy* ipc_message_loop,
71 bool create_pipe_now, 75 bool create_pipe_now,
72 base::WaitableEvent* shutdown_event); 76 base::WaitableEvent* shutdown_event);
73 77
74 // Creates an uninitialized sync channel. Call ChannelProxy::Init to 78 // Creates an uninitialized sync channel. Call ChannelProxy::Init to
75 // initialize the channel. This two-step setup allows message filters to be 79 // initialize the channel. This two-step setup allows message filters to be
76 // added before any messages are sent or received. 80 // added before any messages are sent or received.
77 SyncChannel(Channel::Listener* listener, 81 SyncChannel(Channel::Listener* listener,
78 base::MessageLoopProxy* ipc_message_loop, 82 base::MessageLoopProxy* ipc_message_loop,
79 base::WaitableEvent* shutdown_event); 83 base::WaitableEvent* shutdown_event);
80 84
81 virtual ~SyncChannel(); 85 virtual ~SyncChannel();
82 86
83 virtual bool Send(Message* message) OVERRIDE; 87 virtual bool Send(Message* message) OVERRIDE;
84 virtual bool SendWithTimeout(Message* message, int timeout_ms); 88 virtual bool SendWithTimeout(Message* message, int timeout_ms);
85 89
86 // Whether we allow sending messages with no time-out. 90 // Whether we allow sending messages with no time-out.
87 void set_sync_messages_with_no_timeout_allowed(bool value) { 91 void set_sync_messages_with_no_timeout_allowed(bool value) {
88 sync_messages_with_no_timeout_allowed_ = value; 92 sync_messages_with_no_timeout_allowed_ = value;
89 } 93 }
90 94
91 // Sets this channel to only dispatch its incoming unblocking messages when it 95 // 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. 96 // of messages to other channels in the same group.
93 // 97 //
94 // Normally, any unblocking message coming from any channel can be dispatched 98 // 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 99 // 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 100 // 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 101 // 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 102 // 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. 103 // of some particular channels to only re-enter in known correct cases.
100 void SetRestrictDispatchToSameChannel(bool value); 104 //
105 // Incoming messages on channels belonging to a group that is not
106 // kRestrictDispatchGroup_None will only be dispatched while a sync message is
107 // being sent on a channel of the *same* group.
108 // Incoming messages belonging to the kRestrictDispatchGroup_None group (the
109 // default) will be dispatched in any case.
110 void SetRestrictDispatchChannelGroup(int group);
101 111
102 protected: 112 protected:
103 class ReceivedSyncMsgQueue; 113 class ReceivedSyncMsgQueue;
104 friend class ReceivedSyncMsgQueue; 114 friend class ReceivedSyncMsgQueue;
105 115
106 // SyncContext holds the per object data for SyncChannel, so that SyncChannel 116 // 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 117 // can be deleted while it's being used in a different thread. See
108 // ChannelProxy::Context for more information. 118 // ChannelProxy::Context for more information.
109 class SyncContext : public Context, 119 class SyncContext : public Context,
110 public base::WaitableEventWatcher::Delegate { 120 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 149 // Called on the IPC thread when a sync send that runs a nested message loop
140 // times out. 150 // times out.
141 void OnSendTimeout(int message_id); 151 void OnSendTimeout(int message_id);
142 152
143 base::WaitableEvent* shutdown_event() { return shutdown_event_; } 153 base::WaitableEvent* shutdown_event() { return shutdown_event_; }
144 154
145 ReceivedSyncMsgQueue* received_sync_msgs() { 155 ReceivedSyncMsgQueue* received_sync_msgs() {
146 return received_sync_msgs_; 156 return received_sync_msgs_;
147 } 157 }
148 158
149 void set_restrict_dispatch(bool value) { restrict_dispatch_ = value; } 159 void set_restrict_dispatch_group(int group) {
150 bool restrict_dispatch() const { return restrict_dispatch_; } 160 restrict_dispatch_group_ = group;
161 }
162
163 int restrict_dispatch_group() const {
164 return restrict_dispatch_group_;
165 }
151 166
152 private: 167 private:
153 virtual ~SyncContext(); 168 virtual ~SyncContext();
154 // ChannelProxy methods that we override. 169 // ChannelProxy methods that we override.
155 170
156 // Called on the listener thread. 171 // Called on the listener thread.
157 virtual void Clear() OVERRIDE; 172 virtual void Clear() OVERRIDE;
158 173
159 // Called on the IPC thread. 174 // Called on the IPC thread.
160 virtual bool OnMessageReceived(const Message& msg) OVERRIDE; 175 virtual bool OnMessageReceived(const Message& msg) OVERRIDE;
161 virtual void OnChannelError() OVERRIDE; 176 virtual void OnChannelError() OVERRIDE;
162 virtual void OnChannelOpened() OVERRIDE; 177 virtual void OnChannelOpened() OVERRIDE;
163 virtual void OnChannelClosed() OVERRIDE; 178 virtual void OnChannelClosed() OVERRIDE;
164 179
165 // Cancels all pending Send calls. 180 // Cancels all pending Send calls.
166 void CancelPendingSends(); 181 void CancelPendingSends();
167 182
168 // WaitableEventWatcher::Delegate implementation. 183 // WaitableEventWatcher::Delegate implementation.
169 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg) OVERRIDE; 184 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg) OVERRIDE;
170 185
171 typedef std::deque<PendingSyncMsg> PendingSyncMessageQueue; 186 typedef std::deque<PendingSyncMsg> PendingSyncMessageQueue;
172 PendingSyncMessageQueue deserializers_; 187 PendingSyncMessageQueue deserializers_;
173 base::Lock deserializers_lock_; 188 base::Lock deserializers_lock_;
174 189
175 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_; 190 scoped_refptr<ReceivedSyncMsgQueue> received_sync_msgs_;
176 191
177 base::WaitableEvent* shutdown_event_; 192 base::WaitableEvent* shutdown_event_;
178 base::WaitableEventWatcher shutdown_watcher_; 193 base::WaitableEventWatcher shutdown_watcher_;
179 bool restrict_dispatch_; 194 int restrict_dispatch_group_;
180 }; 195 };
181 196
182 private: 197 private:
183 // WaitableEventWatcher::Delegate implementation. 198 // WaitableEventWatcher::Delegate implementation.
184 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg) OVERRIDE; 199 virtual void OnWaitableEventSignaled(base::WaitableEvent* arg) OVERRIDE;
185 200
186 SyncContext* sync_context() { 201 SyncContext* sync_context() {
187 return reinterpret_cast<SyncContext*>(context()); 202 return reinterpret_cast<SyncContext*>(context());
188 } 203 }
189 204
(...skipping 13 matching lines...) Expand all
203 218
204 // Used to signal events between the IPC and listener threads. 219 // Used to signal events between the IPC and listener threads.
205 base::WaitableEventWatcher dispatch_watcher_; 220 base::WaitableEventWatcher dispatch_watcher_;
206 221
207 DISALLOW_COPY_AND_ASSIGN(SyncChannel); 222 DISALLOW_COPY_AND_ASSIGN(SyncChannel);
208 }; 223 };
209 224
210 } // namespace IPC 225 } // namespace IPC
211 226
212 #endif // IPC_IPC_SYNC_CHANNEL_H_ 227 #endif // IPC_IPC_SYNC_CHANNEL_H_
OLDNEW
« no previous file with comments | « content/renderer/renderer_restrict_dispatch_group.h ('k') | ipc/ipc_sync_channel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698