| 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 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "base/threading/non_thread_safe.h" | 13 #include "base/threading/non_thread_safe.h" |
| 14 #include "ipc/ipc_channel.h" | 14 #include "ipc/ipc_channel.h" |
| 15 #include "ipc/ipc_channel_handle.h" | 15 #include "ipc/ipc_channel_handle.h" |
| 16 #include "ipc/ipc_listener.h" | 16 #include "ipc/ipc_listener.h" |
| 17 #include "ipc/ipc_sender.h" | 17 #include "ipc/ipc_sender.h" |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 class SingleThreadTaskRunner; | 20 class SingleThreadTaskRunner; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace IPC { | 23 namespace IPC { |
| 24 | 24 |
| 25 class ChannelFactory; |
| 25 class MessageFilter; | 26 class MessageFilter; |
| 26 class MessageFilterRouter; | 27 class MessageFilterRouter; |
| 27 class SendCallbackHelper; | 28 class SendCallbackHelper; |
| 28 | 29 |
| 29 //----------------------------------------------------------------------------- | 30 //----------------------------------------------------------------------------- |
| 30 // IPC::ChannelProxy | 31 // IPC::ChannelProxy |
| 31 // | 32 // |
| 32 // This class is a helper class that is useful when you wish to run an IPC | 33 // This class is a helper class that is useful when you wish to run an IPC |
| 33 // channel on a background thread. It provides you with the option of either | 34 // channel on a background thread. It provides you with the option of either |
| 34 // handling IPC messages on that background thread or having them dispatched to | 35 // handling IPC messages on that background thread or having them dispatched to |
| (...skipping 28 matching lines...) Expand all Loading... |
| 63 // filter may be null if the consumer is not interested in handling messages | 64 // filter may be null if the consumer is not interested in handling messages |
| 64 // on the background thread. Any message not handled by the filter will be | 65 // on the background thread. Any message not handled by the filter will be |
| 65 // dispatched to the listener. The given task runner correspond to a thread | 66 // dispatched to the listener. The given task runner correspond to a thread |
| 66 // on which IPC::Channel is created and used (e.g. IO thread). | 67 // on which IPC::Channel is created and used (e.g. IO thread). |
| 67 static scoped_ptr<ChannelProxy> Create( | 68 static scoped_ptr<ChannelProxy> Create( |
| 68 const IPC::ChannelHandle& channel_handle, | 69 const IPC::ChannelHandle& channel_handle, |
| 69 Channel::Mode mode, | 70 Channel::Mode mode, |
| 70 Listener* listener, | 71 Listener* listener, |
| 71 base::SingleThreadTaskRunner* ipc_task_runner); | 72 base::SingleThreadTaskRunner* ipc_task_runner); |
| 72 | 73 |
| 74 static scoped_ptr<ChannelProxy> Create( |
| 75 scoped_ptr<ChannelFactory> factory, |
| 76 Listener* listener, |
| 77 base::SingleThreadTaskRunner* ipc_task_runner); |
| 78 |
| 73 virtual ~ChannelProxy(); | 79 virtual ~ChannelProxy(); |
| 74 | 80 |
| 75 // Initializes the channel proxy. Only call this once to initialize a channel | 81 // Initializes the channel proxy. Only call this once to initialize a channel |
| 76 // proxy that was not initialized in its constructor. If create_pipe_now is | 82 // proxy that was not initialized in its constructor. If create_pipe_now is |
| 77 // true, the pipe is created synchronously. Otherwise it's created on the IO | 83 // true, the pipe is created synchronously. Otherwise it's created on the IO |
| 78 // thread. | 84 // thread. |
| 79 void Init(const IPC::ChannelHandle& channel_handle, Channel::Mode mode, | 85 void Init(const IPC::ChannelHandle& channel_handle, Channel::Mode mode, |
| 80 bool create_pipe_now); | 86 bool create_pipe_now); |
| 87 void Init(scoped_ptr<ChannelFactory> factory, bool create_pipe_now); |
| 81 | 88 |
| 82 // Close the IPC::Channel. This operation completes asynchronously, once the | 89 // Close the IPC::Channel. This operation completes asynchronously, once the |
| 83 // background thread processes the command to close the channel. It is ok to | 90 // background thread processes the command to close the channel. It is ok to |
| 84 // call this method multiple times. Redundant calls are ignored. | 91 // call this method multiple times. Redundant calls are ignored. |
| 85 // | 92 // |
| 86 // WARNING: MessageFilter objects held by the ChannelProxy is also | 93 // WARNING: MessageFilter objects held by the ChannelProxy is also |
| 87 // released asynchronously, and it may in fact have its final reference | 94 // released asynchronously, and it may in fact have its final reference |
| 88 // released on the background thread. The caller should be careful to deal | 95 // released on the background thread. The caller should be careful to deal |
| 89 // with / allow for this possibility. | 96 // with / allow for this possibility. |
| 90 void Close(); | 97 void Close(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 // Called on the consumers thread when the ChannelProxy is closed. At that | 171 // Called on the consumers thread when the ChannelProxy is closed. At that |
| 165 // point the consumer is telling us that they don't want to receive any | 172 // point the consumer is telling us that they don't want to receive any |
| 166 // more messages, so we honor that wish by forgetting them! | 173 // more messages, so we honor that wish by forgetting them! |
| 167 virtual void Clear(); | 174 virtual void Clear(); |
| 168 | 175 |
| 169 private: | 176 private: |
| 170 friend class ChannelProxy; | 177 friend class ChannelProxy; |
| 171 friend class SendCallbackHelper; | 178 friend class SendCallbackHelper; |
| 172 | 179 |
| 173 // Create the Channel | 180 // Create the Channel |
| 174 void CreateChannel(const IPC::ChannelHandle& channel_handle, | 181 void CreateChannel(scoped_ptr<ChannelFactory> factory); |
| 175 const Channel::Mode& mode); | |
| 176 | 182 |
| 177 // Methods called on the IO thread. | 183 // Methods called on the IO thread. |
| 178 void OnSendMessage(scoped_ptr<Message> message_ptr); | 184 void OnSendMessage(scoped_ptr<Message> message_ptr); |
| 179 void OnAddFilter(); | 185 void OnAddFilter(); |
| 180 void OnRemoveFilter(MessageFilter* filter); | 186 void OnRemoveFilter(MessageFilter* filter); |
| 181 | 187 |
| 182 // Methods called on the listener thread. | 188 // Methods called on the listener thread. |
| 183 void AddFilter(MessageFilter* filter); | 189 void AddFilter(MessageFilter* filter); |
| 184 void OnDispatchConnected(); | 190 void OnDispatchConnected(); |
| 185 void OnDispatchError(); | 191 void OnDispatchError(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 // that involves this data. | 230 // that involves this data. |
| 225 scoped_refptr<Context> context_; | 231 scoped_refptr<Context> context_; |
| 226 | 232 |
| 227 // Whether the channel has been initialized. | 233 // Whether the channel has been initialized. |
| 228 bool did_init_; | 234 bool did_init_; |
| 229 }; | 235 }; |
| 230 | 236 |
| 231 } // namespace IPC | 237 } // namespace IPC |
| 232 | 238 |
| 233 #endif // IPC_IPC_CHANNEL_PROXY_H_ | 239 #endif // IPC_IPC_CHANNEL_PROXY_H_ |
| OLD | NEW |