| 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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 new net::UDPClientSocket(net::DatagramSocket::DEFAULT_BIND, | 501 new net::UDPClientSocket(net::DatagramSocket::DEFAULT_BIND, |
| 503 net::RandIntCallback(), | 502 net::RandIntCallback(), |
| 504 NULL, | 503 NULL, |
| 505 net::NetLog::Source()); | 504 net::NetLog::Source()); |
| 506 if (!udp_socket) { | 505 if (!udp_socket) { |
| 507 Finish(SOCKET_CREATE_FAILED, net::ERR_INVALID_ARGUMENT); | 506 Finish(SOCKET_CREATE_FAILED, net::ERR_INVALID_ARGUMENT); |
| 508 return false; | 507 return false; |
| 509 } | 508 } |
| 510 set_socket(udp_socket); | 509 set_socket(udp_socket); |
| 511 | 510 |
| 512 const addrinfo* address = GetAddressList().head(); | 511 if (GetAddressList().empty()) { |
| 513 if (!address) { | |
| 514 Finish(RESOLVE_FAILED, net::ERR_INVALID_ARGUMENT); | 512 Finish(RESOLVE_FAILED, net::ERR_INVALID_ARGUMENT); |
| 515 return false; | 513 return false; |
| 516 } | 514 } |
| 517 | 515 |
| 518 net::IPEndPoint endpoint; | 516 const net::IPEndPoint& endpoint = GetAddressList().front(); |
| 519 endpoint.FromSockAddr(address->ai_addr, address->ai_addrlen); | |
| 520 int rv = udp_socket->Connect(endpoint); | 517 int rv = udp_socket->Connect(endpoint); |
| 521 if (rv < 0) { | 518 if (rv < 0) { |
| 522 Finish(CONNECT_FAILED, rv); | 519 Finish(CONNECT_FAILED, rv); |
| 523 return false; | 520 return false; |
| 524 } | 521 } |
| 525 return NetworkStats::ConnectComplete(rv); | 522 return NetworkStats::ConnectComplete(rv); |
| 526 } | 523 } |
| 527 | 524 |
| 528 bool UDPStatsClient::ReadComplete(int result) { | 525 bool UDPStatsClient::ReadComplete(int result) { |
| 529 DCHECK_NE(net::ERR_IO_PENDING, result); | 526 DCHECK_NE(net::ERR_IO_PENDING, result); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 host_resolver, tcp_server_address, histogram_port, | 705 host_resolver, tcp_server_address, histogram_port, |
| 709 kSmallTestBytesToSend, net::CompletionCallback()); | 706 kSmallTestBytesToSend, net::CompletionCallback()); |
| 710 | 707 |
| 711 TCPStatsClient* large_tcp_client = new TCPStatsClient(); | 708 TCPStatsClient* large_tcp_client = new TCPStatsClient(); |
| 712 large_tcp_client->Start( | 709 large_tcp_client->Start( |
| 713 host_resolver, tcp_server_address, histogram_port, | 710 host_resolver, tcp_server_address, histogram_port, |
| 714 kLargeTestBytesToSend, net::CompletionCallback()); | 711 kLargeTestBytesToSend, net::CompletionCallback()); |
| 715 } | 712 } |
| 716 | 713 |
| 717 } // namespace chrome_browser_net | 714 } // namespace chrome_browser_net |
| OLD | NEW |