| 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" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe { | 57 class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe { |
| 58 public: | 58 public: |
| 59 // Initializes a channel proxy. The channel_handle and mode parameters are | 59 // Initializes a channel proxy. The channel_handle and mode parameters are |
| 60 // passed directly to the underlying IPC::Channel. The listener is called on | 60 // passed directly to the underlying IPC::Channel. The listener is called on |
| 61 // the thread that creates the ChannelProxy. The filter's OnMessageReceived | 61 // the thread that creates the ChannelProxy. The filter's OnMessageReceived |
| 62 // method is called on the thread where the IPC::Channel is running. The | 62 // method is called on the thread where the IPC::Channel is running. The |
| 63 // filter may be null if the consumer is not interested in handling messages | 63 // 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 | 64 // 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 | 65 // 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). | 66 // on which IPC::Channel is created and used (e.g. IO thread). |
| 67 ChannelProxy(const IPC::ChannelHandle& channel_handle, | 67 // The naming pattern follows IPC::Channel. The Create() does not create |
| 68 Channel::Mode mode, | 68 // underlying channel and let Init*() do it. |
| 69 Listener* listener, | 69 static scoped_ptr<ChannelProxy> Create( |
| 70 base::SingleThreadTaskRunner* ipc_task_runner); | 70 Listener* listener, |
| 71 base::SingleThreadTaskRunner* ipc_task_runner); |
| 72 |
| 73 static scoped_ptr<ChannelProxy> CreateClient( |
| 74 const IPC::ChannelHandle& channel_handle, |
| 75 Listener* listener, |
| 76 base::SingleThreadTaskRunner* ipc_task_runner); |
| 77 |
| 78 static scoped_ptr<ChannelProxy> CreateServer( |
| 79 const IPC::ChannelHandle& channel_handle, |
| 80 Listener* listener, |
| 81 base::SingleThreadTaskRunner* ipc_task_runner); |
| 82 |
| 83 static scoped_ptr<ChannelProxy> CreateNamedClient( |
| 84 const IPC::ChannelHandle& channel_handle, |
| 85 Listener* listener, |
| 86 base::SingleThreadTaskRunner* ipc_task_runner); |
| 87 |
| 88 static scoped_ptr<ChannelProxy> CreateNamedServer( |
| 89 const IPC::ChannelHandle& channel_handle, |
| 90 Listener* listener, |
| 91 base::SingleThreadTaskRunner* ipc_task_runner); |
| 71 | 92 |
| 72 virtual ~ChannelProxy(); | 93 virtual ~ChannelProxy(); |
| 73 | 94 |
| 74 // Initializes the channel proxy. Only call this once to initialize a channel | 95 // Initializes the channel proxy. Only call this once to initialize a channel |
| 75 // proxy that was not initialized in its constructor. If create_pipe_now is | 96 // proxy that was not initialized in its constructor. If create_pipe_now is |
| 76 // true, the pipe is created synchronously. Otherwise it's created on the IO | 97 // true, the pipe is created synchronously. Otherwise it's created on the IO |
| 77 // thread. | 98 // thread. |
| 78 void Init(const IPC::ChannelHandle& channel_handle, Channel::Mode mode, | 99 // The naming pattern follows IPC::Channel::Create*(). |
| 79 bool create_pipe_now); | 100 void InitByMode(const IPC::ChannelHandle& channel_handle, Channel::Mode mode, |
| 101 bool create_pipe_now); |
| 102 void InitClient(const IPC::ChannelHandle& channel_handle, |
| 103 bool create_pipe_now); |
| 104 void InitServer(const IPC::ChannelHandle& channel_handle, |
| 105 bool create_pipe_now); |
| 106 void InitNamedClient(const IPC::ChannelHandle& channel_handle, |
| 107 bool create_pipe_now); |
| 108 void InitNamedServer(const IPC::ChannelHandle& channel_handle, |
| 109 bool create_pipe_now); |
| 80 | 110 |
| 81 // Close the IPC::Channel. This operation completes asynchronously, once the | 111 // Close the IPC::Channel. This operation completes asynchronously, once the |
| 82 // background thread processes the command to close the channel. It is ok to | 112 // background thread processes the command to close the channel. It is ok to |
| 83 // call this method multiple times. Redundant calls are ignored. | 113 // call this method multiple times. Redundant calls are ignored. |
| 84 // | 114 // |
| 85 // WARNING: MessageFilter objects held by the ChannelProxy is also | 115 // WARNING: MessageFilter objects held by the ChannelProxy is also |
| 86 // released asynchronously, and it may in fact have its final reference | 116 // released asynchronously, and it may in fact have its final reference |
| 87 // released on the background thread. The caller should be careful to deal | 117 // released on the background thread. The caller should be careful to deal |
| 88 // with / allow for this possibility. | 118 // with / allow for this possibility. |
| 89 void Close(); | 119 void Close(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 117 int TakeClientFileDescriptor(); | 147 int TakeClientFileDescriptor(); |
| 118 bool GetPeerEuid(uid_t* peer_euid) const; | 148 bool GetPeerEuid(uid_t* peer_euid) const; |
| 119 #endif // defined(OS_POSIX) | 149 #endif // defined(OS_POSIX) |
| 120 | 150 |
| 121 protected: | 151 protected: |
| 122 class Context; | 152 class Context; |
| 123 // A subclass uses this constructor if it needs to add more information | 153 // A subclass uses this constructor if it needs to add more information |
| 124 // to the internal state. | 154 // to the internal state. |
| 125 ChannelProxy(Context* context); | 155 ChannelProxy(Context* context); |
| 126 | 156 |
| 157 ChannelProxy(Listener* listener, |
| 158 base::SingleThreadTaskRunner* ipc_task_runner); |
| 159 |
| 160 |
| 127 // Used internally to hold state that is referenced on the IPC thread. | 161 // Used internally to hold state that is referenced on the IPC thread. |
| 128 class Context : public base::RefCountedThreadSafe<Context>, | 162 class Context : public base::RefCountedThreadSafe<Context>, |
| 129 public Listener { | 163 public Listener { |
| 130 public: | 164 public: |
| 131 Context(Listener* listener, base::SingleThreadTaskRunner* ipc_thread); | 165 Context(Listener* listener, base::SingleThreadTaskRunner* ipc_thread); |
| 132 void ClearIPCTaskRunner(); | 166 void ClearIPCTaskRunner(); |
| 133 base::SingleThreadTaskRunner* ipc_task_runner() const { | 167 base::SingleThreadTaskRunner* ipc_task_runner() const { |
| 134 return ipc_task_runner_.get(); | 168 return ipc_task_runner_.get(); |
| 135 } | 169 } |
| 136 const std::string& channel_id() const { return channel_id_; } | 170 const std::string& channel_id() const { return channel_id_; } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 // that involves this data. | 255 // that involves this data. |
| 222 scoped_refptr<Context> context_; | 256 scoped_refptr<Context> context_; |
| 223 | 257 |
| 224 // Whether the channel has been initialized. | 258 // Whether the channel has been initialized. |
| 225 bool did_init_; | 259 bool did_init_; |
| 226 }; | 260 }; |
| 227 | 261 |
| 228 } // namespace IPC | 262 } // namespace IPC |
| 229 | 263 |
| 230 #endif // IPC_IPC_CHANNEL_PROXY_H_ | 264 #endif // IPC_IPC_CHANNEL_PROXY_H_ |
| OLD | NEW |