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