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

Side by Side Diff: ipc/ipc_channel_proxy.h

Issue 159366: Fix memory leak in IPC::ChannelProxy (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months 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 | « no previous file | 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) 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 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/ref_counted.h" 10 #include "base/ref_counted.h"
11 #include "ipc/ipc_channel.h" 11 #include "ipc/ipc_channel.h"
12 12
13 class MessageLoop; 13 class MessageLoop;
14 14
15 namespace IPC { 15 namespace IPC {
16 16
17 class SendTask;
18
17 //----------------------------------------------------------------------------- 19 //-----------------------------------------------------------------------------
18 // IPC::ChannelProxy 20 // IPC::ChannelProxy
19 // 21 //
20 // This class is a helper class that is useful when you wish to run an IPC 22 // This class is a helper class that is useful when you wish to run an IPC
21 // channel on a background thread. It provides you with the option of either 23 // channel on a background thread. It provides you with the option of either
22 // handling IPC messages on that background thread or having them dispatched to 24 // handling IPC messages on that background thread or having them dispatched to
23 // your main thread (the thread on which the IPC::ChannelProxy is created). 25 // your main thread (the thread on which the IPC::ChannelProxy is created).
24 // 26 //
25 // The API for an IPC::ChannelProxy is very similar to that of an IPC::Channel. 27 // The API for an IPC::ChannelProxy is very similar to that of an IPC::Channel.
26 // When you send a message to an IPC::ChannelProxy, the message is routed to 28 // When you send a message to an IPC::ChannelProxy, the message is routed to
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 virtual void OnChannelOpened(); 169 virtual void OnChannelOpened();
168 virtual void OnChannelClosed(); 170 virtual void OnChannelClosed();
169 171
170 // Called on the consumers thread when the ChannelProxy is closed. At that 172 // Called on the consumers thread when the ChannelProxy is closed. At that
171 // point the consumer is telling us that they don't want to receive any 173 // point the consumer is telling us that they don't want to receive any
172 // more messages, so we honor that wish by forgetting them! 174 // more messages, so we honor that wish by forgetting them!
173 virtual void Clear() { listener_ = NULL; } 175 virtual void Clear() { listener_ = NULL; }
174 176
175 private: 177 private:
176 friend class ChannelProxy; 178 friend class ChannelProxy;
179 friend class SendTask;
177 // Create the Channel 180 // Create the Channel
178 void CreateChannel(const std::string& id, const Channel::Mode& mode); 181 void CreateChannel(const std::string& id, const Channel::Mode& mode);
179 182
180 // Methods called via InvokeLater: 183 // Methods called via InvokeLater:
181 void OnSendMessage(Message* message_ptr); 184 void OnSendMessage(Message* message_ptr);
182 void OnAddFilter(MessageFilter* filter); 185 void OnAddFilter(MessageFilter* filter);
183 void OnRemoveFilter(MessageFilter* filter); 186 void OnRemoveFilter(MessageFilter* filter);
184 void OnDispatchConnected(); 187 void OnDispatchConnected();
185 void OnDispatchError(); 188 void OnDispatchError();
186 189
187 MessageLoop* listener_message_loop_; 190 MessageLoop* listener_message_loop_;
188 Channel::Listener* listener_; 191 Channel::Listener* listener_;
189 192
190 // List of filters. This is only accessed on the IPC thread. 193 // List of filters. This is only accessed on the IPC thread.
191 std::vector<scoped_refptr<MessageFilter> > filters_; 194 std::vector<scoped_refptr<MessageFilter> > filters_;
192 MessageLoop* ipc_message_loop_; 195 MessageLoop* ipc_message_loop_;
193 Channel* channel_; 196 Channel* channel_;
194 std::string channel_id_; 197 std::string channel_id_;
195 int peer_pid_; 198 int peer_pid_;
196 bool channel_connected_called_; 199 bool channel_connected_called_;
197 }; 200 };
198 201
199 Context* context() { return context_; } 202 Context* context() { return context_; }
200 203
201 private: 204 private:
205 friend class SendTask;
206
202 void Init(const std::string& channel_id, Channel::Mode mode, 207 void Init(const std::string& channel_id, Channel::Mode mode,
203 MessageLoop* ipc_thread_loop, bool create_pipe_now); 208 MessageLoop* ipc_thread_loop, bool create_pipe_now);
204 209
205 // By maintaining this indirection (ref-counted) to our internal state, we 210 // By maintaining this indirection (ref-counted) to our internal state, we
206 // can safely be destroyed while the background thread continues to do stuff 211 // can safely be destroyed while the background thread continues to do stuff
207 // that involves this data. 212 // that involves this data.
208 scoped_refptr<Context> context_; 213 scoped_refptr<Context> context_;
209 }; 214 };
210 215
211 } // namespace IPC 216 } // namespace IPC
212 217
213 #endif // IPC_IPC_CHANNEL_PROXY_H__ 218 #endif // IPC_IPC_CHANNEL_PROXY_H__
OLDNEW
« no previous file with comments | « no previous file | ipc/ipc_channel_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698