Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: ipc/ipc_channel_proxy.h

Issue 8417054: Allow proxy channels to be created without initializing the underlying channel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/automation/automation_proxy.cc ('k') | ipc/ipc_channel_proxy.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // method is called on the thread where the IPC::Channel is running. The 113 // method is called on the thread where the IPC::Channel is running. The
114 // filter may be null if the consumer is not interested in handling messages 114 // filter may be null if the consumer is not interested in handling messages
115 // on the background thread. Any message not handled by the filter will be 115 // on the background thread. Any message not handled by the filter will be
116 // dispatched to the listener. The given message loop indicates where the 116 // dispatched to the listener. The given message loop indicates where the
117 // IPC::Channel should be created. 117 // IPC::Channel should be created.
118 ChannelProxy(const IPC::ChannelHandle& channel_handle, 118 ChannelProxy(const IPC::ChannelHandle& channel_handle,
119 Channel::Mode mode, 119 Channel::Mode mode,
120 Channel::Listener* listener, 120 Channel::Listener* listener,
121 base::MessageLoopProxy* ipc_thread_loop); 121 base::MessageLoopProxy* ipc_thread_loop);
122 122
123 // Creates an uninitialized channel proxy. Init must be called to receive
124 // or send any messages. This two-step setup allows message filters to be
125 // added before any messages are sent or received.
126 ChannelProxy(Channel::Listener* listener,
127 base::MessageLoopProxy* ipc_thread_loop);
128
123 virtual ~ChannelProxy(); 129 virtual ~ChannelProxy();
124 130
131 // Initializes the channel proxy. Only call this once to initialize a channel
132 // proxy that was not initialized in its constructor. If create_pipe_now is
133 // true, the pipe is created synchronously. Otherwise it's created on the IO
134 // thread.
135 void Init(const IPC::ChannelHandle& channel_handle, Channel::Mode mode,
136 bool create_pipe_now);
137
125 // Close the IPC::Channel. This operation completes asynchronously, once the 138 // Close the IPC::Channel. This operation completes asynchronously, once the
126 // background thread processes the command to close the channel. It is ok to 139 // background thread processes the command to close the channel. It is ok to
127 // call this method multiple times. Redundant calls are ignored. 140 // call this method multiple times. Redundant calls are ignored.
128 // 141 //
129 // WARNING: The MessageFilter object held by the ChannelProxy is also 142 // WARNING: The MessageFilter object held by the ChannelProxy is also
130 // released asynchronously, and it may in fact have its final reference 143 // released asynchronously, and it may in fact have its final reference
131 // released on the background thread. The caller should be careful to deal 144 // released on the background thread. The caller should be careful to deal
132 // with / allow for this possibility. 145 // with / allow for this possibility.
133 void Close(); 146 void Close();
134 147
(...skipping 23 matching lines...) Expand all
158 #if defined(OS_POSIX) 171 #if defined(OS_POSIX)
159 // Calls through to the underlying channel's methods. 172 // Calls through to the underlying channel's methods.
160 int GetClientFileDescriptor(); 173 int GetClientFileDescriptor();
161 int TakeClientFileDescriptor(); 174 int TakeClientFileDescriptor();
162 bool GetClientEuid(uid_t* client_euid) const; 175 bool GetClientEuid(uid_t* client_euid) const;
163 #endif // defined(OS_POSIX) 176 #endif // defined(OS_POSIX)
164 177
165 protected: 178 protected:
166 class Context; 179 class Context;
167 // A subclass uses this constructor if it needs to add more information 180 // A subclass uses this constructor if it needs to add more information
168 // to the internal state. If create_pipe_now is true, the pipe is created 181 // to the internal state.
169 // immediately. Otherwise it's created on the IO thread. 182 ChannelProxy(Context* context);
170 ChannelProxy(const IPC::ChannelHandle& channel_handle,
171 Channel::Mode mode,
172 base::MessageLoopProxy* ipc_thread_loop,
173 Context* context,
174 bool create_pipe_now);
175 183
176 // Used internally to hold state that is referenced on the IPC thread. 184 // Used internally to hold state that is referenced on the IPC thread.
177 class Context : public base::RefCountedThreadSafe<Context>, 185 class Context : public base::RefCountedThreadSafe<Context>,
178 public Channel::Listener { 186 public Channel::Listener {
179 public: 187 public:
180 Context(Channel::Listener* listener, base::MessageLoopProxy* ipc_thread); 188 Context(Channel::Listener* listener, base::MessageLoopProxy* ipc_thread);
181 void ClearIPCMessageLoop() { ipc_message_loop_ = NULL; } 189 void ClearIPCMessageLoop() { ipc_message_loop_ = NULL; }
182 base::MessageLoopProxy* ipc_message_loop() const { 190 base::MessageLoopProxy* ipc_message_loop() const {
183 return ipc_message_loop_.get(); 191 return ipc_message_loop_.get();
184 } 192 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 258
251 Context* context() { return context_; } 259 Context* context() { return context_; }
252 260
253 OutgoingMessageFilter* outgoing_message_filter() { 261 OutgoingMessageFilter* outgoing_message_filter() {
254 return outgoing_message_filter_; 262 return outgoing_message_filter_;
255 } 263 }
256 264
257 private: 265 private:
258 friend class SendTask; 266 friend class SendTask;
259 267
260 void Init(const IPC::ChannelHandle& channel_handle, Channel::Mode mode,
261 base::MessageLoopProxy* ipc_thread_loop, bool create_pipe_now);
262
263 // By maintaining this indirection (ref-counted) to our internal state, we 268 // By maintaining this indirection (ref-counted) to our internal state, we
264 // can safely be destroyed while the background thread continues to do stuff 269 // can safely be destroyed while the background thread continues to do stuff
265 // that involves this data. 270 // that involves this data.
266 scoped_refptr<Context> context_; 271 scoped_refptr<Context> context_;
267 272
268 OutgoingMessageFilter* outgoing_message_filter_; 273 OutgoingMessageFilter* outgoing_message_filter_;
274
275 // Whether the channel has been initialized.
276 bool did_init_;
269 }; 277 };
270 278
271 } // namespace IPC 279 } // namespace IPC
272 280
273 #endif // IPC_IPC_CHANNEL_PROXY_H_ 281 #endif // IPC_IPC_CHANNEL_PROXY_H_
OLDNEW
« no previous file with comments | « chrome/test/automation/automation_proxy.cc ('k') | ipc/ipc_channel_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698