message_filter.h 2.3 KB

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