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

Side by Side Diff: ipc/ipc_sync_message_filter.h

Issue 1601005: Allow synchronous messages to be sent from threads other than the main thread... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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 | « ipc/ipc_sync_message.cc ('k') | ipc/ipc_sync_message_filter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef IPC_IPC_SYNC_MESSAGE_FILTER_H_
6 #define IPC_IPC_SYNC_MESSAGE_FILTER_H_
7
8 #include "base/basictypes.h"
9 #include "base/hash_tables.h"
10 #include "base/lock.h"
11 #include "base/ref_counted.h"
12 #include "base/waitable_event.h"
13 #include "ipc/ipc_channel_proxy.h"
14 #include "ipc/ipc_sync_message.h"
15
16 class MessageLoop;
17
18 #if defined(COMPILER_GCC)
19 // Allows us to use MessageLoop in a hash_map with gcc (MSVC is okay without
20 // specifying this).
21 namespace __gnu_cxx {
22 template<>
23 struct hash<MessageLoop*> {
24 size_t operator()(MessageLoop* message_loop) const {
25 return reinterpret_cast<size_t>(message_loop);
26 }
27 };
28 }
29 #endif
30
31 namespace IPC {
32
33 class MessageReplyDeserializer;
34
35 // This MessageFilter allows sending synchronous IPC messages from a thread
36 // other than the listener thread associated with the SyncChannel. It does not
37 // support fancy features that SyncChannel does, such as handling recursion or
38 // receiving messages while waiting for a response. Note that this object can
39 // be used to send simultaneous synchronous messages from different threads.
40 class SyncMessageFilter : public ChannelProxy::MessageFilter,
41 public Message::Sender {
42 public:
43 explicit SyncMessageFilter(base::WaitableEvent* shutdown_event);
44 virtual ~SyncMessageFilter();
45
46 // Message::Sender implementation.
47 virtual bool Send(Message* message);
48
49 // ChannelProxy::MessageFilter implementation.
50 virtual void OnFilterAdded(Channel* channel);
51 virtual void OnChannelError();
52 virtual void OnChannelClosing();
53 virtual bool OnMessageReceived(const Message& message);
54
55 private:
56 void SendOnIOThread(Message* message);
57 // Signal all the pending sends as done, used in an error condition.
58 void SignalAllEvents();
59
60 // The channel to which this filter was added.
61 Channel* channel_;
62
63 MessageLoop* listener_loop_; // The process's main thread.
64 MessageLoop* io_loop_; // The message loop where the Channel lives.
65
66 typedef base::hash_map<MessageLoop*, PendingSyncMsg*> PendingSyncMessages;
67 PendingSyncMessages pending_sync_messages_;
68
69 // Locks data members above.
70 Lock lock_;
71
72 base::WaitableEvent* shutdown_event_;
73
74 DISALLOW_COPY_AND_ASSIGN(SyncMessageFilter);
75 };
76
77 } // namespace IPC
78
79 #endif // IPC_IPC_SYNC_MESSAGE_FILTER_H_
OLDNEW
« no previous file with comments | « ipc/ipc_sync_message.cc ('k') | ipc/ipc_sync_message_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698