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

Side by Side Diff: ipc/ipc_channel_proxy.h

Issue 142923005: Allow MessageFilters to restrict listening to specific message classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Working patch Created 6 years, 10 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
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"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 virtual void OnChannelError(); 81 virtual void OnChannelError();
82 82
83 // Called to inform the filter that the IPC channel will be destroyed. 83 // Called to inform the filter that the IPC channel will be destroyed.
84 // OnFilterRemoved is called immediately after this. 84 // OnFilterRemoved is called immediately after this.
85 virtual void OnChannelClosing(); 85 virtual void OnChannelClosing();
86 86
87 // Return true to indicate that the message was handled, or false to let 87 // Return true to indicate that the message was handled, or false to let
88 // the message be handled in the default way. 88 // the message be handled in the default way.
89 virtual bool OnMessageReceived(const Message& message); 89 virtual bool OnMessageReceived(const Message& message);
90 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
91 protected: 98 protected:
92 virtual ~MessageFilter(); 99 virtual ~MessageFilter();
93 100
94 private: 101 private:
95 friend class base::RefCountedThreadSafe<MessageFilter>; 102 friend class base::RefCountedThreadSafe<MessageFilter>;
96 }; 103 };
97 104
98 // Initializes a channel proxy. The channel_handle and mode parameters are 105 // Initializes a channel proxy. The channel_handle and mode parameters are
99 // passed directly to the underlying IPC::Channel. The listener is called on 106 // passed directly to the underlying IPC::Channel. The listener is called on
100 // the thread that creates the ChannelProxy. The filter's OnMessageReceived 107 // the thread that creates the ChannelProxy. The filter's OnMessageReceived
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 224
218 // Methods called on the listener thread. 225 // Methods called on the listener thread.
219 void AddFilter(MessageFilter* filter); 226 void AddFilter(MessageFilter* filter);
220 void OnDispatchConnected(); 227 void OnDispatchConnected();
221 void OnDispatchError(); 228 void OnDispatchError();
222 229
223 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_; 230 scoped_refptr<base::SingleThreadTaskRunner> listener_task_runner_;
224 Listener* listener_; 231 Listener* listener_;
225 232
226 // List of filters. This is only accessed on the IPC thread. 233 // List of filters. This is only accessed on the IPC thread.
227 std::vector<scoped_refptr<MessageFilter> > filters_; 234 std::vector<scoped_refptr<MessageFilter> > all_filters_;
piman 2014/02/11 21:48:46 Do we need this? Can't we just iterate over messag
jdduke (slow) 2014/02/11 23:01:48 Well, there are a few operations where we iterate
228 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_; 235 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_;
229 scoped_ptr<Channel> channel_; 236 scoped_ptr<Channel> channel_;
230 std::string channel_id_; 237 std::string channel_id_;
231 bool channel_connected_called_; 238 bool channel_connected_called_;
232 239
240 // List of global and selective filters; a given filter from |all_filters_|
241 // will exists in either |message_global_filters_| OR
242 // |message_class_filters_|, but not both.
243 std::vector<MessageFilter*> message_global_filters_;
244 // TODO(jdduke): Determine if base::SmallMap is a sensible choice here,
245 // or simply an array of length (LastIPCMsgStart + 1).
epennerAtGoogle 2014/02/10 23:55:47 +1 to just a resized-vector, or something equivale
piman 2014/02/11 21:48:46 An array sg. Generally, hash_maps are preferred to
jdduke (slow) 2014/02/11 23:01:48 Done.
epennerAtGoogle 2014/02/12 02:34:09 Just FYI, I mentioned vector since it typically ha
246 typedef std::map<uint32, std::vector<MessageFilter*> >
247 MessageClassFilterMap;
248 MessageClassFilterMap message_class_filters_;
249
233 // Holds filters between the AddFilter call on the listerner thread and the 250 // Holds filters between the AddFilter call on the listerner thread and the
234 // IPC thread when they're added to filters_. 251 // IPC thread when they're added to filters_.
235 std::vector<scoped_refptr<MessageFilter> > pending_filters_; 252 std::vector<scoped_refptr<MessageFilter> > pending_filters_;
236 // Lock for pending_filters_. 253 // Lock for pending_filters_.
237 base::Lock pending_filters_lock_; 254 base::Lock pending_filters_lock_;
238 255
239 // Cached copy of the peer process ID. Set on IPC but read on both IPC and 256 // Cached copy of the peer process ID. Set on IPC but read on both IPC and
240 // listener threads. 257 // listener threads.
241 base::ProcessId peer_pid_; 258 base::ProcessId peer_pid_;
242 }; 259 };
243 260
244 Context* context() { return context_.get(); } 261 Context* context() { return context_.get(); }
245 262
246 private: 263 private:
247 friend class SendCallbackHelper; 264 friend class SendCallbackHelper;
248 265
249 // By maintaining this indirection (ref-counted) to our internal state, we 266 // By maintaining this indirection (ref-counted) to our internal state, we
250 // can safely be destroyed while the background thread continues to do stuff 267 // can safely be destroyed while the background thread continues to do stuff
251 // that involves this data. 268 // that involves this data.
252 scoped_refptr<Context> context_; 269 scoped_refptr<Context> context_;
253 270
254 // Whether the channel has been initialized. 271 // Whether the channel has been initialized.
255 bool did_init_; 272 bool did_init_;
256 }; 273 };
257 274
258 } // namespace IPC 275 } // namespace IPC
259 276
260 #endif // IPC_IPC_CHANNEL_PROXY_H_ 277 #endif // IPC_IPC_CHANNEL_PROXY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698