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