Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: net/url_request/url_request_http_job.cc

Issue 10933022: Revert 153131 (Histograms showed it doesn't help much) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/url_request/url_request_http_job.h ('k') | net/url_request/url_request_job_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "net/url_request/url_request_http_job.h" 5 #include "net/url_request/url_request_http_job.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "net/url_request/url_request_context.h" 42 #include "net/url_request/url_request_context.h"
43 #include "net/url_request/url_request_error_job.h" 43 #include "net/url_request/url_request_error_job.h"
44 #include "net/url_request/url_request_redirect_job.h" 44 #include "net/url_request/url_request_redirect_job.h"
45 #include "net/url_request/url_request_throttler_header_adapter.h" 45 #include "net/url_request/url_request_throttler_header_adapter.h"
46 #include "net/url_request/url_request_throttler_manager.h" 46 #include "net/url_request/url_request_throttler_manager.h"
47 47
48 static const char kAvailDictionaryHeader[] = "Avail-Dictionary"; 48 static const char kAvailDictionaryHeader[] = "Avail-Dictionary";
49 49
50 namespace net { 50 namespace net {
51 51
52 namespace {
53
54 // Array of all network error codes. Needed for histograms.
55 const int kAllNetErrorCodes[] = {
56 #define NET_ERROR(label, value) -(value),
57 #include "net/base/net_error_list.h"
58 #undef NET_ERROR
59 };
60
61 } // namespace
62
63 class URLRequestHttpJob::HttpFilterContext : public FilterContext { 52 class URLRequestHttpJob::HttpFilterContext : public FilterContext {
64 public: 53 public:
65 explicit HttpFilterContext(URLRequestHttpJob* job); 54 explicit HttpFilterContext(URLRequestHttpJob* job);
66 virtual ~HttpFilterContext(); 55 virtual ~HttpFilterContext();
67 56
68 // FilterContext implementation. 57 // FilterContext implementation.
69 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; 58 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE;
70 virtual bool GetURL(GURL* gurl) const OVERRIDE; 59 virtual bool GetURL(GURL* gurl) const OVERRIDE;
71 virtual base::Time GetRequestTime() const OVERRIDE; 60 virtual base::Time GetRequestTime() const OVERRIDE;
72 virtual bool IsCachedContent() const OVERRIDE; 61 virtual bool IsCachedContent() const OVERRIDE;
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 bytes_observed_in_packets_(0), 240 bytes_observed_in_packets_(0),
252 request_time_snapshot_(), 241 request_time_snapshot_(),
253 final_packet_time_(), 242 final_packet_time_(),
254 ALLOW_THIS_IN_INITIALIZER_LIST( 243 ALLOW_THIS_IN_INITIALIZER_LIST(
255 filter_context_(new HttpFilterContext(this))), 244 filter_context_(new HttpFilterContext(this))),
256 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 245 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
257 ALLOW_THIS_IN_INITIALIZER_LIST(on_headers_received_callback_( 246 ALLOW_THIS_IN_INITIALIZER_LIST(on_headers_received_callback_(
258 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback, 247 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback,
259 base::Unretained(this)))), 248 base::Unretained(this)))),
260 awaiting_callback_(false), 249 awaiting_callback_(false),
261 http_transaction_delegate_(new HttpTransactionDelegateImpl(request)), 250 http_transaction_delegate_(new HttpTransactionDelegateImpl(request)) {
262 has_retried_(false),
263 error_before_retry_(OK) {
264 URLRequestThrottlerManager* manager = request->context()->throttler_manager(); 251 URLRequestThrottlerManager* manager = request->context()->throttler_manager();
265 if (manager) 252 if (manager)
266 throttling_entry_ = manager->RegisterRequestUrl(request->url()); 253 throttling_entry_ = manager->RegisterRequestUrl(request->url());
267 254
268 ResetTimer(); 255 ResetTimer();
269 } 256 }
270 257
271 void URLRequestHttpJob::NotifyHeadersComplete() { 258 void URLRequestHttpJob::NotifyHeadersComplete() {
272 DCHECK(!response_info_); 259 DCHECK(!response_info_);
273 260
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 // If the transaction was destroyed, then the job was cancelled, and 753 // If the transaction was destroyed, then the job was cancelled, and
767 // we can just ignore this notification. 754 // we can just ignore this notification.
768 if (!transaction_.get()) 755 if (!transaction_.get())
769 return; 756 return;
770 757
771 // Clear the IO_PENDING status 758 // Clear the IO_PENDING status
772 SetStatus(URLRequestStatus()); 759 SetStatus(URLRequestStatus());
773 760
774 const URLRequestContext* context = request_->context(); 761 const URLRequestContext* context = request_->context();
775 762
776 // If this was a retry, record whether or not we successfully connected to
777 // the server on the second try.
778 if (error_before_retry_ != OK) {
779 DCHECK(has_retried_);
780 RecordRetryResult(result);
781 error_before_retry_ = OK;
782 }
783
784 if (result == ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN && 763 if (result == ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN &&
785 transaction_->GetResponseInfo() != NULL) { 764 transaction_->GetResponseInfo() != NULL) {
786 FraudulentCertificateReporter* reporter = 765 FraudulentCertificateReporter* reporter =
787 context->fraudulent_certificate_reporter(); 766 context->fraudulent_certificate_reporter();
788 if (reporter != NULL) { 767 if (reporter != NULL) {
789 const SSLInfo& ssl_info = transaction_->GetResponseInfo()->ssl_info; 768 const SSLInfo& ssl_info = transaction_->GetResponseInfo()->ssl_info;
790 bool sni_available = SSLConfigService::IsSNIAvailable( 769 bool sni_available = SSLConfigService::IsSNIAvailable(
791 context->ssl_config_service()); 770 context->ssl_config_service());
792 const std::string& host = request_->url().host(); 771 const std::string& host = request_->url().host();
793 772
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 const bool fatal = 809 const bool fatal =
831 context->transport_security_state() && 810 context->transport_security_state() &&
832 context->transport_security_state()->GetDomainState( 811 context->transport_security_state()->GetDomainState(
833 request_info_.url.host(), 812 request_info_.url.host(),
834 SSLConfigService::IsSNIAvailable(context->ssl_config_service()), 813 SSLConfigService::IsSNIAvailable(context->ssl_config_service()),
835 &domain_state); 814 &domain_state);
836 NotifySSLCertificateError(transaction_->GetResponseInfo()->ssl_info, fatal); 815 NotifySSLCertificateError(transaction_->GetResponseInfo()->ssl_info, fatal);
837 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { 816 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) {
838 NotifyCertificateRequested( 817 NotifyCertificateRequested(
839 transaction_->GetResponseInfo()->cert_request_info); 818 transaction_->GetResponseInfo()->cert_request_info);
840 } else if (ShouldRetryRequest(result)) {
841 RetryRequestOnError(result);
842 } else { 819 } else {
843 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); 820 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result));
844 } 821 }
845 } 822 }
846 823
847 void URLRequestHttpJob::OnHeadersReceivedCallback(int result) { 824 void URLRequestHttpJob::OnHeadersReceivedCallback(int result) {
848 request_->net_log().EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE); 825 request_->net_log().EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE);
849 awaiting_callback_ = false; 826 awaiting_callback_ = false;
850 827
851 // Check that there are no callbacks to already canceled requests. 828 // Check that there are no callbacks to already canceled requests.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 ResetTimer(); 860 ResetTimer();
884 861
885 // Update the cookies, since the cookie store may have been updated from the 862 // Update the cookies, since the cookie store may have been updated from the
886 // headers in the 401/407. Since cookies were already appended to 863 // headers in the 401/407. Since cookies were already appended to
887 // extra_headers, we need to strip them out before adding them again. 864 // extra_headers, we need to strip them out before adding them again.
888 request_info_.extra_headers.RemoveHeader(HttpRequestHeaders::kCookie); 865 request_info_.extra_headers.RemoveHeader(HttpRequestHeaders::kCookie);
889 866
890 AddCookieHeaderAndStart(); 867 AddCookieHeaderAndStart();
891 } 868 }
892 869
893 void URLRequestHttpJob::RetryRequestOnError(int result) {
894 // Should have a transaction that returned the result, but should not have
895 // received headers yet.
896 DCHECK(transaction_.get());
897 DCHECK(!response_info_);
898 DCHECK(result != OK && result != ERR_IO_PENDING);
899
900 error_before_retry_ = result;
901 has_retried_ = true;
902 ResetTimer();
903 transaction_.reset();
904
905 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
906 StartTransactionInternal();
907 }
908
909 bool URLRequestHttpJob::ShouldRetryRequest(int result) const {
910 // Request must not have been cancelled, and no response info may have been
911 // received yet.
912 DCHECK(transaction_.get());
913 DCHECK(request_);
914 DCHECK(!response_info_);
915
916 // Don't retry if the request has already been retried or it's not a GET.
917 if (has_retried_ || request_->method() != "GET") {
918 return false;
919 }
920
921
922 // If the HTTP job has already taken too long, do not retry the request.
923 base::TimeDelta request_duration = base::TimeTicks::Now() - start_time_;
924 if (request_duration >= base::TimeDelta::FromSeconds(10))
925 return false;
926
927 // TODO(mmenke): Look at the metrics and figure out which, if any, of these
928 // error codes it's worth retrying on.
929 switch (result) {
930 // These four error codes will also result in a retry in NetworkTransaction,
931 // in the case of a reused socket. It's unclear how much correlation there
932 // is between receiving one of these errors on a reused socket and on a
933 // fresh socket on retry.
934 case ERR_CONNECTION_RESET:
935 case ERR_CONNECTION_CLOSED:
936 case ERR_CONNECTION_ABORTED:
937 case ERR_SOCKET_NOT_CONNECTED:
938
939 // System errors.
940 case ERR_FAILED:
941 case ERR_UNEXPECTED:
942
943 // Connection errors.
944 case ERR_CONNECTION_REFUSED:
945 case ERR_CONNECTION_FAILED:
946 case ERR_NAME_NOT_RESOLVED:
947 case ERR_INTERNET_DISCONNECTED:
948 case ERR_ADDRESS_UNREACHABLE:
949 case ERR_NETWORK_ACCESS_DENIED:
950 case ERR_ADDRESS_IN_USE:
951
952 // Content errors.
953 case ERR_EMPTY_RESPONSE:
954
955 // Cache errors.
956 case ERR_CACHE_MISS:
957 case ERR_CACHE_READ_FAILURE:
958 return true;
959
960 default:
961 return false;
962 }
963 }
964
965 void URLRequestHttpJob::SetUpload(UploadData* upload) { 870 void URLRequestHttpJob::SetUpload(UploadData* upload) {
966 DCHECK(!transaction_.get()) << "cannot change once started"; 871 DCHECK(!transaction_.get()) << "cannot change once started";
967 request_info_.upload_data = upload; 872 request_info_.upload_data = upload;
968 } 873 }
969 874
970 void URLRequestHttpJob::SetExtraRequestHeaders( 875 void URLRequestHttpJob::SetExtraRequestHeaders(
971 const HttpRequestHeaders& headers) { 876 const HttpRequestHeaders& headers) {
972 DCHECK(!transaction_.get()) << "cannot change once started"; 877 DCHECK(!transaction_.get()) << "cannot change once started";
973 request_info_.extra_headers.CopyFrom(headers); 878 request_info_.extra_headers.CopyFrom(headers);
974 } 879 }
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 1314
1410 void URLRequestHttpJob::ResetTimer() { 1315 void URLRequestHttpJob::ResetTimer() {
1411 if (!request_creation_time_.is_null()) { 1316 if (!request_creation_time_.is_null()) {
1412 NOTREACHED() 1317 NOTREACHED()
1413 << "The timer was reset before it was recorded."; 1318 << "The timer was reset before it was recorded.";
1414 return; 1319 return;
1415 } 1320 }
1416 request_creation_time_ = base::Time::Now(); 1321 request_creation_time_ = base::Time::Now();
1417 } 1322 }
1418 1323
1419 void URLRequestHttpJob::RecordRetryResult(int result) const {
1420 if (request_info_.load_flags & LOAD_MAIN_FRAME) {
1421 if (result != OK) {
1422 UMA_HISTOGRAM_CUSTOM_ENUMERATION(
1423 "Net.NetworkErrorsRecovered.MainFrame",
1424 -error_before_retry_,
1425 base::CustomHistogram::ArrayToCustomRanges(
1426 kAllNetErrorCodes, arraysize(kAllNetErrorCodes)));
1427 } else {
1428 UMA_HISTOGRAM_CUSTOM_ENUMERATION(
1429 "Net.NetworkErrorsUnrecovered.MainFrame",
1430 -error_before_retry_,
1431 base::CustomHistogram::ArrayToCustomRanges(
1432 kAllNetErrorCodes, arraysize(kAllNetErrorCodes)));
1433 }
1434 } else {
1435 if (result != OK) {
1436 UMA_HISTOGRAM_CUSTOM_ENUMERATION(
1437 "Net.NetworkErrorsRecovered.Subresource",
1438 -error_before_retry_,
1439 base::CustomHistogram::ArrayToCustomRanges(
1440 kAllNetErrorCodes, arraysize(kAllNetErrorCodes)));
1441 } else {
1442 UMA_HISTOGRAM_CUSTOM_ENUMERATION(
1443 "Net.NetworkErrorsUnrecovered.Subresource",
1444 -error_before_retry_,
1445 base::CustomHistogram::ArrayToCustomRanges(
1446 kAllNetErrorCodes, arraysize(kAllNetErrorCodes)));
1447 }
1448 }
1449 }
1450
1451 void URLRequestHttpJob::UpdatePacketReadTimes() { 1324 void URLRequestHttpJob::UpdatePacketReadTimes() {
1452 if (!packet_timing_enabled_) 1325 if (!packet_timing_enabled_)
1453 return; 1326 return;
1454 1327
1455 if (filter_input_byte_count() <= bytes_observed_in_packets_) { 1328 if (filter_input_byte_count() <= bytes_observed_in_packets_) {
1456 DCHECK_EQ(filter_input_byte_count(), bytes_observed_in_packets_); 1329 DCHECK_EQ(filter_input_byte_count(), bytes_observed_in_packets_);
1457 return; // No new bytes have arrived. 1330 return; // No new bytes have arrived.
1458 } 1331 }
1459 1332
1460 final_packet_time_ = base::Time::Now(); 1333 final_packet_time_ = base::Time::Now();
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 1501
1629 void URLRequestHttpJob::NotifyURLRequestDestroyed() { 1502 void URLRequestHttpJob::NotifyURLRequestDestroyed() {
1630 awaiting_callback_ = false; 1503 awaiting_callback_ = false;
1631 } 1504 }
1632 1505
1633 void URLRequestHttpJob::OnDetachRequest() { 1506 void URLRequestHttpJob::OnDetachRequest() {
1634 http_transaction_delegate_->OnDetachRequest(); 1507 http_transaction_delegate_->OnDetachRequest();
1635 } 1508 }
1636 1509
1637 } // namespace net 1510 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_http_job.h ('k') | net/url_request/url_request_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698