• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 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_MESSAGE_FILTER_H_
6 #define IPC_MESSAGE_FILTER_H_
7 
8 #include <stdint.h>
9 
10 #include <vector>
11 
12 #include "base/component_export.h"
13 #include "base/memory/ref_counted.h"
14 #include "ipc/ipc_channel.h"
15 
16 namespace IPC {
17 
18 class Message;
19 
20 // A class that receives messages on the thread where the IPC channel is
21 // running.  It can choose to prevent the default action for an IPC message.
COMPONENT_EXPORT(IPC)22 class COMPONENT_EXPORT(IPC) MessageFilter
23     : public base::RefCountedThreadSafe<MessageFilter> {
24  public:
25   MessageFilter();
26 
27   // Called on the background thread to provide the filter with access to the
28   // channel.  Called when the IPC channel is initialized or when AddFilter
29   // is called if the channel is already initialized.
30   virtual void OnFilterAdded(Channel* channel);
31 
32   // Called on the background thread when the filter has been removed from
33   // the ChannelProxy and when the Channel is closing.  After a filter is
34   // removed, it will not be called again.
35   virtual void OnFilterRemoved();
36 
37   // Called to inform the filter that the IPC channel is connected and we
38   // have received the internal Hello message from the peer.
39   virtual void OnChannelConnected(int32_t peer_pid);
40 
41   // Called when there is an error on the channel, typically that the channel
42   // has been closed.
43   virtual void OnChannelError();
44 
45   // Called to inform the filter that the IPC channel will be destroyed.
46   // OnFilterRemoved is called immediately after this.
47   virtual void OnChannelClosing();
48 
49   // Return true to indicate that the message was handled, or false to let
50   // the message be handled in the default way.
51   virtual bool OnMessageReceived(const Message& message);
52 
53   // Called to query the Message classes supported by the filter.  Return
54   // false to indicate that all message types should reach the filter, or true
55   // if the resulting contents of |supported_message_classes| may be used to
56   // selectively offer messages of a particular class to the filter.
57   virtual bool GetSupportedMessageClasses(
58       std::vector<uint32_t>* supported_message_classes) const;
59 
60  protected:
61   virtual ~MessageFilter();
62 
63  private:
64   friend class base::RefCountedThreadSafe<MessageFilter>;
65 };
66 
67 }  // namespace IPC
68 
69 #endif  // IPC_MESSAGE_FILTER_H_
70