| OLD | NEW |
| 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 "chrome/browser/net/network_stats.h" | 5 #include "chrome/browser/net/network_stats.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 #include "base/tuple.h" | 16 #include "base/tuple.h" |
| 17 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 20 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
| 21 #include "net/base/network_change_notifier.h" | 21 #include "net/base/network_change_notifier.h" |
| 22 #include "net/base/sys_addrinfo.h" | |
| 23 #include "net/base/test_completion_callback.h" | 22 #include "net/base/test_completion_callback.h" |
| 24 #include "net/socket/tcp_client_socket.h" | 23 #include "net/socket/tcp_client_socket.h" |
| 25 #include "net/udp/udp_client_socket.h" | 24 #include "net/udp/udp_client_socket.h" |
| 26 #include "net/udp/udp_server_socket.h" | 25 #include "net/udp/udp_server_socket.h" |
| 27 | 26 |
| 28 using content::BrowserThread; | 27 using content::BrowserThread; |
| 29 | 28 |
| 30 namespace chrome_browser_net { | 29 namespace chrome_browser_net { |
| 31 | 30 |
| 32 // This specifies the number of bytes to be sent to the TCP/UDP servers as part | 31 // This specifies the number of bytes to be sent to the TCP/UDP servers as part |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 new net::UDPClientSocket(net::DatagramSocket::DEFAULT_BIND, | 614 new net::UDPClientSocket(net::DatagramSocket::DEFAULT_BIND, |
| 616 net::RandIntCallback(), | 615 net::RandIntCallback(), |
| 617 NULL, | 616 NULL, |
| 618 net::NetLog::Source()); | 617 net::NetLog::Source()); |
| 619 if (!udp_socket) { | 618 if (!udp_socket) { |
| 620 Finish(SOCKET_CREATE_FAILED, net::ERR_INVALID_ARGUMENT); | 619 Finish(SOCKET_CREATE_FAILED, net::ERR_INVALID_ARGUMENT); |
| 621 return false; | 620 return false; |
| 622 } | 621 } |
| 623 set_socket(udp_socket); | 622 set_socket(udp_socket); |
| 624 | 623 |
| 625 const addrinfo* address = GetAddressList().head(); | 624 if (addresses().empty()) { |
| 626 if (!address) { | |
| 627 Finish(RESOLVE_FAILED, net::ERR_INVALID_ARGUMENT); | 625 Finish(RESOLVE_FAILED, net::ERR_INVALID_ARGUMENT); |
| 628 return false; | 626 return false; |
| 629 } | 627 } |
| 630 | 628 |
| 631 net::IPEndPoint endpoint; | 629 const net::IPEndPoint& endpoint = addresses().front(); |
| 632 endpoint.FromSockAddr(address->ai_addr, address->ai_addrlen); | |
| 633 int rv = udp_socket->Connect(endpoint); | 630 int rv = udp_socket->Connect(endpoint); |
| 634 if (rv < 0) { | 631 if (rv < 0) { |
| 635 Finish(CONNECT_FAILED, rv); | 632 Finish(CONNECT_FAILED, rv); |
| 636 return false; | 633 return false; |
| 637 } | 634 } |
| 638 return NetworkStats::ConnectComplete(rv); | 635 return NetworkStats::ConnectComplete(rv); |
| 639 } | 636 } |
| 640 | 637 |
| 641 bool UDPStatsClient::ReadComplete(int result) { | 638 bool UDPStatsClient::ReadComplete(int result) { |
| 642 DCHECK_NE(net::ERR_IO_PENDING, result); | 639 DCHECK_NE(net::ERR_IO_PENDING, result); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 668 TCPStatsClient::~TCPStatsClient() { | 665 TCPStatsClient::~TCPStatsClient() { |
| 669 } | 666 } |
| 670 | 667 |
| 671 bool TCPStatsClient::DoConnect(int result) { | 668 bool TCPStatsClient::DoConnect(int result) { |
| 672 if (result != net::OK) { | 669 if (result != net::OK) { |
| 673 Finish(RESOLVE_FAILED, result); | 670 Finish(RESOLVE_FAILED, result); |
| 674 return false; | 671 return false; |
| 675 } | 672 } |
| 676 | 673 |
| 677 net::TCPClientSocket* tcp_socket = | 674 net::TCPClientSocket* tcp_socket = |
| 678 new net::TCPClientSocket(GetAddressList(), NULL, net::NetLog::Source()); | 675 new net::TCPClientSocket(addresses(), NULL, net::NetLog::Source()); |
| 679 if (!tcp_socket) { | 676 if (!tcp_socket) { |
| 680 Finish(SOCKET_CREATE_FAILED, net::ERR_INVALID_ARGUMENT); | 677 Finish(SOCKET_CREATE_FAILED, net::ERR_INVALID_ARGUMENT); |
| 681 return false; | 678 return false; |
| 682 } | 679 } |
| 683 set_socket(tcp_socket); | 680 set_socket(tcp_socket); |
| 684 | 681 |
| 685 int rv = tcp_socket->Connect(base::Bind(&TCPStatsClient::OnConnectComplete, | 682 int rv = tcp_socket->Connect(base::Bind(&TCPStatsClient::OnConnectComplete, |
| 686 base::Unretained(this))); | 683 base::Unretained(this))); |
| 687 if (rv == net::ERR_IO_PENDING) | 684 if (rv == net::ERR_IO_PENDING) |
| 688 return true; | 685 return true; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 UDPStatsClient* packet_loss_udp_stats = new UDPStatsClient(); | 842 UDPStatsClient* packet_loss_udp_stats = new UDPStatsClient(); |
| 846 packet_loss_udp_stats->Start( | 843 packet_loss_udp_stats->Start( |
| 847 host_resolver, server_address, histogram_port, | 844 host_resolver, server_address, histogram_port, |
| 848 kLargeTestBytesToSend, kMaximumPackets, net::CompletionCallback()); | 845 kLargeTestBytesToSend, kMaximumPackets, net::CompletionCallback()); |
| 849 } | 846 } |
| 850 break; | 847 break; |
| 851 } | 848 } |
| 852 } | 849 } |
| 853 | 850 |
| 854 } // namespace chrome_browser_net | 851 } // namespace chrome_browser_net |
| OLD | NEW |