Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / ipc / message_filter.h
blobf70ee069fc28921e26e07496850fa8ebfac55b9d
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.
5 #ifndef IPC_MESSAGE_FILTER_H_
6 #define IPC_MESSAGE_FILTER_H_
8 #include <stdint.h>
10 #include <vector>
12 #include "base/memory/ref_counted.h"
13 #include "ipc/ipc_export.h"
15 namespace IPC {
17 class Sender;
18 class Message;
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.
22 class IPC_EXPORT MessageFilter
23 : public base::RefCountedThreadSafe<MessageFilter> {
24 public:
25 MessageFilter();
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(Sender* sender);
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();
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);
41 // Called when there is an error on the channel, typically that the channel
42 // has been closed.
43 virtual void OnChannelError();
45 // Called to inform the filter that the IPC channel will be destroyed.
46 // OnFilterRemoved is called immediately after this.
47 virtual void OnChannelClosing();
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);
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;
60 protected:
61 virtual ~MessageFilter();
63 private:
64 friend class base::RefCountedThreadSafe<MessageFilter>;
67 } // namespace IPC
69 #endif // IPC_MESSAGE_FILTER_H_