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