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

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

Issue 1833523002: Migrate content/*/p2p/* code to net::IPAddress. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments sergeyu Created 4 years, 9 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
OLDNEW
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 #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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "content/browser/renderer_host/p2p/socket_host.h" 11 #include "content/browser/renderer_host/p2p/socket_host.h"
12 #include "content/common/p2p_messages.h" 12 #include "content/common/p2p_messages.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/resource_context.h" 14 #include "content/public/browser/resource_context.h"
15 #include "net/base/address_list.h" 15 #include "net/base/address_list.h"
16 #include "net/base/completion_callback.h" 16 #include "net/base/completion_callback.h"
17 #include "net/base/ip_address_number.h"
18 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
19 #include "net/base/network_interfaces.h" 18 #include "net/base/network_interfaces.h"
20 #include "net/base/sys_addrinfo.h" 19 #include "net/base/sys_addrinfo.h"
21 #include "net/dns/single_request_host_resolver.h" 20 #include "net/dns/single_request_host_resolver.h"
22 #include "net/log/net_log.h" 21 #include "net/log/net_log.h"
23 #include "net/socket/client_socket_factory.h" 22 #include "net/socket/client_socket_factory.h"
24 #include "net/udp/datagram_client_socket.h" 23 #include "net/udp/datagram_client_socket.h"
25 #include "net/url_request/url_request_context_getter.h" 24 #include "net/url_request/url_request_context_getter.h"
26 25
27 using content::BrowserMessageFilter; 26 using content::BrowserMessageFilter;
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 default_ipv4_local_address_ = GetDefaultLocalAddress(AF_INET); 338 default_ipv4_local_address_ = GetDefaultLocalAddress(AF_INET);
340 default_ipv6_local_address_ = GetDefaultLocalAddress(AF_INET6); 339 default_ipv6_local_address_ = GetDefaultLocalAddress(AF_INET6);
341 BrowserThread::PostTask( 340 BrowserThread::PostTask(
342 BrowserThread::IO, FROM_HERE, 341 BrowserThread::IO, FROM_HERE,
343 base::Bind(&P2PSocketDispatcherHost::SendNetworkList, this, list, 342 base::Bind(&P2PSocketDispatcherHost::SendNetworkList, this, list,
344 default_ipv4_local_address_, default_ipv6_local_address_)); 343 default_ipv4_local_address_, default_ipv6_local_address_));
345 } 344 }
346 345
347 void P2PSocketDispatcherHost::SendNetworkList( 346 void P2PSocketDispatcherHost::SendNetworkList(
348 const net::NetworkInterfaceList& list, 347 const net::NetworkInterfaceList& list,
349 const net::IPAddressNumber& default_ipv4_local_address, 348 const net::IPAddress& default_ipv4_local_address,
350 const net::IPAddressNumber& default_ipv6_local_address) { 349 const net::IPAddress& default_ipv6_local_address) {
351 Send(new P2PMsg_NetworkListChanged(list, default_ipv4_local_address, 350 Send(new P2PMsg_NetworkListChanged(list, default_ipv4_local_address,
352 default_ipv6_local_address)); 351 default_ipv6_local_address));
353 } 352 }
354 353
355 net::IPAddressNumber P2PSocketDispatcherHost::GetDefaultLocalAddress( 354 net::IPAddress P2PSocketDispatcherHost::GetDefaultLocalAddress(int family) {
356 int family) {
357 DCHECK(family == AF_INET || family == AF_INET6); 355 DCHECK(family == AF_INET || family == AF_INET6);
358 356
359 // Creation and connection of a UDP socket might be janky. 357 // Creation and connection of a UDP socket might be janky.
360 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 358 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
361 359
362 scoped_ptr<net::DatagramClientSocket> socket( 360 scoped_ptr<net::DatagramClientSocket> socket(
363 net::ClientSocketFactory::GetDefaultFactory()->CreateDatagramClientSocket( 361 net::ClientSocketFactory::GetDefaultFactory()->CreateDatagramClientSocket(
364 net::DatagramSocket::DEFAULT_BIND, net::RandIntCallback(), NULL, 362 net::DatagramSocket::DEFAULT_BIND, net::RandIntCallback(), NULL,
365 net::NetLog::Source())); 363 net::NetLog::Source()));
366 364
367 net::IPAddressNumber ip_address_number; 365 net::IPAddress ip_address;
368 if (family == AF_INET) { 366 if (family == AF_INET) {
369 ip_address_number.assign(kPublicIPv4Host, 367 ip_address = net::IPAddress(kPublicIPv4Host);
370 kPublicIPv4Host + net::kIPv4AddressSize);
371 } else { 368 } else {
372 ip_address_number.assign(kPublicIPv6Host, 369 ip_address = net::IPAddress(kPublicIPv6Host);
373 kPublicIPv6Host + net::kIPv6AddressSize);
374 } 370 }
375 371
376 if (socket->Connect(net::IPEndPoint(ip_address_number, kPublicPort)) != 372 if (socket->Connect(net::IPEndPoint(ip_address, kPublicPort)) != net::OK) {
377 net::OK) { 373 return net::IPAddress();
378 return net::IPAddressNumber();
379 } 374 }
380 375
381 net::IPEndPoint local_address; 376 net::IPEndPoint local_address;
382 if (socket->GetLocalAddress(&local_address) != net::OK) 377 if (socket->GetLocalAddress(&local_address) != net::OK)
383 return net::IPAddressNumber(); 378 return net::IPAddress();
384 379
385 return local_address.address().bytes(); 380 return local_address.address();
386 } 381 }
387 382
388 void P2PSocketDispatcherHost::OnAddressResolved( 383 void P2PSocketDispatcherHost::OnAddressResolved(
389 DnsRequest* request, 384 DnsRequest* request,
390 const net::IPAddressList& addresses) { 385 const net::IPAddressList& addresses) {
391 Send(new P2PMsg_GetHostAddressResult(request->request_id(), addresses)); 386 Send(new P2PMsg_GetHostAddressResult(request->request_id(), addresses));
392 387
393 dns_requests_.erase(request); 388 dns_requests_.erase(request);
394 delete request; 389 delete request;
395 } 390 }
(...skipping 10 matching lines...) Expand all
406 401
407 if (!dump_incoming_rtp_packet_ && !dump_outgoing_rtp_packet_) 402 if (!dump_incoming_rtp_packet_ && !dump_outgoing_rtp_packet_)
408 packet_callback_.Reset(); 403 packet_callback_.Reset();
409 404
410 for (SocketsMap::iterator it = sockets_.begin(); it != sockets_.end(); ++it) 405 for (SocketsMap::iterator it = sockets_.begin(); it != sockets_.end(); ++it)
411 it->second->StopRtpDump(incoming, outgoing); 406 it->second->StopRtpDump(incoming, outgoing);
412 } 407 }
413 } 408 }
414 409
415 } // namespace content 410 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698