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

Side by Side Diff: ipc/ipc_channel_proxy.h

Issue 5598010: Convert over to channel handles (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed up bad whitespace Created 10 years 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
OLDNEW
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 #pragma once 7 #pragma once
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/lock.h" 11 #include "base/lock.h"
12 #include "base/ref_counted.h" 12 #include "base/ref_counted.h"
13 #include "base/scoped_ptr.h"
13 #include "ipc/ipc_channel.h" 14 #include "ipc/ipc_channel.h"
15 #include "ipc/ipc_channel_handle.h"
14 16
15 class MessageLoop; 17 class MessageLoop;
16 18
17 namespace IPC { 19 namespace IPC {
18 20
19 class SendTask; 21 class SendTask;
20 22
21 //----------------------------------------------------------------------------- 23 //-----------------------------------------------------------------------------
22 // IPC::ChannelProxy 24 // IPC::ChannelProxy
23 // 25 //
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // on etc. 92 // on etc.
91 virtual void OnDestruct() const; 93 virtual void OnDestruct() const;
92 }; 94 };
93 95
94 struct MessageFilterTraits { 96 struct MessageFilterTraits {
95 static void Destruct(const MessageFilter* filter) { 97 static void Destruct(const MessageFilter* filter) {
96 filter->OnDestruct(); 98 filter->OnDestruct();
97 } 99 }
98 }; 100 };
99 101
100 // Initializes a channel proxy. The channel_id and mode parameters are 102 // Initializes a channel proxy. The channel_handle and mode parameters are
101 // passed directly to the underlying IPC::Channel. The listener is called on 103 // passed directly to the underlying IPC::Channel. The listener is called on
102 // the thread that creates the ChannelProxy. The filter's OnMessageReceived 104 // the thread that creates the ChannelProxy. The filter's OnMessageReceived
103 // method is called on the thread where the IPC::Channel is running. The 105 // method is called on the thread where the IPC::Channel is running. The
104 // filter may be null if the consumer is not interested in handling messages 106 // filter may be null if the consumer is not interested in handling messages
105 // on the background thread. Any message not handled by the filter will be 107 // on the background thread. Any message not handled by the filter will be
106 // dispatched to the listener. The given message loop indicates where the 108 // dispatched to the listener. The given message loop indicates where the
107 // IPC::Channel should be created. 109 // IPC::Channel should be created.
108 ChannelProxy(const std::string& channel_id, 110 ChannelProxy(const IPC::ChannelHandle& channel_handle,
109 Channel::Mode mode, 111 Channel::Mode mode,
110 Channel::Listener* listener, 112 Channel::Listener* listener,
111 MessageLoop* ipc_thread_loop); 113 MessageLoop* ipc_thread_loop);
112 114
113 virtual ~ChannelProxy(); 115 virtual ~ChannelProxy();
114 116
115 // Close the IPC::Channel. This operation completes asynchronously, once the 117 // Close the IPC::Channel. This operation completes asynchronously, once the
116 // background thread processes the command to close the channel. It is ok to 118 // background thread processes the command to close the channel. It is ok to
117 // call this method multiple times. Redundant calls are ignored. 119 // call this method multiple times. Redundant calls are ignored.
118 // 120 //
(...skipping 17 matching lines...) Expand all
136 // then some messages might be missed since the filter is added internally on 138 // then some messages might be missed since the filter is added internally on
137 // the IO thread. 139 // the IO thread.
138 void AddFilter(MessageFilter* filter); 140 void AddFilter(MessageFilter* filter);
139 void RemoveFilter(MessageFilter* filter); 141 void RemoveFilter(MessageFilter* filter);
140 142
141 // Called to clear the pointer to the IPC message loop when it's going away. 143 // Called to clear the pointer to the IPC message loop when it's going away.
142 void ClearIPCMessageLoop(); 144 void ClearIPCMessageLoop();
143 145
144 #if defined(OS_POSIX) 146 #if defined(OS_POSIX)
145 // Calls through to the underlying channel's methods. 147 // Calls through to the underlying channel's methods.
146 // TODO(playmobil): For now this is only implemented in the case of
147 // create_pipe_now = true, we need to figure this out for the latter case.
148 int GetClientFileDescriptor() const; 148 int GetClientFileDescriptor() const;
149 #endif // defined(OS_POSIX) 149 #endif // defined(OS_POSIX)
150 150
151 protected: 151 protected:
152 class Context; 152 class Context;
153 // 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
154 // to the internal state. If create_pipe_now is true, the pipe is created 154 // to the internal state. If create_pipe_now is true, the pipe is created
155 // immediately. Otherwise it's created on the IO thread. 155 // immediately. Otherwise it's created on the IO thread.
156 ChannelProxy(const std::string& channel_id, 156 ChannelProxy(const IPC::ChannelHandle& channel_handle,
157 Channel::Mode mode, 157 Channel::Mode mode,
158 MessageLoop* ipc_thread_loop, 158 MessageLoop* ipc_thread_loop,
159 Context* context, 159 Context* context,
160 bool create_pipe_now); 160 bool create_pipe_now);
161 161
162 // Used internally to hold state that is referenced on the IPC thread. 162 // Used internally to hold state that is referenced on the IPC thread.
163 class Context : public base::RefCountedThreadSafe<Context>, 163 class Context : public base::RefCountedThreadSafe<Context>,
164 public Channel::Listener { 164 public Channel::Listener {
165 public: 165 public:
166 Context(Channel::Listener* listener, MessageLoop* ipc_thread); 166 Context(Channel::Listener* listener, MessageLoop* ipc_thread);
(...skipping 27 matching lines...) Expand all
194 // Called on the consumers thread when the ChannelProxy is closed. At that 194 // Called on the consumers thread when the ChannelProxy is closed. At that
195 // point the consumer is telling us that they don't want to receive any 195 // point the consumer is telling us that they don't want to receive any
196 // more messages, so we honor that wish by forgetting them! 196 // more messages, so we honor that wish by forgetting them!
197 virtual void Clear() { listener_ = NULL; } 197 virtual void Clear() { listener_ = NULL; }
198 198
199 private: 199 private:
200 friend class ChannelProxy; 200 friend class ChannelProxy;
201 friend class SendTask; 201 friend class SendTask;
202 202
203 // Create the Channel 203 // Create the Channel
204 void CreateChannel(const std::string& id, const Channel::Mode& mode); 204 void CreateChannel(const IPC::ChannelHandle& channel_handle,
205 const Channel::Mode& mode);
205 206
206 // Methods called on the IO thread. 207 // Methods called on the IO thread.
207 void OnSendMessage(Message* message_ptr); 208 void OnSendMessage(Message* message_ptr);
208 void OnAddFilter(); 209 void OnAddFilter();
209 void OnRemoveFilter(MessageFilter* filter); 210 void OnRemoveFilter(MessageFilter* filter);
210 211
211 // Methods called on the listener thread. 212 // Methods called on the listener thread.
212 void AddFilter(MessageFilter* filter); 213 void AddFilter(MessageFilter* filter);
213 void OnDispatchConnected(); 214 void OnDispatchConnected();
214 void OnDispatchError(); 215 void OnDispatchError();
215 216
216 MessageLoop* listener_message_loop_; 217 MessageLoop* listener_message_loop_;
217 Channel::Listener* listener_; 218 Channel::Listener* listener_;
218 219
219 // List of filters. This is only accessed on the IPC thread. 220 // List of filters. This is only accessed on the IPC thread.
220 std::vector<scoped_refptr<MessageFilter> > filters_; 221 std::vector<scoped_refptr<MessageFilter> > filters_;
221 MessageLoop* ipc_message_loop_; 222 MessageLoop* ipc_message_loop_;
222 Channel* channel_; 223 scoped_ptr<Channel> channel_;
223 std::string channel_id_; 224 std::string channel_id_;
224 int peer_pid_; 225 int peer_pid_;
225 bool channel_connected_called_; 226 bool channel_connected_called_;
226 227
227 // Holds filters between the AddFilter call on the listerner thread and the 228 // Holds filters between the AddFilter call on the listerner thread and the
228 // IPC thread when they're added to filters_. 229 // IPC thread when they're added to filters_.
229 std::vector<scoped_refptr<MessageFilter> > pending_filters_; 230 std::vector<scoped_refptr<MessageFilter> > pending_filters_;
230 // Lock for pending_filters_. 231 // Lock for pending_filters_.
231 Lock pending_filters_lock_; 232 Lock pending_filters_lock_;
232 }; 233 };
233 234
234 Context* context() { return context_; } 235 Context* context() { return context_; }
235 236
236 private: 237 private:
237 friend class SendTask; 238 friend class SendTask;
238 239
239 void Init(const std::string& channel_id, Channel::Mode mode, 240 void Init(const IPC::ChannelHandle& channel_handle, Channel::Mode mode,
240 MessageLoop* ipc_thread_loop, bool create_pipe_now); 241 MessageLoop* ipc_thread_loop, bool create_pipe_now);
241 242
242 // By maintaining this indirection (ref-counted) to our internal state, we 243 // By maintaining this indirection (ref-counted) to our internal state, we
243 // can safely be destroyed while the background thread continues to do stuff 244 // can safely be destroyed while the background thread continues to do stuff
244 // that involves this data. 245 // that involves this data.
245 scoped_refptr<Context> context_; 246 scoped_refptr<Context> context_;
246 }; 247 };
247 248
248 } // namespace IPC 249 } // namespace IPC
249 250
250 #endif // IPC_IPC_CHANNEL_PROXY_H__ 251 #endif // IPC_IPC_CHANNEL_PROXY_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698