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 "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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 DoneWithRequest(FINISHED); | 409 DoneWithRequest(FINISHED); |
410 URLRequestJob::NotifyDone(status); | 410 URLRequestJob::NotifyDone(status); |
411 } | 411 } |
412 | 412 |
413 void URLRequestHttpJob::DestroyTransaction() { | 413 void URLRequestHttpJob::DestroyTransaction() { |
414 DCHECK(transaction_.get()); | 414 DCHECK(transaction_.get()); |
415 | 415 |
416 DoneWithRequest(ABORTED); | 416 DoneWithRequest(ABORTED); |
417 transaction_.reset(); | 417 transaction_.reset(); |
418 response_info_ = NULL; | 418 response_info_ = NULL; |
| 419 receive_headers_end_ = base::TimeTicks(); |
419 } | 420 } |
420 | 421 |
421 void URLRequestHttpJob::StartTransaction() { | 422 void URLRequestHttpJob::StartTransaction() { |
422 if (network_delegate()) { | 423 if (network_delegate()) { |
423 int rv = network_delegate()->NotifyBeforeSendHeaders( | 424 int rv = network_delegate()->NotifyBeforeSendHeaders( |
424 request_, notify_before_headers_sent_callback_, | 425 request_, notify_before_headers_sent_callback_, |
425 &request_info_.extra_headers); | 426 &request_info_.extra_headers); |
426 // If an extension blocks the request, we rely on the callback to | 427 // If an extension blocks the request, we rely on the callback to |
427 // MaybeStartTransactionInternal(). | 428 // MaybeStartTransactionInternal(). |
428 if (rv == ERR_IO_PENDING) { | 429 if (rv == ERR_IO_PENDING) { |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 | 813 |
813 // If the request was destroyed, then there is no more work to do. | 814 // If the request was destroyed, then there is no more work to do. |
814 if (!request_) | 815 if (!request_) |
815 return; | 816 return; |
816 | 817 |
817 // If the transaction was destroyed, then the job was cancelled, and | 818 // If the transaction was destroyed, then the job was cancelled, and |
818 // we can just ignore this notification. | 819 // we can just ignore this notification. |
819 if (!transaction_.get()) | 820 if (!transaction_.get()) |
820 return; | 821 return; |
821 | 822 |
| 823 receive_headers_end_ = base::TimeTicks::Now(); |
| 824 |
822 // Clear the IO_PENDING status | 825 // Clear the IO_PENDING status |
823 SetStatus(URLRequestStatus()); | 826 SetStatus(URLRequestStatus()); |
824 | 827 |
825 const URLRequestContext* context = request_->context(); | 828 const URLRequestContext* context = request_->context(); |
826 | 829 |
827 if (result == ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN && | 830 if (result == ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN && |
828 transaction_->GetResponseInfo() != NULL) { | 831 transaction_->GetResponseInfo() != NULL) { |
829 FraudulentCertificateReporter* reporter = | 832 FraudulentCertificateReporter* reporter = |
830 context->fraudulent_certificate_reporter(); | 833 context->fraudulent_certificate_reporter(); |
831 if (reporter != NULL) { | 834 if (reporter != NULL) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 | 914 |
912 NotifyReadComplete(result); | 915 NotifyReadComplete(result); |
913 } | 916 } |
914 | 917 |
915 void URLRequestHttpJob::RestartTransactionWithAuth( | 918 void URLRequestHttpJob::RestartTransactionWithAuth( |
916 const AuthCredentials& credentials) { | 919 const AuthCredentials& credentials) { |
917 auth_credentials_ = credentials; | 920 auth_credentials_ = credentials; |
918 | 921 |
919 // These will be reset in OnStartCompleted. | 922 // These will be reset in OnStartCompleted. |
920 response_info_ = NULL; | 923 response_info_ = NULL; |
| 924 receive_headers_end_ = base::TimeTicks(); |
921 response_cookies_.clear(); | 925 response_cookies_.clear(); |
922 | 926 |
923 ResetTimer(); | 927 ResetTimer(); |
924 | 928 |
925 // Update the cookies, since the cookie store may have been updated from the | 929 // Update the cookies, since the cookie store may have been updated from the |
926 // headers in the 401/407. Since cookies were already appended to | 930 // headers in the 401/407. Since cookies were already appended to |
927 // extra_headers, we need to strip them out before adding them again. | 931 // extra_headers, we need to strip them out before adding them again. |
928 request_info_.extra_headers.RemoveHeader(HttpRequestHeaders::kCookie); | 932 request_info_.extra_headers.RemoveHeader(HttpRequestHeaders::kCookie); |
929 | 933 |
930 AddCookieHeaderAndStart(); | 934 AddCookieHeaderAndStart(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 | 979 |
976 if (response_info_) { | 980 if (response_info_) { |
977 *info = *response_info_; | 981 *info = *response_info_; |
978 if (override_response_headers_) | 982 if (override_response_headers_) |
979 info->headers = override_response_headers_; | 983 info->headers = override_response_headers_; |
980 } | 984 } |
981 } | 985 } |
982 | 986 |
983 void URLRequestHttpJob::GetLoadTimingInfo( | 987 void URLRequestHttpJob::GetLoadTimingInfo( |
984 LoadTimingInfo* load_timing_info) const { | 988 LoadTimingInfo* load_timing_info) const { |
985 if (transaction_) | 989 // If haven't made it far enough to receive any headers, don't return |
986 transaction_->GetLoadTimingInfo(load_timing_info); | 990 // anything. This makes for more consistent behavior in the case of errors. |
| 991 if (!transaction_ || receive_headers_end_.is_null()) |
| 992 return; |
| 993 if (transaction_->GetLoadTimingInfo(load_timing_info)) |
| 994 load_timing_info->receive_headers_end = receive_headers_end_; |
987 } | 995 } |
988 | 996 |
989 bool URLRequestHttpJob::GetResponseCookies(std::vector<std::string>* cookies) { | 997 bool URLRequestHttpJob::GetResponseCookies(std::vector<std::string>* cookies) { |
990 DCHECK(transaction_.get()); | 998 DCHECK(transaction_.get()); |
991 | 999 |
992 if (!response_info_) | 1000 if (!response_info_) |
993 return false; | 1001 return false; |
994 | 1002 |
995 // TODO(darin): Why are we extracting response cookies again? Perhaps we | 1003 // TODO(darin): Why are we extracting response cookies again? Perhaps we |
996 // should just leverage response_cookies_. | 1004 // should just leverage response_cookies_. |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1117 // Proxy gets set first, then WWW. | 1125 // Proxy gets set first, then WWW. |
1118 if (proxy_auth_state_ == AUTH_STATE_NEED_AUTH) { | 1126 if (proxy_auth_state_ == AUTH_STATE_NEED_AUTH) { |
1119 proxy_auth_state_ = AUTH_STATE_CANCELED; | 1127 proxy_auth_state_ = AUTH_STATE_CANCELED; |
1120 } else { | 1128 } else { |
1121 DCHECK_EQ(server_auth_state_, AUTH_STATE_NEED_AUTH); | 1129 DCHECK_EQ(server_auth_state_, AUTH_STATE_NEED_AUTH); |
1122 server_auth_state_ = AUTH_STATE_CANCELED; | 1130 server_auth_state_ = AUTH_STATE_CANCELED; |
1123 } | 1131 } |
1124 | 1132 |
1125 // These will be reset in OnStartCompleted. | 1133 // These will be reset in OnStartCompleted. |
1126 response_info_ = NULL; | 1134 response_info_ = NULL; |
| 1135 receive_headers_end_ = base::TimeTicks::Now(); |
1127 response_cookies_.clear(); | 1136 response_cookies_.clear(); |
1128 | 1137 |
1129 ResetTimer(); | 1138 ResetTimer(); |
1130 | 1139 |
1131 // OK, let the consumer read the error page... | 1140 // OK, let the consumer read the error page... |
1132 // | 1141 // |
1133 // Because we set the AUTH_STATE_CANCELED flag, NeedsAuth will return false, | 1142 // Because we set the AUTH_STATE_CANCELED flag, NeedsAuth will return false, |
1134 // which will cause the consumer to receive OnResponseStarted instead of | 1143 // which will cause the consumer to receive OnResponseStarted instead of |
1135 // OnAuthRequired. | 1144 // OnAuthRequired. |
1136 // | 1145 // |
1137 // We have to do this via InvokeLater to avoid "recursing" the consumer. | 1146 // We have to do this via InvokeLater to avoid "recursing" the consumer. |
1138 // | 1147 // |
1139 MessageLoop::current()->PostTask( | 1148 MessageLoop::current()->PostTask( |
1140 FROM_HERE, | 1149 FROM_HERE, |
1141 base::Bind(&URLRequestHttpJob::OnStartCompleted, | 1150 base::Bind(&URLRequestHttpJob::OnStartCompleted, |
1142 weak_factory_.GetWeakPtr(), OK)); | 1151 weak_factory_.GetWeakPtr(), OK)); |
1143 } | 1152 } |
1144 | 1153 |
1145 void URLRequestHttpJob::ContinueWithCertificate( | 1154 void URLRequestHttpJob::ContinueWithCertificate( |
1146 X509Certificate* client_cert) { | 1155 X509Certificate* client_cert) { |
1147 DCHECK(transaction_.get()); | 1156 DCHECK(transaction_.get()); |
1148 | 1157 |
1149 DCHECK(!response_info_) << "should not have a response yet"; | 1158 DCHECK(!response_info_) << "should not have a response yet"; |
| 1159 receive_headers_end_ = base::TimeTicks(); |
1150 | 1160 |
1151 ResetTimer(); | 1161 ResetTimer(); |
1152 | 1162 |
1153 // No matter what, we want to report our status as IO pending since we will | 1163 // No matter what, we want to report our status as IO pending since we will |
1154 // be notifying our consumer asynchronously via OnStartCompleted. | 1164 // be notifying our consumer asynchronously via OnStartCompleted. |
1155 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 1165 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
1156 | 1166 |
1157 int rv = transaction_->RestartWithCertificate(client_cert, start_callback_); | 1167 int rv = transaction_->RestartWithCertificate(client_cert, start_callback_); |
1158 if (rv == ERR_IO_PENDING) | 1168 if (rv == ERR_IO_PENDING) |
1159 return; | 1169 return; |
1160 | 1170 |
1161 // The transaction started synchronously, but we need to notify the | 1171 // The transaction started synchronously, but we need to notify the |
1162 // URLRequest delegate via the message loop. | 1172 // URLRequest delegate via the message loop. |
1163 MessageLoop::current()->PostTask( | 1173 MessageLoop::current()->PostTask( |
1164 FROM_HERE, | 1174 FROM_HERE, |
1165 base::Bind(&URLRequestHttpJob::OnStartCompleted, | 1175 base::Bind(&URLRequestHttpJob::OnStartCompleted, |
1166 weak_factory_.GetWeakPtr(), rv)); | 1176 weak_factory_.GetWeakPtr(), rv)); |
1167 } | 1177 } |
1168 | 1178 |
1169 void URLRequestHttpJob::ContinueDespiteLastError() { | 1179 void URLRequestHttpJob::ContinueDespiteLastError() { |
1170 // If the transaction was destroyed, then the job was cancelled. | 1180 // If the transaction was destroyed, then the job was cancelled. |
1171 if (!transaction_.get()) | 1181 if (!transaction_.get()) |
1172 return; | 1182 return; |
1173 | 1183 |
1174 DCHECK(!response_info_) << "should not have a response yet"; | 1184 DCHECK(!response_info_) << "should not have a response yet"; |
| 1185 receive_headers_end_ = base::TimeTicks(); |
1175 | 1186 |
1176 ResetTimer(); | 1187 ResetTimer(); |
1177 | 1188 |
1178 // No matter what, we want to report our status as IO pending since we will | 1189 // No matter what, we want to report our status as IO pending since we will |
1179 // be notifying our consumer asynchronously via OnStartCompleted. | 1190 // be notifying our consumer asynchronously via OnStartCompleted. |
1180 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 1191 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
1181 | 1192 |
1182 int rv = transaction_->RestartIgnoringLastError(start_callback_); | 1193 int rv = transaction_->RestartIgnoringLastError(start_callback_); |
1183 if (rv == ERR_IO_PENDING) | 1194 if (rv == ERR_IO_PENDING) |
1184 return; | 1195 return; |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1462 | 1473 |
1463 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1474 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
1464 awaiting_callback_ = false; | 1475 awaiting_callback_ = false; |
1465 } | 1476 } |
1466 | 1477 |
1467 void URLRequestHttpJob::OnDetachRequest() { | 1478 void URLRequestHttpJob::OnDetachRequest() { |
1468 http_transaction_delegate_->OnDetachRequest(); | 1479 http_transaction_delegate_->OnDetachRequest(); |
1469 } | 1480 } |
1470 | 1481 |
1471 } // namespace net | 1482 } // namespace net |
OLD | NEW |