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

Side by Side Diff: ipc/ipc_channel_proxy.h

Issue 245443005: Move IPC::MessageFilter and router to a separate file (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: small cleanup Created 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_CHANNEL_PROXY_H_ 5 #ifndef IPC_IPC_CHANNEL_PROXY_H_
6 #define IPC_IPC_CHANNEL_PROXY_H_ 6 #define IPC_IPC_CHANNEL_PROXY_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/synchronization/lock.h" 12 #include "base/synchronization/lock.h"
13 #include "base/threading/non_thread_safe.h" 13 #include "base/threading/non_thread_safe.h"
14 #include "ipc/ipc_channel.h" 14 #include "ipc/ipc_channel.h"
15 #include "ipc/ipc_channel_handle.h" 15 #include "ipc/ipc_channel_handle.h"
16 #include "ipc/ipc_listener.h" 16 #include "ipc/ipc_listener.h"
17 #include "ipc/ipc_message_filter.h"
18 // TODO(dmichael): Remove this include of ipc_message_filter.h; move dependents
19 // to including ipc_message_filter.h directly.
20 // See crbug.com/364241
17 #include "ipc/ipc_sender.h" 21 #include "ipc/ipc_sender.h"
18 22
19 namespace base { 23 namespace base {
20 class SingleThreadTaskRunner; 24 class SingleThreadTaskRunner;
21 } 25 }
22 26
23 namespace IPC { 27 namespace IPC {
24 28
29 class MessageFilter;
30 class MessageFilterRouter;
25 class SendCallbackHelper; 31 class SendCallbackHelper;
26 32
27 //----------------------------------------------------------------------------- 33 //-----------------------------------------------------------------------------
28 // IPC::ChannelProxy 34 // IPC::ChannelProxy
29 // 35 //
30 // This class is a helper class that is useful when you wish to run an IPC 36 // This class is a helper class that is useful when you wish to run an IPC
31 // channel on a background thread. It provides you with the option of either 37 // channel on a background thread. It provides you with the option of either
32 // handling IPC messages on that background thread or having them dispatched to 38 // handling IPC messages on that background thread or having them dispatched to
33 // your main thread (the thread on which the IPC::ChannelProxy is created). 39 // your main thread (the thread on which the IPC::ChannelProxy is created).
34 // 40 //
(...skipping 12 matching lines...) Expand all
47 // the consumer of IPC::ChannelProxy the ability to respond to incoming 53 // the consumer of IPC::ChannelProxy the ability to respond to incoming
48 // messages on this background thread instead of on their own thread, which may 54 // messages on this background thread instead of on their own thread, which may
49 // be bogged down with other processing. The result can be greatly improved 55 // be bogged down with other processing. The result can be greatly improved
50 // latency for messages that can be handled on a background thread. 56 // latency for messages that can be handled on a background thread.
51 // 57 //
52 // The consumer of IPC::ChannelProxy is responsible for allocating the Thread 58 // The consumer of IPC::ChannelProxy is responsible for allocating the Thread
53 // instance where the IPC::Channel will be created and operated. 59 // instance where the IPC::Channel will be created and operated.
54 // 60 //
55 class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe { 61 class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe {
56 public: 62 public:
57 63 // This typedef is for backwards compatibility, since the MessageFilter class
58 // A class that receives messages on the thread where the IPC channel is 64 // used to be defined here. See crbug.com/364241
59 // running. It can choose to prevent the default action for an IPC message. 65 typedef IPC::MessageFilter MessageFilter;
jam 2014/04/22 17:14:27 i see only 56 files matching this, why not do it i
dmichael (off chromium) 2014/04/23 19:42:31 Just to make the review easier and make sure the m
60 class IPC_EXPORT MessageFilter
61 : public base::RefCountedThreadSafe<MessageFilter> {
62 public:
63 MessageFilter();
64
65 // Called on the background thread to provide the filter with access to the
66 // channel. Called when the IPC channel is initialized or when AddFilter
67 // is called if the channel is already initialized.
68 virtual void OnFilterAdded(Channel* channel);
69
70 // Called on the background thread when the filter has been removed from
71 // the ChannelProxy and when the Channel is closing. After a filter is
72 // removed, it will not be called again.
73 virtual void OnFilterRemoved();
74
75 // Called to inform the filter that the IPC channel is connected and we
76 // have received the internal Hello message from the peer.
77 virtual void OnChannelConnected(int32 peer_pid);
78
79 // Called when there is an error on the channel, typically that the channel
80 // has been closed.
81 virtual void OnChannelError();
82
83 // Called to inform the filter that the IPC channel will be destroyed.
84 // OnFilterRemoved is called immediately after this.
85 virtual void OnChannelClosing();
86
87 // Return true to indicate that the message was handled, or false to let
88 // the message be handled in the default way.
89 virtual bool OnMessageReceived(const Message& message);
90
91 // Called to query the Message classes supported by the filter. Return
92 // false to indicate that all message types should reach the filter, or true
93 // if the resulting contents of |supported_message_classes| may be used to
94 // selectively offer messages of a particular class to the filter.
95 virtual bool GetSupportedMessageClasses(
96 std::vector<uint32>* supported_message_classes) const;
97
98 protected:
99 virtual ~MessageFilter();
100
101 private:
102 friend class base::RefCountedThreadSafe<MessageFilter>;
103 };
104 66
105 // Initializes a channel proxy. The channel_handle and mode parameters are 67 // Initializes a channel proxy. The channel_handle and mode parameters are
106 // passed directly to the underlying IPC::Channel. The listener is called on 68 // passed directly to the underlying IPC::Channel. The listener is called on
107 // the thread that creates the ChannelProxy. The filter's OnMessageReceived 69 // the thread that creates the ChannelProxy. The filter's OnMessageReceived
108 // method is called on the thread where the IPC::Channel is running. The 70 // method is called on the thread where the IPC::Channel is running. The
109 // filter may be null if the consumer is not interested in handling messages 71 // filter may be null if the consumer is not interested in handling messages
110 // on the background thread. Any message not handled by the filter will be 72 // on the background thread. Any message not handled by the filter will be
111 // dispatched to the listener. The given task runner correspond to a thread 73 // dispatched to the listener. The given task runner correspond to a thread
112 // on which IPC::Channel is created and used (e.g. IO thread). 74 // on which IPC::Channel is created and used (e.g. IO thread).
113 ChannelProxy(const IPC::ChannelHandle& channel_handle, 75 ChannelProxy(const IPC::ChannelHandle& channel_handle,
114 Channel::Mode mode, 76 Channel::Mode mode,
115 Listener* listener, 77 Listener* listener,
116 base::SingleThreadTaskRunner* ipc_task_runner); 78 base::SingleThreadTaskRunner* ipc_task_runner);
117 79
118 virtual ~ChannelProxy(); 80 virtual ~ChannelProxy();
119 81
120 // Initializes the channel proxy. Only call this once to initialize a channel 82 // Initializes the channel proxy. Only call this once to initialize a channel
121 // proxy that was not initialized in its constructor. If create_pipe_now is 83 // proxy that was not initialized in its constructor. If create_pipe_now is
122 // true, the pipe is created synchronously. Otherwise it's created on the IO 84 // true, the pipe is created synchronously. Otherwise it's created on the IO
123 // thread. 85 // thread.
124 void Init(const IPC::ChannelHandle& channel_handle, Channel::Mode mode, 86 void Init(const IPC::ChannelHandle& channel_handle, Channel::Mode mode,
125 bool create_pipe_now); 87 bool create_pipe_now);
126 88
127 // Close the IPC::Channel. This operation completes asynchronously, once the 89 // Close the IPC::Channel. This operation completes asynchronously, once the
128 // background thread processes the command to close the channel. It is ok to 90 // background thread processes the command to close the channel. It is ok to
129 // call this method multiple times. Redundant calls are ignored. 91 // call this method multiple times. Redundant calls are ignored.
130 // 92 //
131 // WARNING: The MessageFilter object held by the ChannelProxy is also 93 // WARNING: MessageFilter objects held by the ChannelProxy is also
132 // released asynchronously, and it may in fact have its final reference 94 // released asynchronously, and it may in fact have its final reference
133 // released on the background thread. The caller should be careful to deal 95 // released on the background thread. The caller should be careful to deal
134 // with / allow for this possibility. 96 // with / allow for this possibility.
135 void Close(); 97 void Close();
136 98
137 // Send a message asynchronously. The message is routed to the background 99 // Send a message asynchronously. The message is routed to the background
138 // thread where it is passed to the IPC::Channel's Send method. 100 // thread where it is passed to the IPC::Channel's Send method.
139 virtual bool Send(Message* message) OVERRIDE; 101 virtual bool Send(Message* message) OVERRIDE;
140 102
141 // Used to intercept messages as they are received on the background thread. 103 // Used to intercept messages as they are received on the background thread.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 198
237 // Note, channel_ may be set on the Listener thread or the IPC thread. 199 // Note, channel_ may be set on the Listener thread or the IPC thread.
238 // But once it has been set, it must only be read or cleared on the IPC 200 // But once it has been set, it must only be read or cleared on the IPC
239 // thread. 201 // thread.
240 scoped_ptr<Channel> channel_; 202 scoped_ptr<Channel> channel_;
241 std::string channel_id_; 203 std::string channel_id_;
242 bool channel_connected_called_; 204 bool channel_connected_called_;
243 205
244 // Routes a given message to a proper subset of |filters_|, depending 206 // Routes a given message to a proper subset of |filters_|, depending
245 // on which message classes a filter might support. 207 // on which message classes a filter might support.
246 class MessageFilterRouter;
247 scoped_ptr<MessageFilterRouter> message_filter_router_; 208 scoped_ptr<MessageFilterRouter> message_filter_router_;
248 209
249 // Holds filters between the AddFilter call on the listerner thread and the 210 // Holds filters between the AddFilter call on the listerner thread and the
250 // IPC thread when they're added to filters_. 211 // IPC thread when they're added to filters_.
251 std::vector<scoped_refptr<MessageFilter> > pending_filters_; 212 std::vector<scoped_refptr<MessageFilter> > pending_filters_;
252 // Lock for pending_filters_. 213 // Lock for pending_filters_.
253 base::Lock pending_filters_lock_; 214 base::Lock pending_filters_lock_;
254 215
255 // Cached copy of the peer process ID. Set on IPC but read on both IPC and 216 // Cached copy of the peer process ID. Set on IPC but read on both IPC and
256 // listener threads. 217 // listener threads.
(...skipping 10 matching lines...) Expand all
267 // that involves this data. 228 // that involves this data.
268 scoped_refptr<Context> context_; 229 scoped_refptr<Context> context_;
269 230
270 // Whether the channel has been initialized. 231 // Whether the channel has been initialized.
271 bool did_init_; 232 bool did_init_;
272 }; 233 };
273 234
274 } // namespace IPC 235 } // namespace IPC
275 236
276 #endif // IPC_IPC_CHANNEL_PROXY_H_ 237 #endif // IPC_IPC_CHANNEL_PROXY_H_
OLDNEW
« no previous file with comments | « ipc/ipc.gypi ('k') | ipc/ipc_channel_proxy.cc » ('j') | ipc/ipc_message_filter.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698