Chromium Code Reviews| 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 "googleurl/src/gurl.h" | |
| 19 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 20 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
| 21 #include "net/base/network_change_notifier.h" | 22 #include "net/base/network_change_notifier.h" |
| 22 #include "net/base/sys_addrinfo.h" | 23 #include "net/base/sys_addrinfo.h" |
| 23 #include "net/base/test_completion_callback.h" | 24 #include "net/base/test_completion_callback.h" |
| 25 #include "net/proxy/proxy_service.h" | |
| 24 #include "net/socket/tcp_client_socket.h" | 26 #include "net/socket/tcp_client_socket.h" |
| 25 #include "net/udp/udp_client_socket.h" | 27 #include "net/udp/udp_client_socket.h" |
| 26 #include "net/udp/udp_server_socket.h" | 28 #include "net/udp/udp_server_socket.h" |
| 27 | 29 |
| 28 using content::BrowserThread; | 30 using content::BrowserThread; |
| 29 | 31 |
| 30 namespace chrome_browser_net { | 32 namespace chrome_browser_net { |
| 31 | 33 |
| 32 // This specifies the number of bytes to be sent to the TCP/UDP servers as part | 34 // This specifies the number of bytes to be sent to the TCP/UDP servers as part |
| 33 // of small packet size test. | 35 // of small packet size test. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 | 89 |
| 88 // Maximum number of packets that can be sent to the server for packet loss | 90 // Maximum number of packets that can be sent to the server for packet loss |
| 89 // testing. | 91 // testing. |
| 90 static const uint32 kMaximumPackets = 4; | 92 static const uint32 kMaximumPackets = 4; |
| 91 | 93 |
| 92 // NetworkStats methods and members. | 94 // NetworkStats methods and members. |
| 93 NetworkStats::NetworkStats() | 95 NetworkStats::NetworkStats() |
| 94 : load_size_(0), | 96 : load_size_(0), |
| 95 bytes_to_read_(0), | 97 bytes_to_read_(0), |
| 96 bytes_to_send_(0), | 98 bytes_to_send_(0), |
| 99 has_proxy_server_(false), | |
| 97 packets_to_send_(0), | 100 packets_to_send_(0), |
| 98 packets_sent_(0), | 101 packets_sent_(0), |
| 99 base_packet_number_(0), | 102 base_packet_number_(0), |
| 100 packets_received_mask_(0), | 103 packets_received_mask_(0), |
| 101 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 104 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 102 } | 105 } |
| 103 | 106 |
| 104 NetworkStats::~NetworkStats() { | 107 NetworkStats::~NetworkStats() { |
| 105 socket_.reset(); | 108 socket_.reset(); |
| 106 } | 109 } |
| 107 | 110 |
| 108 bool NetworkStats::Start(net::HostResolver* host_resolver, | 111 bool NetworkStats::Start(net::HostResolver* host_resolver, |
| 109 const net::HostPortPair& server_host_port_pair, | 112 const net::HostPortPair& server_host_port_pair, |
| 110 HistogramPortSelector histogram_port, | 113 HistogramPortSelector histogram_port, |
| 114 bool has_proxy_server, | |
| 111 uint32 bytes_to_send, | 115 uint32 bytes_to_send, |
| 112 uint32 packets_to_send, | 116 uint32 packets_to_send, |
| 113 const net::CompletionCallback& finished_callback) { | 117 const net::CompletionCallback& finished_callback) { |
| 118 DCHECK(host_resolver); | |
| 114 DCHECK(bytes_to_send); // We should have data to send. | 119 DCHECK(bytes_to_send); // We should have data to send. |
| 115 DCHECK_LE(packets_to_send, kMaximumPackets); | 120 DCHECK_LE(packets_to_send, kMaximumPackets); |
| 116 | 121 |
| 117 Initialize(bytes_to_send, histogram_port, packets_to_send, finished_callback); | 122 Initialize(bytes_to_send, |
| 123 histogram_port, | |
| 124 has_proxy_server, | |
| 125 packets_to_send, | |
| 126 finished_callback); | |
| 118 | 127 |
| 119 net::HostResolver::RequestInfo request(server_host_port_pair); | 128 net::HostResolver::RequestInfo request(server_host_port_pair); |
| 120 int rv = host_resolver->Resolve( | 129 int rv = host_resolver->Resolve( |
| 121 request, &addresses_, | 130 request, &addresses_, |
| 122 base::Bind(&NetworkStats::OnResolveComplete, | 131 base::Bind(&NetworkStats::OnResolveComplete, |
| 123 base::Unretained(this)), | 132 base::Unretained(this)), |
| 124 NULL, net::BoundNetLog()); | 133 NULL, net::BoundNetLog()); |
| 125 if (rv == net::ERR_IO_PENDING) | 134 if (rv == net::ERR_IO_PENDING) |
| 126 return true; | 135 return true; |
| 127 return DoConnect(rv); | 136 return DoConnect(rv); |
| 128 } | 137 } |
| 129 | 138 |
| 130 void NetworkStats::Initialize( | 139 void NetworkStats::Initialize( |
| 131 uint32 bytes_to_send, | 140 uint32 bytes_to_send, |
| 132 HistogramPortSelector histogram_port, | 141 HistogramPortSelector histogram_port, |
| 142 bool has_proxy_server, | |
| 133 uint32 packets_to_send, | 143 uint32 packets_to_send, |
| 134 const net::CompletionCallback& finished_callback) { | 144 const net::CompletionCallback& finished_callback) { |
| 135 DCHECK(bytes_to_send); // We should have data to send. | 145 DCHECK(bytes_to_send); // We should have data to send. |
| 136 DCHECK(packets_to_send); // We should send at least 1 packet. | 146 DCHECK(packets_to_send); // We should send at least 1 packet. |
| 137 DCHECK_LE(bytes_to_send, kLargeTestBytesToSend); | 147 DCHECK_LE(bytes_to_send, kLargeTestBytesToSend); |
| 138 | 148 |
| 139 load_size_ = bytes_to_send; | 149 load_size_ = bytes_to_send; |
| 140 packets_to_send_ = packets_to_send; | 150 packets_to_send_ = packets_to_send; |
| 141 | 151 |
| 142 histogram_port_ = histogram_port; | 152 histogram_port_ = histogram_port; |
| 153 has_proxy_server_ = has_proxy_server; | |
| 143 finished_callback_ = finished_callback; | 154 finished_callback_ = finished_callback; |
| 144 } | 155 } |
| 145 | 156 |
| 146 uint32 SendingPacketSize(uint32 load_size) { | 157 uint32 SendingPacketSize(uint32 load_size) { |
| 147 return kVersionLength + kChecksumLength + kPayloadSizeLength + load_size; | 158 return kVersionLength + kChecksumLength + kPayloadSizeLength + load_size; |
| 148 } | 159 } |
| 149 | 160 |
| 150 uint32 ReceivingPacketSize(uint32 load_size) { | 161 uint32 ReceivingPacketSize(uint32 load_size) { |
| 151 return kVersionLength + kChecksumLength + kPayloadSizeLength + kKeyLength + | 162 return kVersionLength + kChecksumLength + kPayloadSizeLength + kKeyLength + |
| 152 load_size; | 163 load_size; |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 531 if (result == net::OK) { | 542 if (result == net::OK) { |
| 532 *rtt_histogram_name = base::StringPrintf( | 543 *rtt_histogram_name = base::StringPrintf( |
| 533 "NetConnectivity.%s.Success.%d.%s.RTT", | 544 "NetConnectivity.%s.Success.%d.%s.RTT", |
| 534 protocol_string, | 545 protocol_string, |
| 535 kPorts[port], | 546 kPorts[port], |
| 536 load_size_string); | 547 load_size_string); |
| 537 } | 548 } |
| 538 | 549 |
| 539 // Build "NetConnectivity.<protocol>.Status.<port>.<load_size>" histogram | 550 // Build "NetConnectivity.<protocol>.Status.<port>.<load_size>" histogram |
| 540 // name. Total number of histograms are 2*5*2. | 551 // name. Total number of histograms are 2*5*2. |
| 541 *status_histogram_name = base::StringPrintf( | 552 *status_histogram_name = base::StringPrintf( |
| 542 "NetConnectivity.%s.Status.%d.%s", | 553 "NetConnectivity.%s.Status.%d.%s", |
| 543 protocol_string, | 554 protocol_string, |
| 544 kPorts[port], | 555 kPorts[port], |
| 545 load_size_string); | 556 load_size_string); |
| 546 | 557 |
| 547 // Build "NetConnectivity.<protocol>.PacketLoss.<port>.<load_size>" histogram | 558 // Build "NetConnectivity.<protocol>.PacketLoss.<port>.<load_size>" histogram |
| 548 // name. Total number of histograms are 5 (because we do this test for UDP | 559 // name. Total number of histograms are 5 (because we do this test for UDP |
| 549 // only). | 560 // only). |
| 550 *packet_loss_histogram_name = base::StringPrintf( | 561 *packet_loss_histogram_name = base::StringPrintf( |
| 551 "NetConnectivity.%s.PacketLoss.%d.%s", | 562 "NetConnectivity.%s.PacketLoss.%d.%s", |
| 552 protocol_string, | 563 protocol_string, |
| 553 kPorts[port], | 564 kPorts[port], |
| 554 load_size_string); | 565 load_size_string); |
| 555 } | 566 } |
| 556 | 567 |
| 557 void NetworkStats::RecordHistograms(const ProtocolValue& protocol, | 568 void NetworkStats::RecordHistograms(const ProtocolValue& protocol, |
| 558 const Status& status, | 569 const Status& status, |
| 559 int result) { | 570 int result) { |
| 560 base::TimeDelta duration = base::TimeTicks::Now() - start_time(); | 571 base::TimeDelta duration = base::TimeTicks::Now() - start_time(); |
| 561 | 572 |
| 562 std::string rtt_histogram_name; | 573 std::string rtt_histogram_name; |
| 563 std::string status_histogram_name; | 574 std::string status_histogram_name; |
| 564 std::string packet_loss_histogram_name; | 575 std::string packet_loss_histogram_name; |
| 565 GetHistogramNames(protocol, | 576 GetHistogramNames(protocol, |
| 566 histogram_port_, | 577 histogram_port_, |
| 567 load_size_, | 578 load_size_, |
| 568 result, | 579 result, |
| 569 &rtt_histogram_name, | 580 &rtt_histogram_name, |
| 570 &status_histogram_name, | 581 &status_histogram_name, |
| 571 &packet_loss_histogram_name); | 582 &packet_loss_histogram_name); |
| 572 | 583 |
| 573 // For packet loss test, just record packet loss data. | 584 size_t histogram_count = has_proxy_server_ ? 1 : 2; |
| 574 if (packets_to_send_ > 1) { | 585 for (size_t i = 0; i < histogram_count; i++) { |
| 575 base::Histogram* packet_loss_histogram = base::LinearHistogram::FactoryGet( | 586 // For packet loss test, just record packet loss data. |
| 576 packet_loss_histogram_name, | 587 if (packets_to_send_ > 1) { |
| 577 1, | 588 base::Histogram* histogram = base::LinearHistogram::FactoryGet( |
| 578 2 << kMaximumPackets, | 589 packet_loss_histogram_name, |
| 579 (2 << kMaximumPackets) + 1, | 590 1, |
| 591 2 << kMaximumPackets, | |
| 592 (2 << kMaximumPackets) + 1, | |
| 593 base::Histogram::kUmaTargetedHistogramFlag); | |
| 594 histogram->Add(packets_received_mask_); | |
| 595 packet_loss_histogram_name.append(".NoProxy"); | |
| 596 continue; | |
| 597 } | |
| 598 | |
| 599 if (result == net::OK) { | |
| 600 base::Histogram* rtt_histogram = base::Histogram::FactoryTimeGet( | |
| 601 rtt_histogram_name, | |
| 602 base::TimeDelta::FromMilliseconds(10), | |
| 603 base::TimeDelta::FromSeconds(60), 50, | |
| 604 base::Histogram::kUmaTargetedHistogramFlag); | |
| 605 rtt_histogram->AddTime(duration); | |
| 606 rtt_histogram_name.append(".NoProxy"); | |
| 607 } | |
| 608 | |
| 609 base::Histogram* status_histogram = base::LinearHistogram::FactoryGet( | |
| 610 status_histogram_name, 1, STATUS_MAX, STATUS_MAX+1, | |
| 580 base::Histogram::kUmaTargetedHistogramFlag); | 611 base::Histogram::kUmaTargetedHistogramFlag); |
| 581 packet_loss_histogram->Add(packets_received_mask_); | 612 status_histogram->Add(status); |
| 582 return; | 613 status_histogram_name.append(".NoProxy"); |
| 583 } | 614 } |
| 584 | |
| 585 if (result == net::OK) { | |
| 586 base::Histogram* rtt_histogram = base::Histogram::FactoryTimeGet( | |
| 587 rtt_histogram_name, | |
| 588 base::TimeDelta::FromMilliseconds(10), | |
| 589 base::TimeDelta::FromSeconds(60), 50, | |
| 590 base::Histogram::kUmaTargetedHistogramFlag); | |
| 591 rtt_histogram->AddTime(duration); | |
| 592 } | |
| 593 | |
| 594 base::Histogram* status_histogram = base::LinearHistogram::FactoryGet( | |
| 595 status_histogram_name, 1, STATUS_MAX, STATUS_MAX+1, | |
| 596 base::Histogram::kUmaTargetedHistogramFlag); | |
| 597 status_histogram->Add(status); | |
| 598 } | 615 } |
| 599 | 616 |
| 600 // UDPStatsClient methods and members. | 617 // UDPStatsClient methods and members. |
| 601 UDPStatsClient::UDPStatsClient() | 618 UDPStatsClient::UDPStatsClient() |
| 602 : NetworkStats() { | 619 : NetworkStats() { |
| 603 } | 620 } |
| 604 | 621 |
| 605 UDPStatsClient::~UDPStatsClient() { | 622 UDPStatsClient::~UDPStatsClient() { |
| 606 } | 623 } |
| 607 | 624 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 710 | 727 |
| 711 // Disconnect the socket so that there are no more IO operations. | 728 // Disconnect the socket so that there are no more IO operations. |
| 712 net::TCPClientSocket* tcp_socket = | 729 net::TCPClientSocket* tcp_socket = |
| 713 static_cast<net::TCPClientSocket*>(socket()); | 730 static_cast<net::TCPClientSocket*>(socket()); |
| 714 if (tcp_socket) | 731 if (tcp_socket) |
| 715 tcp_socket->Disconnect(); | 732 tcp_socket->Disconnect(); |
| 716 | 733 |
| 717 delete this; | 734 delete this; |
| 718 } | 735 } |
| 719 | 736 |
| 737 // ProxyDetector methods and members. | |
| 738 ProxyDetector::ProxyDetector(net::ProxyService* proxy_service, | |
| 739 const net::HostPortPair& server_address, | |
| 740 ProxyDetectorCallback callback) | |
| 741 : proxy_service_(proxy_service), | |
| 742 server_address_(server_address), | |
| 743 callback_(callback), | |
| 744 has_pending_proxy_resolution_(false) { | |
| 745 } | |
| 746 | |
| 747 ProxyDetector::~ProxyDetector() { | |
| 748 CHECK(!has_pending_proxy_resolution_); | |
| 749 } | |
| 750 | |
| 751 void ProxyDetector::ResolveProxy() { | |
|
eroman
2012/05/08 01:02:27
[optional] nit: I suggest calling this StartResolv
ramant (doing other things)
2012/05/08 05:28:19
Done.
| |
| 752 std::string url = | |
| 753 base::StringPrintf("https://%s", server_address_.ToString().c_str()); | |
| 754 GURL gurl(url); | |
| 755 | |
| 756 has_pending_proxy_resolution_ = true; | |
| 757 DCHECK(proxy_service_); | |
| 758 int rv = proxy_service_->ResolveProxy( | |
| 759 gurl, | |
| 760 &proxy_info_, | |
| 761 base::Bind(&ProxyDetector::OnResolveProxyComplete, | |
| 762 base::Unretained(this)), | |
| 763 NULL, | |
| 764 net::BoundNetLog()); | |
| 765 if (rv == net::OK) | |
|
eroman
2012/05/08 01:02:27
this should actually be:
rv != net::ERR_IO_PENDI
ramant (doing other things)
2012/05/08 05:28:19
Done.
| |
| 766 OnResolveProxyComplete(rv); | |
| 767 } | |
| 768 | |
| 769 void ProxyDetector::OnResolveProxyComplete(int result) { | |
| 770 DCHECK(result == net::OK); | |
|
eroman
2012/05/08 01:02:27
Delete this. (Errors are possible).
ramant (doing other things)
2012/05/08 05:28:19
Done.
| |
| 771 | |
| 772 has_pending_proxy_resolution_ = false; | |
| 773 bool has_proxy_server = (proxy_info_.proxy_server().is_valid() && | |
|
eroman
2012/05/08 01:02:27
Please also add result == net::OK at the start.
ramant (doing other things)
2012/05/08 05:28:19
Done.
| |
| 774 !proxy_info_.proxy_server().is_direct()); | |
| 775 | |
| 776 callback_.Run(has_proxy_server); | |
| 777 | |
| 778 // TODO(rtenneti): Will we leak if ProxtResolve is cancelled (or proxy | |
| 779 // resolution never completes). | |
| 780 delete this; | |
| 781 } | |
| 782 | |
| 720 // static | 783 // static |
| 721 void CollectNetworkStats(const std::string& network_stats_server, | 784 void CollectNetworkStats(const std::string& network_stats_server, |
| 722 IOThread* io_thread) { | 785 IOThread* io_thread) { |
| 723 if (network_stats_server.empty()) | 786 if (network_stats_server.empty()) |
| 724 return; | 787 return; |
| 725 | 788 |
| 726 // If we are not on IO Thread, then post a task to call CollectNetworkStats on | 789 // If we are not on IO Thread, then post a task to call CollectNetworkStats on |
| 727 // IO Thread. | 790 // IO Thread. |
| 728 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 791 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 729 BrowserThread::PostTask( | 792 BrowserThread::PostTask( |
| 730 BrowserThread::IO, | 793 BrowserThread::IO, |
| 731 FROM_HERE, | 794 FROM_HERE, |
| 732 base::Bind( | 795 base::Bind( |
| 733 &CollectNetworkStats, network_stats_server, io_thread)); | 796 &CollectNetworkStats, network_stats_server, io_thread)); |
| 734 return; | 797 return; |
| 735 } | 798 } |
| 736 | 799 |
| 737 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 800 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 738 | 801 |
| 739 // Check that there is a network connection. We get called only if UMA upload | 802 // Check that there is a network connection. We get called only if UMA upload |
| 740 // to the server has succeeded. | 803 // to the server has succeeded. |
| 741 DCHECK(!net::NetworkChangeNotifier::IsOffline()); | 804 DCHECK(!net::NetworkChangeNotifier::IsOffline()); |
| 742 | 805 |
| 743 CR_DEFINE_STATIC_LOCAL(scoped_refptr<base::FieldTrial>, trial, ()); | 806 CR_DEFINE_STATIC_LOCAL(scoped_refptr<base::FieldTrial>, trial, ()); |
| 744 static bool collect_stats = false; | 807 static bool collect_stats = false; |
| 745 | |
| 746 static uint32 port; | |
| 747 static NetworkStats::HistogramPortSelector histogram_port; | 808 static NetworkStats::HistogramPortSelector histogram_port; |
| 748 | 809 |
| 749 if (!trial.get()) { | 810 if (!trial.get()) { |
| 750 // Set up a field trial to collect network stats for UDP and TCP. | 811 // Set up a field trial to collect network stats for UDP and TCP. |
| 751 const base::FieldTrial::Probability kDivisor = 1000; | 812 const base::FieldTrial::Probability kDivisor = 1000; |
| 752 | 813 |
| 753 // Enable the connectivity testing for 0.5% of the users in stable channel. | 814 // Enable the connectivity testing for 0.5% of the users in stable channel. |
| 754 base::FieldTrial::Probability probability_per_group = 5; | 815 base::FieldTrial::Probability probability_per_group = 5; |
| 755 | 816 |
| 756 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 817 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 775 if (trial->group() == collect_stats_group) | 836 if (trial->group() == collect_stats_group) |
| 776 collect_stats = true; | 837 collect_stats = true; |
| 777 | 838 |
| 778 if (collect_stats) { | 839 if (collect_stats) { |
| 779 // Pick a port randomly from the set of TCP/UDP echo server ports | 840 // Pick a port randomly from the set of TCP/UDP echo server ports |
| 780 // specified in |kPorts|. | 841 // specified in |kPorts|. |
| 781 histogram_port = static_cast<NetworkStats::HistogramPortSelector>( | 842 histogram_port = static_cast<NetworkStats::HistogramPortSelector>( |
| 782 base::RandInt(NetworkStats::PORT_53, NetworkStats::PORT_8080)); | 843 base::RandInt(NetworkStats::PORT_53, NetworkStats::PORT_8080)); |
| 783 DCHECK_GE(histogram_port, NetworkStats::PORT_53); | 844 DCHECK_GE(histogram_port, NetworkStats::PORT_53); |
| 784 DCHECK_LE(histogram_port, NetworkStats::PORT_8080); | 845 DCHECK_LE(histogram_port, NetworkStats::PORT_8080); |
| 785 port = kPorts[histogram_port]; | |
| 786 } | 846 } |
| 787 } | 847 } |
| 788 | 848 |
| 789 if (!collect_stats) | 849 if (!collect_stats) |
| 790 return; | 850 return; |
| 791 | 851 |
| 792 // Run test kMaxNumberOfTests times. | 852 // Run test kMaxNumberOfTests times. |
| 793 const size_t kMaxNumberOfTests = INT_MAX; | 853 const size_t kMaxNumberOfTests = INT_MAX; |
| 794 static size_t number_of_tests_done = 0; | 854 static size_t number_of_tests_done = 0; |
| 795 if (number_of_tests_done > kMaxNumberOfTests) | 855 if (number_of_tests_done > kMaxNumberOfTests) |
| 796 return; | 856 return; |
| 797 | 857 |
| 798 ++number_of_tests_done; | 858 ++number_of_tests_done; |
| 799 | 859 |
| 800 net::HostResolver* host_resolver = io_thread->globals()->host_resolver.get(); | 860 net::HostResolver* host_resolver = io_thread->globals()->host_resolver.get(); |
| 801 DCHECK(host_resolver); | 861 DCHECK(host_resolver); |
| 802 | 862 |
| 803 net::HostPortPair server_address(network_stats_server, port); | 863 net::HostPortPair server_address(network_stats_server, |
| 864 kPorts[histogram_port]); | |
| 804 | 865 |
| 866 net::ProxyService* proxy_service = | |
| 867 io_thread->globals()->system_proxy_service.get(); | |
| 868 DCHECK(proxy_service); | |
| 869 | |
| 870 ProxyDetector::ProxyDetectorCallback callback = | |
| 871 base::Bind(&StartNetworkStatsTest, | |
| 872 host_resolver, server_address, histogram_port); | |
| 873 | |
| 874 ProxyDetector* proxy_client = new ProxyDetector( | |
| 875 proxy_service, server_address, callback); | |
| 876 proxy_client->ResolveProxy(); | |
| 877 } | |
| 878 | |
| 879 // static | |
| 880 void StartNetworkStatsTest(net::HostResolver* host_resolver, | |
| 881 const net::HostPortPair& server_address, | |
| 882 NetworkStats::HistogramPortSelector histogram_port, | |
| 883 bool has_proxy_server) { | |
| 805 int experiment_to_run = base::RandInt(1, 5); | 884 int experiment_to_run = base::RandInt(1, 5); |
| 806 switch (experiment_to_run) { | 885 switch (experiment_to_run) { |
| 807 case 1: | 886 case 1: |
| 808 { | 887 { |
| 809 UDPStatsClient* small_udp_stats = new UDPStatsClient(); | 888 UDPStatsClient* small_udp_stats = new UDPStatsClient(); |
| 810 small_udp_stats->Start( | 889 small_udp_stats->Start( |
| 811 host_resolver, server_address, histogram_port, | 890 host_resolver, server_address, histogram_port, has_proxy_server, |
| 812 kSmallTestBytesToSend, 1, net::CompletionCallback()); | 891 kSmallTestBytesToSend, 1, net::CompletionCallback()); |
| 813 } | 892 } |
| 814 break; | 893 break; |
| 815 | 894 |
| 816 case 2: | 895 case 2: |
| 817 { | 896 { |
| 818 UDPStatsClient* large_udp_stats = new UDPStatsClient(); | 897 UDPStatsClient* large_udp_stats = new UDPStatsClient(); |
| 819 large_udp_stats->Start( | 898 large_udp_stats->Start( |
| 820 host_resolver, server_address, histogram_port, | 899 host_resolver, server_address, histogram_port, has_proxy_server, |
| 821 kLargeTestBytesToSend, 1, net::CompletionCallback()); | 900 kLargeTestBytesToSend, 1, net::CompletionCallback()); |
| 822 } | 901 } |
| 823 break; | 902 break; |
| 824 | 903 |
| 825 case 3: | 904 case 3: |
| 826 { | 905 { |
| 827 TCPStatsClient* small_tcp_client = new TCPStatsClient(); | 906 TCPStatsClient* small_tcp_client = new TCPStatsClient(); |
| 828 small_tcp_client->Start( | 907 small_tcp_client->Start( |
| 829 host_resolver, server_address, histogram_port, | 908 host_resolver, server_address, histogram_port, has_proxy_server, |
| 830 kSmallTestBytesToSend, 1, net::CompletionCallback()); | 909 kSmallTestBytesToSend, 1, net::CompletionCallback()); |
| 831 } | 910 } |
| 832 break; | 911 break; |
| 833 | 912 |
| 834 case 4: | 913 case 4: |
| 835 { | 914 { |
| 836 TCPStatsClient* large_tcp_client = new TCPStatsClient(); | 915 TCPStatsClient* large_tcp_client = new TCPStatsClient(); |
| 837 large_tcp_client->Start( | 916 large_tcp_client->Start( |
| 838 host_resolver, server_address, histogram_port, | 917 host_resolver, server_address, histogram_port, has_proxy_server, |
| 839 kLargeTestBytesToSend, 1, net::CompletionCallback()); | 918 kLargeTestBytesToSend, 1, net::CompletionCallback()); |
| 840 } | 919 } |
| 841 break; | 920 break; |
| 842 | 921 |
| 843 case 5: | 922 case 5: |
| 844 { | 923 { |
| 845 UDPStatsClient* packet_loss_udp_stats = new UDPStatsClient(); | 924 UDPStatsClient* packet_loss_udp_stats = new UDPStatsClient(); |
| 846 packet_loss_udp_stats->Start( | 925 packet_loss_udp_stats->Start( |
| 847 host_resolver, server_address, histogram_port, | 926 host_resolver, server_address, histogram_port, has_proxy_server, |
| 848 kLargeTestBytesToSend, kMaximumPackets, net::CompletionCallback()); | 927 kLargeTestBytesToSend, kMaximumPackets, net::CompletionCallback()); |
| 849 } | 928 } |
| 850 break; | 929 break; |
| 851 } | 930 } |
| 852 } | 931 } |
| 853 | 932 |
| 854 } // namespace chrome_browser_net | 933 } // namespace chrome_browser_net |
| OLD | NEW |