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

Side by Side Diff: content/browser/renderer_host/p2p/socket_dispatcher_host.cc

Issue 10068037: RefCounted types should not have public destructors, content/browser part 1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: MSVC fixes Created 8 years, 8 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
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 #include "content/browser/renderer_host/p2p/socket_dispatcher_host.h" 5 #include "content/browser/renderer_host/p2p/socket_dispatcher_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "content/browser/renderer_host/p2p/socket_host.h" 9 #include "content/browser/renderer_host/p2p/socket_host.h"
10 #include "content/public/browser/resource_context.h" 10 #include "content/public/browser/resource_context.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 99
100 DoneCallback done_callback_; 100 DoneCallback done_callback_;
101 }; 101 };
102 102
103 P2PSocketDispatcherHost::P2PSocketDispatcherHost( 103 P2PSocketDispatcherHost::P2PSocketDispatcherHost(
104 content::ResourceContext* resource_context) 104 content::ResourceContext* resource_context)
105 : resource_context_(resource_context), 105 : resource_context_(resource_context),
106 monitoring_networks_(false) { 106 monitoring_networks_(false) {
107 } 107 }
108 108
109 P2PSocketDispatcherHost::~P2PSocketDispatcherHost() {
110 DCHECK(sockets_.empty());
111 DCHECK(dns_requests_.empty());
112
113 if (monitoring_networks_)
114 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
115 }
116
117 void P2PSocketDispatcherHost::OnChannelClosing() { 109 void P2PSocketDispatcherHost::OnChannelClosing() {
118 BrowserMessageFilter::OnChannelClosing(); 110 BrowserMessageFilter::OnChannelClosing();
119 111
120 // Since the IPC channel is gone, close pending connections. 112 // Since the IPC channel is gone, close pending connections.
121 STLDeleteContainerPairSecondPointers(sockets_.begin(), sockets_.end()); 113 STLDeleteContainerPairSecondPointers(sockets_.begin(), sockets_.end());
122 sockets_.clear(); 114 sockets_.clear();
123 115
124 STLDeleteContainerPointers(dns_requests_.begin(), dns_requests_.end()); 116 STLDeleteContainerPointers(dns_requests_.begin(), dns_requests_.end());
125 dns_requests_.clear(); 117 dns_requests_.clear();
126 } 118 }
(...skipping 14 matching lines...) Expand all
141 IPC_MESSAGE_HANDLER(P2PHostMsg_CreateSocket, OnCreateSocket) 133 IPC_MESSAGE_HANDLER(P2PHostMsg_CreateSocket, OnCreateSocket)
142 IPC_MESSAGE_HANDLER(P2PHostMsg_AcceptIncomingTcpConnection, 134 IPC_MESSAGE_HANDLER(P2PHostMsg_AcceptIncomingTcpConnection,
143 OnAcceptIncomingTcpConnection) 135 OnAcceptIncomingTcpConnection)
144 IPC_MESSAGE_HANDLER(P2PHostMsg_Send, OnSend) 136 IPC_MESSAGE_HANDLER(P2PHostMsg_Send, OnSend)
145 IPC_MESSAGE_HANDLER(P2PHostMsg_DestroySocket, OnDestroySocket) 137 IPC_MESSAGE_HANDLER(P2PHostMsg_DestroySocket, OnDestroySocket)
146 IPC_MESSAGE_UNHANDLED(handled = false) 138 IPC_MESSAGE_UNHANDLED(handled = false)
147 IPC_END_MESSAGE_MAP_EX() 139 IPC_END_MESSAGE_MAP_EX()
148 return handled; 140 return handled;
149 } 141 }
150 142
143 void P2PSocketDispatcherHost::OnIPAddressChanged() {
144 // Notify the renderer about changes to list of network interfaces.
145 BrowserThread::PostTask(
146 BrowserThread::FILE, FROM_HERE, base::Bind(
147 &P2PSocketDispatcherHost::DoGetNetworkList, this));
148 }
149
150 P2PSocketDispatcherHost::~P2PSocketDispatcherHost() {
151 DCHECK(sockets_.empty());
152 DCHECK(dns_requests_.empty());
153
154 if (monitoring_networks_)
155 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
156 }
157
151 P2PSocketHost* P2PSocketDispatcherHost::LookupSocket( 158 P2PSocketHost* P2PSocketDispatcherHost::LookupSocket(
152 int32 routing_id, int socket_id) { 159 int32 routing_id, int socket_id) {
153 SocketsMap::iterator it = sockets_.find( 160 SocketsMap::iterator it = sockets_.find(
154 ExtendedSocketId(routing_id, socket_id)); 161 ExtendedSocketId(routing_id, socket_id));
155 if (it == sockets_.end()) 162 if (it == sockets_.end())
156 return NULL; 163 return NULL;
157 else 164 else
158 return it->second; 165 return it->second;
159 } 166 }
160 167
161 void P2PSocketDispatcherHost::OnStartNetworkNotifications( 168 void P2PSocketDispatcherHost::OnStartNetworkNotifications(
162 const IPC::Message& msg) { 169 const IPC::Message& msg) {
163 if (!monitoring_networks_) { 170 if (!monitoring_networks_) {
164 net::NetworkChangeNotifier::AddIPAddressObserver(this); 171 net::NetworkChangeNotifier::AddIPAddressObserver(this);
165 monitoring_networks_ = true; 172 monitoring_networks_ = true;
166 } 173 }
167 174
168 notifications_routing_ids_.insert(msg.routing_id()); 175 notifications_routing_ids_.insert(msg.routing_id());
169 176
170 BrowserThread::PostTask( 177 BrowserThread::PostTask(
171 BrowserThread::FILE, FROM_HERE, base::Bind( 178 BrowserThread::FILE, FROM_HERE, base::Bind(
172 &P2PSocketDispatcherHost::DoGetNetworkList, this)); 179 &P2PSocketDispatcherHost::DoGetNetworkList, this));
173 } 180 }
174 181
175 void P2PSocketDispatcherHost::OnStopNetworkNotifications( 182 void P2PSocketDispatcherHost::OnStopNetworkNotifications(
176 const IPC::Message& msg) { 183 const IPC::Message& msg) {
177 notifications_routing_ids_.erase(msg.routing_id()); 184 notifications_routing_ids_.erase(msg.routing_id());
178 } 185 }
179 186
180 void P2PSocketDispatcherHost::OnIPAddressChanged() {
181 // Notify the renderer about changes to list of network interfaces.
182 BrowserThread::PostTask(
183 BrowserThread::FILE, FROM_HERE, base::Bind(
184 &P2PSocketDispatcherHost::DoGetNetworkList, this));
185 }
186
187 void P2PSocketDispatcherHost::DoGetNetworkList() {
188 net::NetworkInterfaceList list;
189 net::GetNetworkList(&list);
190 BrowserThread::PostTask(
191 BrowserThread::IO, FROM_HERE, base::Bind(
192 &P2PSocketDispatcherHost::SendNetworkList, this, list));
193 }
194
195 void P2PSocketDispatcherHost::SendNetworkList(
196 const net::NetworkInterfaceList& list) {
197 for (std::set<int>::iterator it = notifications_routing_ids_.begin();
198 it != notifications_routing_ids_.end(); ++it) {
199 Send(new P2PMsg_NetworkListChanged(*it, list));
200 }
201 }
202
203 void P2PSocketDispatcherHost::OnGetHostAddress(const IPC::Message& msg, 187 void P2PSocketDispatcherHost::OnGetHostAddress(const IPC::Message& msg,
204 const std::string& host_name, 188 const std::string& host_name,
205 int32 request_id) { 189 int32 request_id) {
206 DnsRequest* request = new DnsRequest( 190 DnsRequest* request = new DnsRequest(
207 msg.routing_id(), request_id, resource_context_->GetHostResolver()); 191 msg.routing_id(), request_id, resource_context_->GetHostResolver());
208 dns_requests_.insert(request); 192 dns_requests_.insert(request);
209 request->Resolve(host_name, base::Bind( 193 request->Resolve(host_name, base::Bind(
210 &P2PSocketDispatcherHost::OnAddressResolved, 194 &P2PSocketDispatcherHost::OnAddressResolved,
211 base::Unretained(this), request)); 195 base::Unretained(this), request));
212 } 196 }
213 197
214 void P2PSocketDispatcherHost::OnAddressResolved(
215 DnsRequest* request,
216 const net::IPAddressNumber& result) {
217 Send(new P2PMsg_GetHostAddressResult(
218 request->routing_id(), request->request_id(), result));
219
220 dns_requests_.erase(request);
221 delete request;
222 }
223
224 void P2PSocketDispatcherHost::OnCreateSocket( 198 void P2PSocketDispatcherHost::OnCreateSocket(
225 const IPC::Message& msg, P2PSocketType type, int socket_id, 199 const IPC::Message& msg, P2PSocketType type, int socket_id,
226 const net::IPEndPoint& local_address, 200 const net::IPEndPoint& local_address,
227 const net::IPEndPoint& remote_address) { 201 const net::IPEndPoint& remote_address) {
228 if (LookupSocket(msg.routing_id(), socket_id)) { 202 if (LookupSocket(msg.routing_id(), socket_id)) {
229 LOG(ERROR) << "Received P2PHostMsg_CreateSocket for socket " 203 LOG(ERROR) << "Received P2PHostMsg_CreateSocket for socket "
230 "that already exists."; 204 "that already exists.";
231 return; 205 return;
232 } 206 }
233 207
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 SocketsMap::iterator it = sockets_.find( 253 SocketsMap::iterator it = sockets_.find(
280 ExtendedSocketId(msg.routing_id(), socket_id)); 254 ExtendedSocketId(msg.routing_id(), socket_id));
281 if (it != sockets_.end()) { 255 if (it != sockets_.end()) {
282 delete it->second; 256 delete it->second;
283 sockets_.erase(it); 257 sockets_.erase(it);
284 } else { 258 } else {
285 LOG(ERROR) << "Received P2PHostMsg_DestroySocket for invalid socket_id."; 259 LOG(ERROR) << "Received P2PHostMsg_DestroySocket for invalid socket_id.";
286 } 260 }
287 } 261 }
288 262
263 void P2PSocketDispatcherHost::DoGetNetworkList() {
264 net::NetworkInterfaceList list;
265 net::GetNetworkList(&list);
266 BrowserThread::PostTask(
267 BrowserThread::IO, FROM_HERE, base::Bind(
268 &P2PSocketDispatcherHost::SendNetworkList, this, list));
269 }
270
271 void P2PSocketDispatcherHost::SendNetworkList(
272 const net::NetworkInterfaceList& list) {
273 for (std::set<int>::iterator it = notifications_routing_ids_.begin();
274 it != notifications_routing_ids_.end(); ++it) {
275 Send(new P2PMsg_NetworkListChanged(*it, list));
276 }
277 }
278
279 void P2PSocketDispatcherHost::OnAddressResolved(
280 DnsRequest* request,
281 const net::IPAddressNumber& result) {
282 Send(new P2PMsg_GetHostAddressResult(
283 request->routing_id(), request->request_id(), result));
284
285 dns_requests_.erase(request);
286 delete request;
287 }
288
289 } // namespace content 289 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/p2p/socket_dispatcher_host.h ('k') | content/browser/renderer_host/pepper_file_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698