| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_IPC_CHANNEL_PROXY_H_ | 5 #ifndef IPC_IPC_CHANNEL_PROXY_H_ |
| 6 #define IPC_IPC_CHANNEL_PROXY_H_ | 6 #define IPC_IPC_CHANNEL_PROXY_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 public: | 51 public: |
| 52 | 52 |
| 53 struct MessageFilterTraits; | 53 struct MessageFilterTraits; |
| 54 | 54 |
| 55 // A class that receives messages on the thread where the IPC channel is | 55 // A class that receives messages on the thread where the IPC channel is |
| 56 // running. It can choose to prevent the default action for an IPC message. | 56 // running. It can choose to prevent the default action for an IPC message. |
| 57 class IPC_EXPORT MessageFilter | 57 class IPC_EXPORT MessageFilter |
| 58 : public base::RefCountedThreadSafe<MessageFilter, MessageFilterTraits> { | 58 : public base::RefCountedThreadSafe<MessageFilter, MessageFilterTraits> { |
| 59 public: | 59 public: |
| 60 MessageFilter(); | 60 MessageFilter(); |
| 61 virtual ~MessageFilter(); | |
| 62 | 61 |
| 63 // Called on the background thread to provide the filter with access to the | 62 // Called on the background thread to provide the filter with access to the |
| 64 // channel. Called when the IPC channel is initialized or when AddFilter | 63 // channel. Called when the IPC channel is initialized or when AddFilter |
| 65 // is called if the channel is already initialized. | 64 // is called if the channel is already initialized. |
| 66 virtual void OnFilterAdded(Channel* channel); | 65 virtual void OnFilterAdded(Channel* channel); |
| 67 | 66 |
| 68 // Called on the background thread when the filter has been removed from | 67 // Called on the background thread when the filter has been removed from |
| 69 // the ChannelProxy and when the Channel is closing. After a filter is | 68 // the ChannelProxy and when the Channel is closing. After a filter is |
| 70 // removed, it will not be called again. | 69 // removed, it will not be called again. |
| 71 virtual void OnFilterRemoved(); | 70 virtual void OnFilterRemoved(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 83 virtual void OnChannelClosing(); | 82 virtual void OnChannelClosing(); |
| 84 | 83 |
| 85 // Return true to indicate that the message was handled, or false to let | 84 // Return true to indicate that the message was handled, or false to let |
| 86 // the message be handled in the default way. | 85 // the message be handled in the default way. |
| 87 virtual bool OnMessageReceived(const Message& message); | 86 virtual bool OnMessageReceived(const Message& message); |
| 88 | 87 |
| 89 // Called when the message filter is about to be deleted. This gives | 88 // Called when the message filter is about to be deleted. This gives |
| 90 // derived classes the option of controlling which thread they're deleted | 89 // derived classes the option of controlling which thread they're deleted |
| 91 // on etc. | 90 // on etc. |
| 92 virtual void OnDestruct() const; | 91 virtual void OnDestruct() const; |
| 92 |
| 93 protected: |
| 94 virtual ~MessageFilter(); |
| 95 |
| 96 private: |
| 97 friend class base::RefCountedThreadSafe<MessageFilter, |
| 98 MessageFilterTraits>; |
| 93 }; | 99 }; |
| 94 | 100 |
| 95 struct MessageFilterTraits { | 101 struct MessageFilterTraits { |
| 96 static void Destruct(const MessageFilter* filter) { | 102 static void Destruct(const MessageFilter* filter) { |
| 97 filter->OnDestruct(); | 103 filter->OnDestruct(); |
| 98 } | 104 } |
| 99 }; | 105 }; |
| 100 | 106 |
| 107 |
| 101 // Interface for a filter to be imposed on outgoing messages which can | 108 // Interface for a filter to be imposed on outgoing messages which can |
| 102 // re-write the message. Used mainly for testing. | 109 // re-write the message. Used mainly for testing. |
| 103 class OutgoingMessageFilter { | 110 class OutgoingMessageFilter { |
| 104 public: | 111 public: |
| 105 // Returns a re-written message, freeing the original, or simply the | 112 // Returns a re-written message, freeing the original, or simply the |
| 106 // original unchanged if no rewrite indicated. | 113 // original unchanged if no rewrite indicated. |
| 107 virtual Message *Rewrite(Message *message) = 0; | 114 virtual Message *Rewrite(Message *message) = 0; |
| 108 }; | 115 }; |
| 109 | 116 |
| 110 // Initializes a channel proxy. The channel_handle and mode parameters are | 117 // Initializes a channel proxy. The channel_handle and mode parameters are |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 233 |
| 227 private: | 234 private: |
| 228 friend class ChannelProxy; | 235 friend class ChannelProxy; |
| 229 friend class SendCallbackHelper; | 236 friend class SendCallbackHelper; |
| 230 | 237 |
| 231 // Create the Channel | 238 // Create the Channel |
| 232 void CreateChannel(const IPC::ChannelHandle& channel_handle, | 239 void CreateChannel(const IPC::ChannelHandle& channel_handle, |
| 233 const Channel::Mode& mode); | 240 const Channel::Mode& mode); |
| 234 | 241 |
| 235 // Methods called on the IO thread. | 242 // Methods called on the IO thread. |
| 236 void OnSendMessage(Message* message_ptr); | 243 void OnSendMessage(scoped_ptr<Message> message_ptr); |
| 237 void OnAddFilter(); | 244 void OnAddFilter(); |
| 238 void OnRemoveFilter(MessageFilter* filter); | 245 void OnRemoveFilter(MessageFilter* filter); |
| 239 | 246 |
| 240 // Methods called on the listener thread. | 247 // Methods called on the listener thread. |
| 241 void AddFilter(MessageFilter* filter); | 248 void AddFilter(MessageFilter* filter); |
| 242 void OnDispatchConnected(); | 249 void OnDispatchConnected(); |
| 243 void OnDispatchError(); | 250 void OnDispatchError(); |
| 244 | 251 |
| 245 scoped_refptr<base::MessageLoopProxy> listener_message_loop_; | 252 scoped_refptr<base::MessageLoopProxy> listener_message_loop_; |
| 246 Channel::Listener* listener_; | 253 Channel::Listener* listener_; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 286 |
| 280 OutgoingMessageFilter* outgoing_message_filter_; | 287 OutgoingMessageFilter* outgoing_message_filter_; |
| 281 | 288 |
| 282 // Whether the channel has been initialized. | 289 // Whether the channel has been initialized. |
| 283 bool did_init_; | 290 bool did_init_; |
| 284 }; | 291 }; |
| 285 | 292 |
| 286 } // namespace IPC | 293 } // namespace IPC |
| 287 | 294 |
| 288 #endif // IPC_IPC_CHANNEL_PROXY_H_ | 295 #endif // IPC_IPC_CHANNEL_PROXY_H_ |
| OLD | NEW |