Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 } | 92 } |
| 93 | 93 |
| 94 } // namespace | 94 } // namespace |
| 95 | 95 |
| 96 //----------------------------------------------------------------------------- | 96 //----------------------------------------------------------------------------- |
| 97 | 97 |
| 98 HttpNetworkTransaction::HttpNetworkTransaction(HttpNetworkSession* session) | 98 HttpNetworkTransaction::HttpNetworkTransaction(HttpNetworkSession* session) |
| 99 : pending_auth_target_(HttpAuth::AUTH_NONE), | 99 : pending_auth_target_(HttpAuth::AUTH_NONE), |
| 100 ALLOW_THIS_IN_INITIALIZER_LIST( | 100 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 101 io_callback_(this, &HttpNetworkTransaction::OnIOComplete)), | 101 io_callback_(this, &HttpNetworkTransaction::OnIOComplete)), |
| 102 ALLOW_THIS_IN_INITIALIZER_LIST(delegate_callback_( | |
| 103 new CancelableCompletionCallback<HttpNetworkTransaction>( | |
| 104 this, &HttpNetworkTransaction::OnIOComplete))), | |
| 102 user_callback_(NULL), | 105 user_callback_(NULL), |
| 103 session_(session), | 106 session_(session), |
| 104 request_(NULL), | 107 request_(NULL), |
| 105 headers_valid_(false), | 108 headers_valid_(false), |
| 106 logged_response_time_(false), | 109 logged_response_time_(false), |
| 107 request_headers_(), | 110 request_headers_(), |
| 108 read_buf_len_(0), | 111 read_buf_len_(0), |
| 109 next_state_(STATE_NONE), | 112 next_state_(STATE_NONE), |
| 110 establishing_tunnel_(false) { | 113 establishing_tunnel_(false) { |
| 111 session->ssl_config_service()->GetSSLConfig(&ssl_config_); | 114 session->ssl_config_service()->GetSSLConfig(&ssl_config_); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 139 // HTTP, it can vary depending on whether or not we're pipelining. It's | 142 // HTTP, it can vary depending on whether or not we're pipelining. It's |
| 140 // stream dependent, so the different subtypes should be implementing | 143 // stream dependent, so the different subtypes should be implementing |
| 141 // their solutions. | 144 // their solutions. |
| 142 HttpResponseBodyDrainer* drainer = | 145 HttpResponseBodyDrainer* drainer = |
| 143 new HttpResponseBodyDrainer(stream_.release()); | 146 new HttpResponseBodyDrainer(stream_.release()); |
| 144 drainer->Start(session_); | 147 drainer->Start(session_); |
| 145 // |drainer| will delete itself. | 148 // |drainer| will delete itself. |
| 146 } | 149 } |
| 147 } | 150 } |
| 148 } | 151 } |
| 152 | |
| 153 delegate_callback_->Cancel(); | |
| 149 } | 154 } |
| 150 | 155 |
| 151 int HttpNetworkTransaction::Start(const HttpRequestInfo* request_info, | 156 int HttpNetworkTransaction::Start(const HttpRequestInfo* request_info, |
| 152 CompletionCallback* callback, | 157 CompletionCallback* callback, |
| 153 const BoundNetLog& net_log) { | 158 const BoundNetLog& net_log) { |
| 154 SIMPLE_STATS_COUNTER("HttpNetworkTransaction.Count"); | 159 SIMPLE_STATS_COUNTER("HttpNetworkTransaction.Count"); |
| 155 | 160 |
| 156 net_log_ = net_log; | 161 net_log_ = net_log; |
| 157 request_ = request_info; | 162 request_ = request_info; |
| 158 start_time_ = base::Time::Now(); | 163 start_time_ = base::Time::Now(); |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 507 case STATE_GENERATE_PROXY_AUTH_TOKEN_COMPLETE: | 512 case STATE_GENERATE_PROXY_AUTH_TOKEN_COMPLETE: |
| 508 rv = DoGenerateProxyAuthTokenComplete(rv); | 513 rv = DoGenerateProxyAuthTokenComplete(rv); |
| 509 break; | 514 break; |
| 510 case STATE_GENERATE_SERVER_AUTH_TOKEN: | 515 case STATE_GENERATE_SERVER_AUTH_TOKEN: |
| 511 DCHECK_EQ(OK, rv); | 516 DCHECK_EQ(OK, rv); |
| 512 rv = DoGenerateServerAuthToken(); | 517 rv = DoGenerateServerAuthToken(); |
| 513 break; | 518 break; |
| 514 case STATE_GENERATE_SERVER_AUTH_TOKEN_COMPLETE: | 519 case STATE_GENERATE_SERVER_AUTH_TOKEN_COMPLETE: |
| 515 rv = DoGenerateServerAuthTokenComplete(rv); | 520 rv = DoGenerateServerAuthTokenComplete(rv); |
| 516 break; | 521 break; |
| 517 case STATE_SEND_REQUEST: | 522 case STATE_BUILD_REQUEST: |
| 518 DCHECK_EQ(OK, rv); | 523 DCHECK_EQ(OK, rv); |
| 519 net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, NULL); | 524 net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, NULL); |
| 520 rv = DoSendRequest(); | 525 rv = DoBuildRequest(); |
| 526 break; | |
| 527 case STATE_BUILD_REQUEST_COMPLETE: | |
| 528 rv = DoBuildRequestComplete(rv); | |
| 529 break; | |
| 530 case STATE_SEND_REQUEST: | |
| 531 rv = DoSendRequest(rv); | |
| 521 break; | 532 break; |
| 522 case STATE_SEND_REQUEST_COMPLETE: | 533 case STATE_SEND_REQUEST_COMPLETE: |
| 523 rv = DoSendRequestComplete(rv); | 534 rv = DoSendRequestComplete(rv); |
| 524 net_log_.EndEventWithNetErrorCode( | 535 net_log_.EndEventWithNetErrorCode( |
| 525 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, rv); | 536 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, rv); |
| 526 break; | 537 break; |
| 527 case STATE_READ_HEADERS: | 538 case STATE_READ_HEADERS: |
| 528 DCHECK_EQ(OK, rv); | 539 DCHECK_EQ(OK, rv); |
| 529 net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, NULL); | 540 net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, NULL); |
| 530 rv = DoReadHeaders(); | 541 rv = DoReadHeaders(); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 654 if (!ShouldApplyServerAuth()) | 665 if (!ShouldApplyServerAuth()) |
| 655 return OK; | 666 return OK; |
| 656 return auth_controllers_[target]->MaybeGenerateAuthToken(request_, | 667 return auth_controllers_[target]->MaybeGenerateAuthToken(request_, |
| 657 &io_callback_, | 668 &io_callback_, |
| 658 net_log_); | 669 net_log_); |
| 659 } | 670 } |
| 660 | 671 |
| 661 int HttpNetworkTransaction::DoGenerateServerAuthTokenComplete(int rv) { | 672 int HttpNetworkTransaction::DoGenerateServerAuthTokenComplete(int rv) { |
| 662 DCHECK_NE(ERR_IO_PENDING, rv); | 673 DCHECK_NE(ERR_IO_PENDING, rv); |
| 663 if (rv == OK) | 674 if (rv == OK) |
| 664 next_state_ = STATE_SEND_REQUEST; | 675 next_state_ = STATE_BUILD_REQUEST; |
| 665 return rv; | 676 return rv; |
| 666 } | 677 } |
| 667 | 678 |
| 668 int HttpNetworkTransaction::DoSendRequest() { | 679 int HttpNetworkTransaction::DoBuildRequest() { |
| 669 next_state_ = STATE_SEND_REQUEST_COMPLETE; | 680 next_state_ = STATE_BUILD_REQUEST_COMPLETE; |
| 670 | 681 |
| 671 UploadDataStream* request_body = NULL; | 682 request_body_.reset(NULL); |
| 672 if (request_->upload_data) { | 683 if (request_->upload_data) { |
| 673 int error_code; | 684 int error_code; |
| 674 request_body = UploadDataStream::Create(request_->upload_data, &error_code); | 685 request_body_.reset( |
| 675 if (!request_body) | 686 UploadDataStream::Create(request_->upload_data, &error_code)); |
| 687 if (!request_body_.get()) | |
| 676 return error_code; | 688 return error_code; |
| 677 } | 689 } |
| 678 | 690 |
| 691 headers_valid_ = false; | |
| 692 | |
| 679 // This is constructed lazily (instead of within our Start method), so that | 693 // This is constructed lazily (instead of within our Start method), so that |
| 680 // we have proxy info available. | 694 // we have proxy info available. |
| 681 if (request_headers_.IsEmpty()) { | 695 if (request_headers_.IsEmpty()) { |
| 682 bool using_proxy = (proxy_info_.is_http()|| proxy_info_.is_https()) && | 696 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && |
| 683 !is_https_request(); | 697 !is_https_request(); |
| 684 HttpUtil::BuildRequestHeaders(request_, request_body, auth_controllers_, | 698 HttpUtil::BuildRequestHeaders(request_, request_body_.get(), |
| 699 auth_controllers_, | |
| 685 ShouldApplyServerAuth(), | 700 ShouldApplyServerAuth(), |
| 686 ShouldApplyProxyAuth(), using_proxy, | 701 ShouldApplyProxyAuth(), using_proxy, |
| 687 &request_headers_); | 702 &request_headers_); |
| 688 | |
| 689 if (session_->network_delegate()) | |
| 690 session_->network_delegate()->NotifySendHttpRequest(&request_headers_); | |
| 691 } | 703 } |
| 692 | 704 |
| 693 headers_valid_ = false; | 705 return OK; |
| 694 return stream_->SendRequest(request_headers_, request_body, &response_, | 706 } |
| 695 &io_callback_); | 707 |
| 708 int HttpNetworkTransaction::DoBuildRequestComplete(int result) { | |
|
willchan no longer on Chromium
2011/03/22 23:05:35
Sorry for nitpicking like this, but to make it mor
Matt Perry
2011/03/24 00:11:25
Done. Though now I notice that delegate_callback_
willchan no longer on Chromium
2011/03/26 01:46:49
I think maybe you want to only create the delegate
Matt Perry
2011/03/28 22:51:01
Any reason to prefer doing it that way as opposed
willchan no longer on Chromium
2011/03/29 20:46:27
I don't know that this is possible today, but let'
| |
| 709 next_state_ = STATE_SEND_REQUEST; | |
| 710 delegate_callback_->AddRef(); // balanced in DoSendRequest | |
| 711 | |
| 712 if (session_->network_delegate()) { | |
| 713 if (session_->network_delegate()->NotifyBeforeSendHeaders( | |
| 714 request_->request_id, &request_headers_, delegate_callback_)) | |
| 715 return ERR_IO_PENDING; | |
| 716 } | |
| 717 | |
| 718 return OK; | |
| 719 } | |
| 720 | |
| 721 int HttpNetworkTransaction::DoSendRequest(int result) { | |
| 722 next_state_ = STATE_SEND_REQUEST_COMPLETE; | |
| 723 delegate_callback_->Release(); // balanced in DoBuildRequestComplete | |
| 724 | |
| 725 if (result == net::OK) { | |
| 726 return stream_->SendRequest( | |
| 727 request_headers_, request_body_.release(), &response_, &io_callback_); | |
| 728 } | |
| 729 return result; | |
| 696 } | 730 } |
| 697 | 731 |
| 698 int HttpNetworkTransaction::DoSendRequestComplete(int result) { | 732 int HttpNetworkTransaction::DoSendRequestComplete(int result) { |
| 699 if (result < 0) | 733 if (result < 0) |
| 700 return HandleIOError(result); | 734 return HandleIOError(result); |
| 701 next_state_ = STATE_READ_HEADERS; | 735 next_state_ = STATE_READ_HEADERS; |
| 702 return OK; | 736 return OK; |
| 703 } | 737 } |
| 704 | 738 |
| 705 int HttpNetworkTransaction::DoReadHeaders() { | 739 int HttpNetworkTransaction::DoReadHeaders() { |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1113 case ERR_CONNECTION_ABORTED: | 1147 case ERR_CONNECTION_ABORTED: |
| 1114 if (ShouldResendRequest(error)) { | 1148 if (ShouldResendRequest(error)) { |
| 1115 ResetConnectionAndRequestForResend(); | 1149 ResetConnectionAndRequestForResend(); |
| 1116 error = OK; | 1150 error = OK; |
| 1117 } | 1151 } |
| 1118 break; | 1152 break; |
| 1119 } | 1153 } |
| 1120 return error; | 1154 return error; |
| 1121 } | 1155 } |
| 1122 | 1156 |
| 1123 void HttpNetworkTransaction::ResetStateForRestart() { | 1157 void HttpNetworkTransaction::ResetStateForRestart() { |
|
willchan no longer on Chromium
2011/03/22 23:05:35
This is the core place where all state gets reset
Matt Perry
2011/03/24 00:11:25
Mark it how?
willchan no longer on Chromium
2011/03/26 01:46:49
Note that we will "restart" a transaction for auth
Matt Perry
2011/03/28 22:51:01
Oh I see now. FWIW, OnBeforeSendHeaders will be ca
willchan no longer on Chromium
2011/03/29 20:46:27
OIC, ok!
| |
| 1124 ResetStateForAuthRestart(); | 1158 ResetStateForAuthRestart(); |
| 1125 stream_.reset(); | 1159 stream_.reset(); |
| 1126 } | 1160 } |
| 1127 | 1161 |
| 1128 void HttpNetworkTransaction::ResetStateForAuthRestart() { | 1162 void HttpNetworkTransaction::ResetStateForAuthRestart() { |
| 1129 pending_auth_target_ = HttpAuth::AUTH_NONE; | 1163 pending_auth_target_ = HttpAuth::AUTH_NONE; |
| 1130 read_buf_ = NULL; | 1164 read_buf_ = NULL; |
| 1131 read_buf_len_ = 0; | 1165 read_buf_len_ = 0; |
| 1132 headers_valid_ = false; | 1166 headers_valid_ = false; |
| 1133 request_headers_.Clear(); | 1167 request_headers_.Clear(); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1231 #define STATE_CASE(s) \ | 1265 #define STATE_CASE(s) \ |
| 1232 case s: \ | 1266 case s: \ |
| 1233 description = base::StringPrintf("%s (0x%08X)", #s, s); \ | 1267 description = base::StringPrintf("%s (0x%08X)", #s, s); \ |
| 1234 break | 1268 break |
| 1235 | 1269 |
| 1236 std::string HttpNetworkTransaction::DescribeState(State state) { | 1270 std::string HttpNetworkTransaction::DescribeState(State state) { |
| 1237 std::string description; | 1271 std::string description; |
| 1238 switch (state) { | 1272 switch (state) { |
| 1239 STATE_CASE(STATE_CREATE_STREAM); | 1273 STATE_CASE(STATE_CREATE_STREAM); |
| 1240 STATE_CASE(STATE_CREATE_STREAM_COMPLETE); | 1274 STATE_CASE(STATE_CREATE_STREAM_COMPLETE); |
| 1275 STATE_CASE(STATE_BUILD_REQUEST); | |
| 1276 STATE_CASE(STATE_BUILD_REQUEST_COMPLETE); | |
| 1241 STATE_CASE(STATE_SEND_REQUEST); | 1277 STATE_CASE(STATE_SEND_REQUEST); |
| 1242 STATE_CASE(STATE_SEND_REQUEST_COMPLETE); | 1278 STATE_CASE(STATE_SEND_REQUEST_COMPLETE); |
| 1243 STATE_CASE(STATE_READ_HEADERS); | 1279 STATE_CASE(STATE_READ_HEADERS); |
| 1244 STATE_CASE(STATE_READ_HEADERS_COMPLETE); | 1280 STATE_CASE(STATE_READ_HEADERS_COMPLETE); |
| 1245 STATE_CASE(STATE_READ_BODY); | 1281 STATE_CASE(STATE_READ_BODY); |
| 1246 STATE_CASE(STATE_READ_BODY_COMPLETE); | 1282 STATE_CASE(STATE_READ_BODY_COMPLETE); |
| 1247 STATE_CASE(STATE_DRAIN_BODY_FOR_AUTH_RESTART); | 1283 STATE_CASE(STATE_DRAIN_BODY_FOR_AUTH_RESTART); |
| 1248 STATE_CASE(STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE); | 1284 STATE_CASE(STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE); |
| 1249 STATE_CASE(STATE_NONE); | 1285 STATE_CASE(STATE_NONE); |
| 1250 default: | 1286 default: |
| 1251 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, | 1287 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, |
| 1252 state); | 1288 state); |
| 1253 break; | 1289 break; |
| 1254 } | 1290 } |
| 1255 return description; | 1291 return description; |
| 1256 } | 1292 } |
| 1257 | 1293 |
| 1258 #undef STATE_CASE | 1294 #undef STATE_CASE |
| 1259 | 1295 |
| 1260 } // namespace net | 1296 } // namespace net |
| OLD | NEW |