OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 // the consumer of IPC::ChannelProxy the ability to respond to incoming | 39 // the consumer of IPC::ChannelProxy the ability to respond to incoming |
40 // messages on this background thread instead of on their own thread, which may | 40 // messages on this background thread instead of on their own thread, which may |
41 // be bogged down with other processing. The result can be greatly improved | 41 // be bogged down with other processing. The result can be greatly improved |
42 // latency for messages that can be handled on a background thread. | 42 // latency for messages that can be handled on a background thread. |
43 // | 43 // |
44 // The consumer of IPC::ChannelProxy is responsible for allocating the Thread | 44 // The consumer of IPC::ChannelProxy is responsible for allocating the Thread |
45 // instance where the IPC::Channel will be created and operated. | 45 // instance where the IPC::Channel will be created and operated. |
46 // | 46 // |
47 class ChannelProxy : public Message::Sender { | 47 class ChannelProxy : public Message::Sender { |
48 public: | 48 public: |
| 49 |
| 50 class MessageFilter; |
| 51 struct MessageFilterTraits { |
| 52 static void Destruct(MessageFilter* filter); |
| 53 }; |
| 54 |
49 // 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 |
50 // 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. |
51 class MessageFilter : public base::RefCountedThreadSafe<MessageFilter> { | 57 class MessageFilter |
| 58 : public base::RefCountedThreadSafe<MessageFilter, MessageFilterTraits> { |
52 public: | 59 public: |
53 virtual ~MessageFilter() {} | 60 virtual ~MessageFilter() {} |
54 | 61 |
55 // 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 |
56 // channel. Called when the IPC channel is initialized or when AddFilter | 63 // channel. Called when the IPC channel is initialized or when AddFilter |
57 // is called if the channel is already initialized. | 64 // is called if the channel is already initialized. |
58 virtual void OnFilterAdded(Channel* channel) {} | 65 virtual void OnFilterAdded(Channel* channel) {} |
59 | 66 |
60 // 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 |
61 // 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 |
(...skipping 10 matching lines...) Expand all Loading... |
72 | 79 |
73 // Called to inform the filter that the IPC channel will be destroyed. | 80 // Called to inform the filter that the IPC channel will be destroyed. |
74 // OnFilterRemoved is called immediately after this. | 81 // OnFilterRemoved is called immediately after this. |
75 virtual void OnChannelClosing() {} | 82 virtual void OnChannelClosing() {} |
76 | 83 |
77 // 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 |
78 // the message be handled in the default way. | 85 // the message be handled in the default way. |
79 virtual bool OnMessageReceived(const Message& message) { | 86 virtual bool OnMessageReceived(const Message& message) { |
80 return false; | 87 return false; |
81 } | 88 } |
| 89 |
| 90 // Called when the message filter is about to be deleted. This gives |
| 91 // derived classes the option of controlling which thread they're deleted |
| 92 // on etc. |
| 93 virtual void OnDestruct() { |
| 94 delete this; |
| 95 } |
82 }; | 96 }; |
83 | 97 |
84 // Initializes a channel proxy. The channel_id and mode parameters are | 98 // Initializes a channel proxy. The channel_id and mode parameters are |
85 // passed directly to the underlying IPC::Channel. The listener is called on | 99 // passed directly to the underlying IPC::Channel. The listener is called on |
86 // the thread that creates the ChannelProxy. The filter's OnMessageReceived | 100 // the thread that creates the ChannelProxy. The filter's OnMessageReceived |
87 // method is called on the thread where the IPC::Channel is running. The | 101 // method is called on the thread where the IPC::Channel is running. The |
88 // filter may be null if the consumer is not interested in handling messages | 102 // filter may be null if the consumer is not interested in handling messages |
89 // on the background thread. Any message not handled by the filter will be | 103 // on the background thread. Any message not handled by the filter will be |
90 // dispatched to the listener. The given message loop indicates where the | 104 // dispatched to the listener. The given message loop indicates where the |
91 // IPC::Channel should be created. | 105 // IPC::Channel should be created. |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 223 |
210 // By maintaining this indirection (ref-counted) to our internal state, we | 224 // By maintaining this indirection (ref-counted) to our internal state, we |
211 // can safely be destroyed while the background thread continues to do stuff | 225 // can safely be destroyed while the background thread continues to do stuff |
212 // that involves this data. | 226 // that involves this data. |
213 scoped_refptr<Context> context_; | 227 scoped_refptr<Context> context_; |
214 }; | 228 }; |
215 | 229 |
216 } // namespace IPC | 230 } // namespace IPC |
217 | 231 |
218 #endif // IPC_IPC_CHANNEL_PROXY_H__ | 232 #endif // IPC_IPC_CHANNEL_PROXY_H__ |
OLD | NEW |