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

Side by Side Diff: net/http/http_network_transaction.cc

Issue 10829188: Use net::UploadDataStream::Init() instead of InitSync() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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/http/http_network_transaction.h ('k') | no next file » | 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/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/bind.h" 10 #include "base/bind.h"
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 case STATE_GENERATE_PROXY_AUTH_TOKEN_COMPLETE: 527 case STATE_GENERATE_PROXY_AUTH_TOKEN_COMPLETE:
528 rv = DoGenerateProxyAuthTokenComplete(rv); 528 rv = DoGenerateProxyAuthTokenComplete(rv);
529 break; 529 break;
530 case STATE_GENERATE_SERVER_AUTH_TOKEN: 530 case STATE_GENERATE_SERVER_AUTH_TOKEN:
531 DCHECK_EQ(OK, rv); 531 DCHECK_EQ(OK, rv);
532 rv = DoGenerateServerAuthToken(); 532 rv = DoGenerateServerAuthToken();
533 break; 533 break;
534 case STATE_GENERATE_SERVER_AUTH_TOKEN_COMPLETE: 534 case STATE_GENERATE_SERVER_AUTH_TOKEN_COMPLETE:
535 rv = DoGenerateServerAuthTokenComplete(rv); 535 rv = DoGenerateServerAuthTokenComplete(rv);
536 break; 536 break;
537 case STATE_INIT_REQUEST_BODY:
538 DCHECK_EQ(OK, rv);
539 rv = DoInitRequestBody();
540 break;
541 case STATE_INIT_REQUEST_BODY_COMPLETE:
542 rv = DoInitRequestBodyComplete(rv);
543 break;
537 case STATE_BUILD_REQUEST: 544 case STATE_BUILD_REQUEST:
538 DCHECK_EQ(OK, rv); 545 DCHECK_EQ(OK, rv);
539 net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST); 546 net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST);
540 rv = DoBuildRequest(); 547 rv = DoBuildRequest();
541 break; 548 break;
542 case STATE_BUILD_REQUEST_COMPLETE: 549 case STATE_BUILD_REQUEST_COMPLETE:
543 rv = DoBuildRequestComplete(rv); 550 rv = DoBuildRequestComplete(rv);
544 break; 551 break;
545 case STATE_SEND_REQUEST: 552 case STATE_SEND_REQUEST:
546 DCHECK_EQ(OK, rv); 553 DCHECK_EQ(OK, rv);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 if (!ShouldApplyServerAuth()) 689 if (!ShouldApplyServerAuth())
683 return OK; 690 return OK;
684 return auth_controllers_[target]->MaybeGenerateAuthToken(request_, 691 return auth_controllers_[target]->MaybeGenerateAuthToken(request_,
685 io_callback_, 692 io_callback_,
686 net_log_); 693 net_log_);
687 } 694 }
688 695
689 int HttpNetworkTransaction::DoGenerateServerAuthTokenComplete(int rv) { 696 int HttpNetworkTransaction::DoGenerateServerAuthTokenComplete(int rv) {
690 DCHECK_NE(ERR_IO_PENDING, rv); 697 DCHECK_NE(ERR_IO_PENDING, rv);
691 if (rv == OK) 698 if (rv == OK)
692 next_state_ = STATE_BUILD_REQUEST; 699 next_state_ = STATE_INIT_REQUEST_BODY;
693 return rv; 700 return rv;
694 } 701 }
695 702
696 void HttpNetworkTransaction::BuildRequestHeaders(bool using_proxy) { 703 void HttpNetworkTransaction::BuildRequestHeaders(bool using_proxy) {
697 request_headers_.SetHeader(HttpRequestHeaders::kHost, 704 request_headers_.SetHeader(HttpRequestHeaders::kHost,
698 GetHostAndOptionalPort(request_->url)); 705 GetHostAndOptionalPort(request_->url));
699 706
700 // For compat with HTTP/1.0 servers and proxies: 707 // For compat with HTTP/1.0 servers and proxies:
701 if (using_proxy) { 708 if (using_proxy) {
702 request_headers_.SetHeader(HttpRequestHeaders::kProxyConnection, 709 request_headers_.SetHeader(HttpRequestHeaders::kProxyConnection,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 if (ShouldApplyProxyAuth() && HaveAuth(HttpAuth::AUTH_PROXY)) 742 if (ShouldApplyProxyAuth() && HaveAuth(HttpAuth::AUTH_PROXY))
736 auth_controllers_[HttpAuth::AUTH_PROXY]->AddAuthorizationHeader( 743 auth_controllers_[HttpAuth::AUTH_PROXY]->AddAuthorizationHeader(
737 &request_headers_); 744 &request_headers_);
738 if (ShouldApplyServerAuth() && HaveAuth(HttpAuth::AUTH_SERVER)) 745 if (ShouldApplyServerAuth() && HaveAuth(HttpAuth::AUTH_SERVER))
739 auth_controllers_[HttpAuth::AUTH_SERVER]->AddAuthorizationHeader( 746 auth_controllers_[HttpAuth::AUTH_SERVER]->AddAuthorizationHeader(
740 &request_headers_); 747 &request_headers_);
741 748
742 request_headers_.MergeFrom(request_->extra_headers); 749 request_headers_.MergeFrom(request_->extra_headers);
743 } 750 }
744 751
752 int HttpNetworkTransaction::DoInitRequestBody() {
753 next_state_ = STATE_INIT_REQUEST_BODY_COMPLETE;
754 request_body_.reset(NULL);
755 int error_code = OK;
eroman 2012/08/08 19:06:01 nit: for consistency you may want to call this |r
hashimoto 2012/08/09 04:35:20 Done.
756 if (request_->upload_data) {
757 request_body_.reset(new UploadDataStream(request_->upload_data));
758 error_code = request_body_->Init(io_callback_);
759 if (error_code != OK && error_code != ERR_IO_PENDING)
760 request_body_.reset(NULL);
eroman 2012/08/08 19:06:01 You can remove this: it will already be reset by D
hashimoto 2012/08/09 04:35:20 Done.
761 }
762 return error_code;
763 }
764
765 int HttpNetworkTransaction::DoInitRequestBodyComplete(int result) {
766 if (result == OK)
767 next_state_ = STATE_BUILD_REQUEST;
768 else
769 request_body_.reset(NULL);
770 return result;
771 }
772
745 int HttpNetworkTransaction::DoBuildRequest() { 773 int HttpNetworkTransaction::DoBuildRequest() {
746 next_state_ = STATE_BUILD_REQUEST_COMPLETE; 774 next_state_ = STATE_BUILD_REQUEST_COMPLETE;
747 request_body_.reset(NULL);
748 if (request_->upload_data) {
749 request_body_.reset(new UploadDataStream(request_->upload_data));
750 const int error_code = request_body_->InitSync();
751 if (error_code != OK) {
752 request_body_.reset(NULL);
753 return error_code;
754 }
755 }
756
757 headers_valid_ = false; 775 headers_valid_ = false;
758 776
759 // This is constructed lazily (instead of within our Start method), so that 777 // This is constructed lazily (instead of within our Start method), so that
760 // we have proxy info available. 778 // we have proxy info available.
761 if (request_headers_.IsEmpty()) { 779 if (request_headers_.IsEmpty()) {
762 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && 780 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) &&
763 !is_https_request(); 781 !is_https_request();
764 BuildRequestHeaders(using_proxy); 782 BuildRequestHeaders(using_proxy);
765 } 783 }
766 784
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 #define STATE_CASE(s) \ 1405 #define STATE_CASE(s) \
1388 case s: \ 1406 case s: \
1389 description = base::StringPrintf("%s (0x%08X)", #s, s); \ 1407 description = base::StringPrintf("%s (0x%08X)", #s, s); \
1390 break 1408 break
1391 1409
1392 std::string HttpNetworkTransaction::DescribeState(State state) { 1410 std::string HttpNetworkTransaction::DescribeState(State state) {
1393 std::string description; 1411 std::string description;
1394 switch (state) { 1412 switch (state) {
1395 STATE_CASE(STATE_CREATE_STREAM); 1413 STATE_CASE(STATE_CREATE_STREAM);
1396 STATE_CASE(STATE_CREATE_STREAM_COMPLETE); 1414 STATE_CASE(STATE_CREATE_STREAM_COMPLETE);
1415 STATE_CASE(STATE_INIT_REQUEST_BODY);
1416 STATE_CASE(STATE_INIT_REQUEST_BODY_COMPLETE);
1397 STATE_CASE(STATE_BUILD_REQUEST); 1417 STATE_CASE(STATE_BUILD_REQUEST);
1398 STATE_CASE(STATE_BUILD_REQUEST_COMPLETE); 1418 STATE_CASE(STATE_BUILD_REQUEST_COMPLETE);
1399 STATE_CASE(STATE_SEND_REQUEST); 1419 STATE_CASE(STATE_SEND_REQUEST);
1400 STATE_CASE(STATE_SEND_REQUEST_COMPLETE); 1420 STATE_CASE(STATE_SEND_REQUEST_COMPLETE);
1401 STATE_CASE(STATE_READ_HEADERS); 1421 STATE_CASE(STATE_READ_HEADERS);
1402 STATE_CASE(STATE_READ_HEADERS_COMPLETE); 1422 STATE_CASE(STATE_READ_HEADERS_COMPLETE);
1403 STATE_CASE(STATE_READ_BODY); 1423 STATE_CASE(STATE_READ_BODY);
1404 STATE_CASE(STATE_READ_BODY_COMPLETE); 1424 STATE_CASE(STATE_READ_BODY_COMPLETE);
1405 STATE_CASE(STATE_DRAIN_BODY_FOR_AUTH_RESTART); 1425 STATE_CASE(STATE_DRAIN_BODY_FOR_AUTH_RESTART);
1406 STATE_CASE(STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE); 1426 STATE_CASE(STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE);
1407 STATE_CASE(STATE_NONE); 1427 STATE_CASE(STATE_NONE);
1408 default: 1428 default:
1409 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, 1429 description = base::StringPrintf("Unknown state 0x%08X (%u)", state,
1410 state); 1430 state);
1411 break; 1431 break;
1412 } 1432 }
1413 return description; 1433 return description;
1414 } 1434 }
1415 1435
1416 #undef STATE_CASE 1436 #undef STATE_CASE
1417 1437
1418 } // namespace net 1438 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_transaction.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698