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

Side by Side Diff: ipc/ipc_sync_channel.h

Issue 6711024: Example of how to interpose yourself in a message stream. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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_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>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
15 #include "base/synchronization/waitable_event_watcher.h" 15 #include "base/synchronization/waitable_event_watcher.h"
16 #include "ipc/ipc_channel_handle.h" 16 #include "ipc/ipc_channel_handle.h"
17 #include "ipc/ipc_channel_proxy.h" 17 #include "ipc/ipc_channel_proxy.h"
18 #include "ipc/ipc_sync_message.h" 18 #include "ipc/ipc_sync_message.h"
19 19
20 namespace base { 20 namespace base {
21 class WaitableEvent; 21 class WaitableEvent;
22 }; 22 };
23 23
24 namespace IPC { 24 namespace IPC {
25 25
26 class SyncMessage; 26 class SyncMessage;
27 class MessageReplyDeserializer; 27 class MessageReplyDeserializer;
28 class OutgoingMessageFilter;
28 29
29 // This is similar to ChannelProxy, with the added feature of supporting sending 30 // This is similar to ChannelProxy, with the added feature of supporting sending
30 // synchronous messages. 31 // synchronous messages.
31 // 32 //
32 // Overview of how the sync channel works 33 // Overview of how the sync channel works
33 // -------------------------------------- 34 // --------------------------------------
34 // When the sending thread sends a synchronous message, we create a bunch 35 // When the sending thread sends a synchronous message, we create a bunch
35 // of tracking info (created in SendWithTimeout, stored in the PendingSyncMsg 36 // of tracking info (created in SendWithTimeout, stored in the PendingSyncMsg
36 // structure) associated with the message that we identify by the unique 37 // structure) associated with the message that we identify by the unique
37 // "MessageId" on the SyncMessage. Among the things we save is the 38 // "MessageId" on the SyncMessage. Among the things we save is the
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // is itself blocked on sending a sync message, not when other channels are. 84 // is itself blocked on sending a sync message, not when other channels are.
84 // 85 //
85 // Normally, any unblocking message coming from any channel can be dispatched 86 // Normally, any unblocking message coming from any channel can be dispatched
86 // when any (possibly other) channel is blocked on sending a message. This is 87 // when any (possibly other) channel is blocked on sending a message. This is
87 // needed in some cases to unblock certain loops (e.g. necessary when some 88 // needed in some cases to unblock certain loops (e.g. necessary when some
88 // processes share a window hierarchy), but may cause re-entrancy issues in 89 // processes share a window hierarchy), but may cause re-entrancy issues in
89 // some cases where such loops are not possible. This flags allows the tagging 90 // some cases where such loops are not possible. This flags allows the tagging
90 // of some particular channels to not re-enter in such cases. 91 // of some particular channels to not re-enter in such cases.
91 void SetRestrictDispatchToSameChannel(bool value); 92 void SetRestrictDispatchToSameChannel(bool value);
92 93
94 // Sets this channel to rewrite its outgoing messages.
95 void set_outgoing_message_filter(OutgoingMessageFilter *filter) {
96 outgoing_message_filter_ = filter;
97 }
98
93 protected: 99 protected:
94 class ReceivedSyncMsgQueue; 100 class ReceivedSyncMsgQueue;
95 friend class ReceivedSyncMsgQueue; 101 friend class ReceivedSyncMsgQueue;
96 102
97 // SyncContext holds the per object data for SyncChannel, so that SyncChannel 103 // SyncContext holds the per object data for SyncChannel, so that SyncChannel
98 // can be deleted while it's being used in a different thread. See 104 // can be deleted while it's being used in a different thread. See
99 // ChannelProxy::Context for more information. 105 // ChannelProxy::Context for more information.
100 class SyncContext : public Context, 106 class SyncContext : public Context,
101 public base::WaitableEventWatcher::Delegate { 107 public base::WaitableEventWatcher::Delegate {
102 public: 108 public:
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // Both these functions wait for a reply, timeout or process shutdown. The 187 // Both these functions wait for a reply, timeout or process shutdown. The
182 // latter one also runs a nested message loop in the meantime. 188 // latter one also runs a nested message loop in the meantime.
183 static void WaitForReply( 189 static void WaitForReply(
184 SyncContext* context, base::WaitableEvent* pump_messages_event); 190 SyncContext* context, base::WaitableEvent* pump_messages_event);
185 191
186 // Runs a nested message loop until a reply arrives, times out, or the process 192 // Runs a nested message loop until a reply arrives, times out, or the process
187 // shuts down. 193 // shuts down.
188 static void WaitForReplyWithNestedMessageLoop(SyncContext* context); 194 static void WaitForReplyWithNestedMessageLoop(SyncContext* context);
189 195
190 bool sync_messages_with_no_timeout_allowed_; 196 bool sync_messages_with_no_timeout_allowed_;
197 OutgoingMessageFilter *outgoing_message_filter_;
jam 2011/04/28 23:43:46 nit: * then space
191 198
192 // Used to signal events between the IPC and listener threads. 199 // Used to signal events between the IPC and listener threads.
193 base::WaitableEventWatcher dispatch_watcher_; 200 base::WaitableEventWatcher dispatch_watcher_;
194 201
195 DISALLOW_COPY_AND_ASSIGN(SyncChannel); 202 DISALLOW_COPY_AND_ASSIGN(SyncChannel);
196 }; 203 };
197 204
205 // Interface for a filter to be imposed on outgoing messages which can
206 // re-write the message. Used mainly for testing.
207 class OutgoingMessageFilter {
jam 2011/04/28 23:43:46 since this doesn't have to do with sync messages,
208 public:
209 // Returns a re-written message, freeing the original, or simply the
210 // original unchanged if no rewrite indicated.
211 virtual Message *Rewrite(Message *message) = 0;
212 };
213
198 } // namespace IPC 214 } // namespace IPC
199 215
200 #endif // IPC_IPC_SYNC_SENDER_H__ 216 #endif // IPC_IPC_SYNC_SENDER_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698