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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 | 80 |
| 79 // HistogramPortSelector and kPorts should be kept in sync. | 81 // HistogramPortSelector and kPorts should be kept in sync. |
| 80 static const int32 kPorts[] = {53, 80, 587, 6121, 8080, 999999}; | 82 static const int32 kPorts[] = {53, 80, 587, 6121, 8080, 999999}; |
| 81 | 83 |
| 82 // NetworkStats methods and members. | 84 // NetworkStats methods and members. |
| 83 NetworkStats::NetworkStats() | 85 NetworkStats::NetworkStats() |
| 84 : load_size_(0), | 86 : load_size_(0), |
| 85 bytes_to_read_(0), | 87 bytes_to_read_(0), |
| 86 bytes_to_send_(0), | 88 bytes_to_send_(0), |
| 87 encoded_message_(""), | 89 encoded_message_(""), |
| 90 has_no_proxy_server_(true), | |
| 88 start_time_(base::TimeTicks::Now()), | 91 start_time_(base::TimeTicks::Now()), |
| 89 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 92 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 90 } | 93 } |
| 91 | 94 |
| 92 NetworkStats::~NetworkStats() { | 95 NetworkStats::~NetworkStats() { |
| 93 socket_.reset(); | 96 socket_.reset(); |
| 94 } | 97 } |
| 95 | 98 |
| 96 bool NetworkStats::Start(net::HostResolver* host_resolver, | 99 bool NetworkStats::Start(net::HostResolver* host_resolver, |
| 97 const net::HostPortPair& server_host_port_pair, | 100 const net::HostPortPair& server_host_port_pair, |
| 98 HistogramPortSelector histogram_port, | 101 HistogramPortSelector histogram_port, |
| 102 bool has_no_proxy_server, | |
| 99 uint32 bytes_to_send, | 103 uint32 bytes_to_send, |
| 100 const net::CompletionCallback& finished_callback) { | 104 const net::CompletionCallback& finished_callback) { |
| 101 DCHECK(bytes_to_send); // We should have data to send. | 105 DCHECK(bytes_to_send); // We should have data to send. |
| 102 | 106 |
| 103 Initialize(bytes_to_send, histogram_port, finished_callback); | 107 Initialize( |
| 108 bytes_to_send, histogram_port, has_no_proxy_server, finished_callback); | |
| 104 | 109 |
| 105 net::HostResolver::RequestInfo request(server_host_port_pair); | 110 net::HostResolver::RequestInfo request(server_host_port_pair); |
| 106 int rv = host_resolver->Resolve( | 111 int rv = host_resolver->Resolve( |
| 107 request, &addresses_, | 112 request, &addresses_, |
| 108 base::Bind(&NetworkStats::OnResolveComplete, | 113 base::Bind(&NetworkStats::OnResolveComplete, |
| 109 base::Unretained(this)), | 114 base::Unretained(this)), |
| 110 NULL, net::BoundNetLog()); | 115 NULL, net::BoundNetLog()); |
| 111 if (rv == net::ERR_IO_PENDING) | 116 if (rv == net::ERR_IO_PENDING) |
| 112 return true; | 117 return true; |
| 113 return DoConnect(rv); | 118 return DoConnect(rv); |
| 114 } | 119 } |
| 115 | 120 |
| 116 void NetworkStats::Initialize( | 121 void NetworkStats::Initialize( |
| 117 uint32 bytes_to_send, | 122 uint32 bytes_to_send, |
| 118 HistogramPortSelector histogram_port, | 123 HistogramPortSelector histogram_port, |
| 124 bool has_no_proxy_server, | |
| 119 const net::CompletionCallback& finished_callback) { | 125 const net::CompletionCallback& finished_callback) { |
| 120 DCHECK(bytes_to_send); // We should have data to send. | 126 DCHECK(bytes_to_send); // We should have data to send. |
| 121 DCHECK_LE(bytes_to_send, kLargeTestBytesToSend); | 127 DCHECK_LE(bytes_to_send, kLargeTestBytesToSend); |
| 122 | 128 |
| 123 load_size_ = bytes_to_send; | 129 load_size_ = bytes_to_send; |
| 124 bytes_to_send_ = kVersionLength + kChecksumLength + kPayloadSizeLength + | 130 bytes_to_send_ = kVersionLength + kChecksumLength + kPayloadSizeLength + |
| 125 load_size_; | 131 load_size_; |
| 126 bytes_to_read_ = kVersionLength + kChecksumLength + kPayloadSizeLength + | 132 bytes_to_read_ = kVersionLength + kChecksumLength + kPayloadSizeLength + |
| 127 kKeyLength + load_size_; | 133 kKeyLength + load_size_; |
| 128 | 134 |
| 129 histogram_port_ = histogram_port; | 135 histogram_port_ = histogram_port; |
| 136 has_no_proxy_server_ = has_no_proxy_server; | |
| 130 finished_callback_ = finished_callback; | 137 finished_callback_ = finished_callback; |
| 131 } | 138 } |
| 132 | 139 |
| 133 bool NetworkStats::ConnectComplete(int result) { | 140 bool NetworkStats::ConnectComplete(int result) { |
| 134 if (result < 0) { | 141 if (result < 0) { |
| 135 Finish(CONNECT_FAILED, result); | 142 Finish(CONNECT_FAILED, result); |
| 136 return false; | 143 return false; |
| 137 } | 144 } |
| 138 | 145 |
| 139 DCHECK(bytes_to_send_); // We should have data to send. | 146 DCHECK(bytes_to_send_); // We should have data to send. |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 return INVALID_CHECKSUM; | 409 return INVALID_CHECKSUM; |
| 403 | 410 |
| 404 stream_.Reset(); | 411 stream_.Reset(); |
| 405 if (!stream_.VerifyBytes(decoded_data, message_length)) | 412 if (!stream_.VerifyBytes(decoded_data, message_length)) |
| 406 return PATTERN_CHANGED; | 413 return PATTERN_CHANGED; |
| 407 | 414 |
| 408 return SUCCESS; | 415 return SUCCESS; |
| 409 } | 416 } |
| 410 | 417 |
| 411 // static | 418 // static |
| 412 void NetworkStats::GetHistogramNames(const ProtocolValue& protocol, | 419 void NetworkStats::GetHistogramNames( |
| 413 HistogramPortSelector port, | 420 const ProtocolValue& protocol, |
| 414 uint32 load_size, | 421 HistogramPortSelector histogram_port, |
| 415 int result, | 422 bool has_no_proxy_server, |
| 416 std::string* rtt_histogram_name, | 423 uint32 load_size, |
| 417 std::string* status_histogram_name) { | 424 int result, |
| 418 CHECK_GE(port, PORT_53); | 425 std::string* rtt_histogram_name, |
| 419 CHECK_LE(port, HISTOGRAM_PORT_MAX); | 426 std::string* rtt_no_proxy_histogram_name, |
| 427 std::string* status_histogram_name, | |
| 428 std::string* status_no_proxy_histogram_name) { | |
| 429 CHECK_GE(histogram_port, PORT_53); | |
| 430 CHECK_LE(histogram_port, HISTOGRAM_PORT_MAX); | |
| 420 | 431 |
| 421 // Build <protocol> string. | 432 // Build <protocol> string. |
| 422 const char* kTcpString = "TCP"; | 433 const char* kTcpString = "TCP"; |
| 423 const char* kUdpString = "UDP"; | 434 const char* kUdpString = "UDP"; |
| 424 const char* protocol_string; | 435 const char* protocol_string; |
| 425 if (protocol == PROTOCOL_TCP) | 436 if (protocol == PROTOCOL_TCP) |
| 426 protocol_string = kTcpString; | 437 protocol_string = kTcpString; |
| 427 else | 438 else |
| 428 protocol_string = kUdpString; | 439 protocol_string = kUdpString; |
| 429 | 440 |
| 430 // Build <load_size> string. | 441 // Build <load_size> string. |
| 431 const char* kSmallLoadString = "100B"; | 442 const char* kSmallLoadString = "100B"; |
| 432 const char* kLargeLoadString = "1K"; | 443 const char* kLargeLoadString = "1K"; |
| 433 const char* load_size_string; | 444 const char* load_size_string; |
| 434 if (load_size == kSmallTestBytesToSend) | 445 if (load_size == kSmallTestBytesToSend) |
| 435 load_size_string = kSmallLoadString; | 446 load_size_string = kSmallLoadString; |
| 436 else | 447 else |
| 437 load_size_string = kLargeLoadString; | 448 load_size_string = kLargeLoadString; |
| 438 | 449 |
| 439 // Build "NetConnectivity.<protocol>.Success.<port>.<load_size>.RTT" | 450 // Build "NetConnectivity.<protocol>.Success.<port>.<load_size>.RTT" |
| 440 // histogram name. Total number of histograms are 2*5*2. | 451 // and "NetConnectivity.<protocol>.NoProxy.Success.<port>.<load_size>.RTT" |
| 452 // histogram names. Total number of histograms are 2*5*2*2. | |
| 441 if (result == net::OK) { | 453 if (result == net::OK) { |
| 442 *rtt_histogram_name = base::StringPrintf( | 454 *rtt_histogram_name = base::StringPrintf( |
| 443 "NetConnectivity.%s.Success.%d.%s.RTT", | 455 "NetConnectivity.%s.Success.%d.%s.RTT", |
| 444 protocol_string, | 456 protocol_string, |
| 445 kPorts[port], | 457 kPorts[histogram_port], |
| 446 load_size_string); | 458 load_size_string); |
| 459 if (has_no_proxy_server) { | |
| 460 *rtt_no_proxy_histogram_name = base::StringPrintf( | |
| 461 "NetConnectivity.%s.NoProxy.Success.%d.%s.RTT", | |
| 462 protocol_string, | |
| 463 kPorts[histogram_port], | |
| 464 load_size_string); | |
| 465 } else { | |
| 466 rtt_no_proxy_histogram_name->clear(); | |
| 467 } | |
| 468 } else { | |
| 469 rtt_histogram_name->clear(); | |
|
Ryan Sleevi
2012/04/28 02:06:32
random drive by: Since much of our error handling
ramant (doing other things)
2012/04/30 17:17:00
Done.
| |
| 447 } | 470 } |
| 448 | 471 |
| 449 // Build "NetConnectivity.<protocol>.Status.<port>.<load_size>" histogram | 472 // Build "NetConnectivity.<protocol>.Status.<port>.<load_size>" and |
| 450 // name. Total number of histograms are 2*5*2. | 473 // "NetConnectivity.<protocol>.NoProxy.Status.<port>.<load_size>" histogram |
| 474 // name. Total number of histograms are 2*2*5*2. | |
| 451 *status_histogram_name = base::StringPrintf( | 475 *status_histogram_name = base::StringPrintf( |
| 452 "NetConnectivity.%s.Status.%d.%s", | 476 "NetConnectivity.%s.Status.%d.%s", |
| 453 protocol_string, | 477 protocol_string, |
| 454 kPorts[port], | 478 kPorts[histogram_port], |
| 455 load_size_string); | 479 load_size_string); |
| 480 if (has_no_proxy_server) { | |
| 481 *status_no_proxy_histogram_name = base::StringPrintf( | |
| 482 "NetConnectivity.%s.NoProxy.Status.%d.%s", | |
| 483 protocol_string, | |
| 484 kPorts[histogram_port], | |
| 485 load_size_string); | |
| 486 } else { | |
| 487 status_no_proxy_histogram_name->clear(); | |
| 488 } | |
| 456 } | 489 } |
| 457 | 490 |
| 458 void NetworkStats::RecordHistograms(const ProtocolValue& protocol, | 491 void NetworkStats::RecordHistograms(const ProtocolValue& protocol, |
| 459 const Status& status, | 492 const Status& status, |
| 460 int result) { | 493 int result) { |
| 461 base::TimeDelta duration = base::TimeTicks::Now() - start_time(); | 494 base::TimeDelta duration = base::TimeTicks::Now() - start_time(); |
| 462 | 495 |
| 463 std::string rtt_histogram_name; | 496 std::string rtt_histogram_name; |
| 497 std::string rtt_no_proxy_histogram_name; | |
| 464 std::string status_histogram_name; | 498 std::string status_histogram_name; |
| 499 std::string status_no_proxy_histogram_name; | |
| 465 GetHistogramNames(protocol, | 500 GetHistogramNames(protocol, |
| 466 histogram_port_, | 501 histogram_port_, |
| 502 has_no_proxy_server_, | |
| 467 load_size_, | 503 load_size_, |
| 468 result, | 504 result, |
| 469 &rtt_histogram_name, | 505 &rtt_histogram_name, |
| 470 &status_histogram_name); | 506 &rtt_no_proxy_histogram_name, |
| 507 &status_histogram_name, | |
| 508 &status_no_proxy_histogram_name); | |
| 471 | 509 |
| 472 if (result == net::OK) { | 510 if (result == net::OK) { |
| 473 base::Histogram* rtt_histogram = base::Histogram::FactoryTimeGet( | 511 base::Histogram* rtt_histogram = base::Histogram::FactoryTimeGet( |
| 474 rtt_histogram_name, | 512 rtt_histogram_name, |
| 475 base::TimeDelta::FromMilliseconds(10), | 513 base::TimeDelta::FromMilliseconds(10), |
| 476 base::TimeDelta::FromSeconds(60), 50, | 514 base::TimeDelta::FromSeconds(60), 50, |
| 477 base::Histogram::kUmaTargetedHistogramFlag); | 515 base::Histogram::kUmaTargetedHistogramFlag); |
| 478 rtt_histogram->AddTime(duration); | 516 rtt_histogram->AddTime(duration); |
| 517 | |
| 518 if (has_no_proxy_server_) { | |
| 519 base::Histogram* rtt_no_proxy_histogram = base::Histogram::FactoryTimeGet( | |
| 520 rtt_no_proxy_histogram_name, | |
| 521 base::TimeDelta::FromMilliseconds(10), | |
| 522 base::TimeDelta::FromSeconds(60), 50, | |
| 523 base::Histogram::kUmaTargetedHistogramFlag); | |
| 524 rtt_no_proxy_histogram->AddTime(duration); | |
| 525 } | |
| 479 } | 526 } |
| 480 | 527 |
| 481 base::Histogram* status_histogram = base::LinearHistogram::FactoryGet( | 528 base::Histogram* status_histogram = base::LinearHistogram::FactoryGet( |
| 482 status_histogram_name, 1, STATUS_MAX, STATUS_MAX+1, | 529 status_histogram_name, 1, STATUS_MAX, STATUS_MAX+1, |
| 483 base::Histogram::kUmaTargetedHistogramFlag); | 530 base::Histogram::kUmaTargetedHistogramFlag); |
| 484 status_histogram->Add(status); | 531 status_histogram->Add(status); |
| 532 if (has_no_proxy_server_) { | |
| 533 base::Histogram* status_no_proxy_histogram = | |
| 534 base::LinearHistogram::FactoryGet( | |
| 535 status_no_proxy_histogram_name, 1, STATUS_MAX, STATUS_MAX+1, | |
| 536 base::Histogram::kUmaTargetedHistogramFlag); | |
| 537 status_no_proxy_histogram->Add(status); | |
| 538 } | |
| 485 } | 539 } |
| 486 | 540 |
| 487 // UDPStatsClient methods and members. | 541 // UDPStatsClient methods and members. |
| 488 UDPStatsClient::UDPStatsClient() | 542 UDPStatsClient::UDPStatsClient() |
| 489 : NetworkStats() { | 543 : NetworkStats() { |
| 490 } | 544 } |
| 491 | 545 |
| 492 UDPStatsClient::~UDPStatsClient() { | 546 UDPStatsClient::~UDPStatsClient() { |
| 493 } | 547 } |
| 494 | 548 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 597 | 651 |
| 598 // Disconnect the socket so that there are no more IO operations. | 652 // Disconnect the socket so that there are no more IO operations. |
| 599 net::TCPClientSocket* tcp_socket = | 653 net::TCPClientSocket* tcp_socket = |
| 600 static_cast<net::TCPClientSocket*>(socket()); | 654 static_cast<net::TCPClientSocket*>(socket()); |
| 601 if (tcp_socket) | 655 if (tcp_socket) |
| 602 tcp_socket->Disconnect(); | 656 tcp_socket->Disconnect(); |
| 603 | 657 |
| 604 delete this; | 658 delete this; |
| 605 } | 659 } |
| 606 | 660 |
| 661 // ProxyClient methods and members. | |
| 662 ProxyClient::ProxyClient(const std::string& network_stats_server, | |
| 663 NetworkStats::HistogramPortSelector histogram_port, | |
| 664 IOThread* io_thread) | |
| 665 : network_stats_server_(network_stats_server), | |
| 666 histogram_port_(histogram_port), | |
| 667 io_thread_(io_thread) { | |
| 668 } | |
| 669 | |
| 670 ProxyClient::~ProxyClient() { | |
| 671 } | |
| 672 | |
| 673 void ProxyClient::ResolveProxy() { | |
| 674 std::string url = base::StringPrintf("http://%s:%d", | |
| 675 network_stats_server_.c_str(), | |
| 676 kPorts[histogram_port_]); | |
|
Ryan Sleevi
2012/04/28 02:06:32
Would it make more sense to check for HTTPS here?
ramant (doing other things)
2012/04/30 17:17:00
Done.
| |
| 677 GURL gurl(url); | |
| 678 net::ProxyService* service = | |
| 679 io_thread_->globals()->system_proxy_service.get(); | |
| 680 | |
| 681 int rv = service->ResolveProxy( | |
| 682 gurl, | |
| 683 &proxy_info_, | |
| 684 base::Bind(&ProxyClient::OnResolveProxyComplete, | |
| 685 base::Unretained(this)), | |
| 686 NULL, | |
| 687 net::BoundNetLog()); | |
| 688 if (rv == net::OK) | |
| 689 OnResolveProxyComplete(rv); | |
| 690 } | |
| 691 | |
| 692 void ProxyClient::OnResolveProxyComplete(int result) { | |
| 693 bool no_proxy_server = (!proxy_info_.proxy_server().is_valid() || | |
| 694 proxy_info_.proxy_server().is_direct()); | |
| 695 | |
| 696 net::HostResolver* host_resolver = io_thread_->globals()->host_resolver.get(); | |
| 697 DCHECK(host_resolver); | |
| 698 | |
| 699 DCHECK_GE(histogram_port_, NetworkStats::PORT_53); | |
| 700 DCHECK_LE(histogram_port_, NetworkStats::PORT_8080); | |
| 701 net::HostPortPair server_address(network_stats_server_, | |
| 702 kPorts[histogram_port_]); | |
| 703 | |
| 704 UDPStatsClient* small_udp_stats = new UDPStatsClient(); | |
|
Ryan Sleevi
2012/04/28 02:06:32
Might be worth mentioning either here or in networ
ramant (doing other things)
2012/04/30 17:17:00
Done.
| |
| 705 small_udp_stats->Start( | |
| 706 host_resolver, server_address, histogram_port_, no_proxy_server, | |
| 707 kSmallTestBytesToSend, net::CompletionCallback()); | |
| 708 | |
| 709 UDPStatsClient* large_udp_stats = new UDPStatsClient(); | |
| 710 large_udp_stats->Start( | |
| 711 host_resolver, server_address, histogram_port_, no_proxy_server, | |
| 712 kLargeTestBytesToSend, net::CompletionCallback()); | |
| 713 | |
| 714 TCPStatsClient* small_tcp_client = new TCPStatsClient(); | |
| 715 small_tcp_client->Start( | |
| 716 host_resolver, server_address, histogram_port_, no_proxy_server, | |
| 717 kSmallTestBytesToSend, net::CompletionCallback()); | |
| 718 | |
| 719 TCPStatsClient* large_tcp_client = new TCPStatsClient(); | |
| 720 large_tcp_client->Start( | |
| 721 host_resolver, server_address, histogram_port_, no_proxy_server, | |
| 722 kLargeTestBytesToSend, net::CompletionCallback()); | |
| 723 } | |
| 724 | |
| 607 // static | 725 // static |
| 608 void CollectNetworkStats(const std::string& network_stats_server, | 726 void CollectNetworkStats(const std::string& network_stats_server, |
| 609 IOThread* io_thread) { | 727 IOThread* io_thread) { |
| 610 if (network_stats_server.empty()) | 728 if (network_stats_server.empty()) |
| 611 return; | 729 return; |
| 612 | 730 |
| 613 // If we are not on IO Thread, then post a task to call CollectNetworkStats on | 731 // If we are not on IO Thread, then post a task to call CollectNetworkStats on |
| 614 // IO Thread. | 732 // IO Thread. |
| 615 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 733 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 616 BrowserThread::PostTask( | 734 BrowserThread::PostTask( |
| 617 BrowserThread::IO, | 735 BrowserThread::IO, |
| 618 FROM_HERE, | 736 FROM_HERE, |
| 619 base::Bind( | 737 base::Bind( |
| 620 &CollectNetworkStats, network_stats_server, io_thread)); | 738 &CollectNetworkStats, network_stats_server, io_thread)); |
| 621 return; | 739 return; |
| 622 } | 740 } |
| 623 | 741 |
| 624 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 742 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 625 | 743 |
| 626 // Check that there is a network connection. We get called only if UMA upload | 744 // Check that there is a network connection. We get called only if UMA upload |
| 627 // to the server has succeeded. | 745 // to the server has succeeded. |
| 628 DCHECK(!net::NetworkChangeNotifier::IsOffline()); | 746 DCHECK(!net::NetworkChangeNotifier::IsOffline()); |
| 629 | 747 |
| 630 CR_DEFINE_STATIC_LOCAL(scoped_refptr<base::FieldTrial>, trial, ()); | 748 CR_DEFINE_STATIC_LOCAL(scoped_refptr<base::FieldTrial>, trial, ()); |
| 631 static bool collect_stats = false; | 749 static bool collect_stats = false; |
| 632 | 750 |
| 633 static uint32 kTCPTestingPort; | |
| 634 static uint32 kUDPTestingPort; | |
| 635 static NetworkStats::HistogramPortSelector histogram_port; | 751 static NetworkStats::HistogramPortSelector histogram_port; |
| 636 | 752 |
| 637 if (!trial.get()) { | 753 if (!trial.get()) { |
| 638 // Set up a field trial to collect network stats for UDP and TCP. | 754 // Set up a field trial to collect network stats for UDP and TCP. |
| 639 const base::FieldTrial::Probability kDivisor = 1000; | 755 const base::FieldTrial::Probability kDivisor = 1000; |
| 640 | 756 |
| 641 // Enable the connectivity testing for 0.5% of the users in stable channel. | 757 // Enable the connectivity testing for 0.5% of the users in stable channel. |
| 642 base::FieldTrial::Probability probability_per_group = 5; | 758 base::FieldTrial::Probability probability_per_group = 5; |
| 643 | 759 |
| 644 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 760 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 663 if (trial->group() == collect_stats_group) | 779 if (trial->group() == collect_stats_group) |
| 664 collect_stats = true; | 780 collect_stats = true; |
| 665 | 781 |
| 666 if (collect_stats) { | 782 if (collect_stats) { |
| 667 // Pick a port randomly from the set of TCP/UDP echo server ports | 783 // Pick a port randomly from the set of TCP/UDP echo server ports |
| 668 // specified in |kPorts|. | 784 // specified in |kPorts|. |
| 669 histogram_port = static_cast<NetworkStats::HistogramPortSelector>( | 785 histogram_port = static_cast<NetworkStats::HistogramPortSelector>( |
| 670 base::RandInt(NetworkStats::PORT_53, NetworkStats::PORT_8080)); | 786 base::RandInt(NetworkStats::PORT_53, NetworkStats::PORT_8080)); |
| 671 DCHECK_GE(histogram_port, NetworkStats::PORT_53); | 787 DCHECK_GE(histogram_port, NetworkStats::PORT_53); |
| 672 DCHECK_LE(histogram_port, NetworkStats::PORT_8080); | 788 DCHECK_LE(histogram_port, NetworkStats::PORT_8080); |
| 673 kTCPTestingPort = kPorts[histogram_port]; | |
| 674 kUDPTestingPort = kPorts[histogram_port]; | |
| 675 } | 789 } |
| 676 } | 790 } |
| 677 | 791 |
| 678 if (!collect_stats) | 792 if (!collect_stats) |
| 679 return; | 793 return; |
| 680 | 794 |
| 681 // Run test kMaxNumberOfTests times. | 795 // Run test kMaxNumberOfTests times. |
| 682 const size_t kMaxNumberOfTests = INT_MAX; | 796 const size_t kMaxNumberOfTests = INT_MAX; |
| 683 static size_t number_of_tests_done = 0; | 797 static size_t number_of_tests_done = 0; |
| 684 if (number_of_tests_done > kMaxNumberOfTests) | 798 if (number_of_tests_done > kMaxNumberOfTests) |
| 685 return; | 799 return; |
| 686 | 800 |
| 687 ++number_of_tests_done; | 801 ++number_of_tests_done; |
| 688 | 802 |
| 689 net::HostResolver* host_resolver = io_thread->globals()->host_resolver.get(); | 803 ProxyClient* proxy_client = new ProxyClient( |
| 690 DCHECK(host_resolver); | 804 network_stats_server, histogram_port, io_thread); |
| 691 | 805 proxy_client->ResolveProxy(); |
| 692 net::HostPortPair udp_server_address(network_stats_server, kUDPTestingPort); | |
| 693 | |
| 694 UDPStatsClient* small_udp_stats = new UDPStatsClient(); | |
| 695 small_udp_stats->Start( | |
| 696 host_resolver, udp_server_address, histogram_port, | |
| 697 kSmallTestBytesToSend, net::CompletionCallback()); | |
| 698 | |
| 699 UDPStatsClient* large_udp_stats = new UDPStatsClient(); | |
| 700 large_udp_stats->Start( | |
| 701 host_resolver, udp_server_address, histogram_port, | |
| 702 kLargeTestBytesToSend, net::CompletionCallback()); | |
| 703 | |
| 704 net::HostPortPair tcp_server_address(network_stats_server, kTCPTestingPort); | |
| 705 | |
| 706 TCPStatsClient* small_tcp_client = new TCPStatsClient(); | |
| 707 small_tcp_client->Start( | |
| 708 host_resolver, tcp_server_address, histogram_port, | |
| 709 kSmallTestBytesToSend, net::CompletionCallback()); | |
| 710 | |
| 711 TCPStatsClient* large_tcp_client = new TCPStatsClient(); | |
| 712 large_tcp_client->Start( | |
| 713 host_resolver, tcp_server_address, histogram_port, | |
| 714 kLargeTestBytesToSend, net::CompletionCallback()); | |
| 715 } | 806 } |
| 716 | 807 |
| 717 } // namespace chrome_browser_net | 808 } // namespace chrome_browser_net |
| OLD | NEW |