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

Side by Side Diff: ipc/ipc_message_filter.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
(Empty)
1 // Copyright (c) 2014 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_MESSAGE_FILTER_H_
6 #define IPC_IPC_MESSAGE_FILTER_H_
7
8 #include <vector>
9
10 #include "base/memory/ref_counted.h"
11 #include "ipc/ipc_export.h"
12 #include "ipc/ipc_message_start.h"
13
14 namespace IPC {
15
16 class Channel;
17 class Message;
18
19 // A class that receives messages on the thread where the IPC channel is
20 // running. It can choose to prevent the default action for an IPC message.
21 class IPC_EXPORT MessageFilter
22 : public base::RefCountedThreadSafe<MessageFilter> {
23 public:
24 MessageFilter();
25
26 // Called on the background thread to provide the filter with access to the
27 // channel. Called when the IPC channel is initialized or when AddFilter
28 // is called if the channel is already initialized.
29 virtual void OnFilterAdded(Channel* channel);
30
31 // Called on the background thread when the filter has been removed from
32 // the ChannelProxy and when the Channel is closing. After a filter is
33 // removed, it will not be called again.
34 virtual void OnFilterRemoved();
35
36 // Called to inform the filter that the IPC channel is connected and we
37 // have received the internal Hello message from the peer.
38 virtual void OnChannelConnected(int32 peer_pid);
39
40 // Called when there is an error on the channel, typically that the channel
41 // has been closed.
42 virtual void OnChannelError();
43
44 // Called to inform the filter that the IPC channel will be destroyed.
45 // OnFilterRemoved is called immediately after this.
46 virtual void OnChannelClosing();
47
48 // Return true to indicate that the message was handled, or false to let
49 // the message be handled in the default way.
50 virtual bool OnMessageReceived(const Message& message);
51
52 // Called to query the Message classes supported by the filter. Return
53 // false to indicate that all message types should reach the filter, or true
54 // if the resulting contents of |supported_message_classes| may be used to
55 // selectively offer messages of a particular class to the filter.
56 virtual bool GetSupportedMessageClasses(
57 std::vector<uint32>* supported_message_classes) const;
58
59 protected:
60 virtual ~MessageFilter();
61
62 private:
63 friend class base::RefCountedThreadSafe<MessageFilter>;
64 };
65
66 //------------------------------------------------------------------------------
67
68 class MessageFilterRouter {
jam 2014/04/22 17:14:27 put this in a separate file
dmichael (off chromium) 2014/04/23 19:42:31 Done.
69 public:
70 typedef std::vector<MessageFilter*> MessageFilters;
71
72 MessageFilterRouter();
73 ~MessageFilterRouter();
74
75 void AddFilter(MessageFilter* filter);
76 void RemoveFilter(MessageFilter* filter);
77 bool TryFilters(const Message& message);
78 void Clear();
79
80 private:
81 // List of global and selective filters; a given filter will exist in either
82 // |message_global_filters_| OR |message_class_filters_|, but not both.
83 // Note that |message_global_filters_| will be given first offering of any
84 // given message. It's the filter implementer and installer's
85 // responsibility to ensure that a filter is either global or selective to
86 // ensure proper message filtering order.
87 MessageFilters global_filters_;
88 MessageFilters message_class_filters_[LastIPCMsgStart];
89 };
90
91 } // namespace IPC
92
93 #endif // IPC_IPC_MESSAGE_FILTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698