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 "net/spdy/spdy_http_stream.h" | 5 #include "net/spdy/spdy_http_stream.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <list> | 8 #include <list> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 void SpdyHttpStream::Cancel() { | 295 void SpdyHttpStream::Cancel() { |
| 296 request_callback_.Reset(); | 296 request_callback_.Reset(); |
| 297 response_callback_.Reset(); | 297 response_callback_.Reset(); |
| 298 if (stream_.get()) { | 298 if (stream_.get()) { |
| 299 stream_->Cancel(); | 299 stream_->Cancel(); |
| 300 DCHECK(!stream_.get()); | 300 DCHECK(!stream_.get()); |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 | 303 |
| 304 void SpdyHttpStream::OnRequestHeadersSent() { | 304 void SpdyHttpStream::OnRequestHeadersSent() { |
| 305 if (!request_callback_.is_null()) | 305 if (HasUploadData()) { |
| 306 DoRequestCallback(OK); | |
| 307 | |
| 308 // TODO(akalin): Do this immediately after sending the request | |
| 309 // headers. | |
| 310 if (HasUploadData()) | |
| 311 ReadAndSendRequestBodyData(); | 306 ReadAndSendRequestBodyData(); |
| 307 } else { | |
| 308 if (!request_callback_.is_null()) | |
| 309 DoRequestCallback(OK); | |
| 310 } | |
| 312 } | 311 } |
| 313 | 312 |
| 314 SpdyResponseHeadersStatus SpdyHttpStream::OnResponseHeadersUpdated( | 313 SpdyResponseHeadersStatus SpdyHttpStream::OnResponseHeadersUpdated( |
| 315 const SpdyHeaderBlock& response_headers) { | 314 const SpdyHeaderBlock& response_headers) { |
| 316 CHECK_EQ(response_headers_status_, RESPONSE_HEADERS_ARE_INCOMPLETE); | 315 CHECK_EQ(response_headers_status_, RESPONSE_HEADERS_ARE_INCOMPLETE); |
| 317 | 316 |
| 318 if (!response_info_) { | 317 if (!response_info_) { |
| 319 DCHECK_EQ(stream_->type(), SPDY_PUSH_STREAM); | 318 DCHECK_EQ(stream_->type(), SPDY_PUSH_STREAM); |
| 320 push_response_info_.reset(new HttpResponseInfo); | 319 push_response_info_.reset(new HttpResponseInfo); |
| 321 response_info_ = push_response_info_.get(); | 320 response_info_ = push_response_info_.get(); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 stream_ = stream_request_.ReleaseStream(); | 429 stream_ = stream_request_.ReleaseStream(); |
| 431 stream_->SetDelegate(this); | 430 stream_->SetDelegate(this); |
| 432 } | 431 } |
| 433 callback.Run(rv); | 432 callback.Run(rv); |
| 434 } | 433 } |
| 435 | 434 |
| 436 void SpdyHttpStream::ReadAndSendRequestBodyData() { | 435 void SpdyHttpStream::ReadAndSendRequestBodyData() { |
| 437 CHECK(HasUploadData()); | 436 CHECK(HasUploadData()); |
| 438 CHECK_EQ(request_body_buf_size_, 0); | 437 CHECK_EQ(request_body_buf_size_, 0); |
| 439 | 438 |
| 440 if (request_info_->upload_data_stream->IsEOF()) | 439 if (request_info_->upload_data_stream->IsEOF()) { |
| 440 // The cb should be null here, but it's better to be | |
| 441 // paranoid. | |
|
mmenke
2016/06/14 15:25:44
I don't believe this is true - when uploading chun
maksims (do not use this acc)
2016/06/15 07:51:45
Check the SendChunkedPostLastEmpty that I added. A
| |
| 442 if (!request_callback_.is_null()) { | |
| 443 DoRequestCallback(OK); | |
| 444 } | |
|
mmenke
2016/06/14 15:25:44
nit: Remove braces
| |
| 441 return; | 445 return; |
| 446 } | |
| 442 | 447 |
| 443 // Read the data from the request body stream. | 448 // Read the data from the request body stream. |
| 444 const int rv = request_info_->upload_data_stream | 449 const int rv = request_info_->upload_data_stream |
| 445 ->Read(request_body_buf_.get(), | 450 ->Read(request_body_buf_.get(), |
| 446 request_body_buf_->size(), | 451 request_body_buf_->size(), |
| 447 base::Bind(&SpdyHttpStream::OnRequestBodyReadCompleted, | 452 base::Bind(&SpdyHttpStream::OnRequestBodyReadCompleted, |
| 448 weak_factory_.GetWeakPtr())); | 453 weak_factory_.GetWeakPtr())); |
| 449 | 454 |
| 450 if (rv != ERR_IO_PENDING) { | 455 if (rv != ERR_IO_PENDING) { |
| 451 // ERR_IO_PENDING is the only possible error. | 456 // ERR_IO_PENDING is the only possible error. |
| 452 CHECK_GE(rv, 0); | 457 CHECK_GE(rv, 0); |
| 453 OnRequestBodyReadCompleted(rv); | 458 OnRequestBodyReadCompleted(rv); |
| 454 } | 459 } |
| 455 } | 460 } |
| 456 | 461 |
| 457 void SpdyHttpStream::OnRequestBodyReadCompleted(int status) { | 462 void SpdyHttpStream::OnRequestBodyReadCompleted(int status) { |
| 458 CHECK_GE(status, 0); | 463 CHECK_GE(status, 0); |
| 459 request_body_buf_size_ = status; | 464 request_body_buf_size_ = status; |
| 460 const bool eof = request_info_->upload_data_stream->IsEOF(); | 465 const bool eof = request_info_->upload_data_stream->IsEOF(); |
| 461 // Only the final fame may have a length of 0. | 466 // Only the final fame may have a length of 0. |
| 462 if (eof) { | 467 if (eof) { |
| 463 CHECK_GE(request_body_buf_size_, 0); | 468 CHECK_GE(request_body_buf_size_, 0); |
| 469 // Call the cb only after the whole data is sent. | |
|
mmenke
2016/06/14 15:25:44
nit: "after the whole file is sent." or "after al
maksims (do not use this acc)
2016/06/15 07:51:45
Done.
| |
| 470 if (!request_callback_.is_null()) { | |
| 471 DoRequestCallback(OK); | |
| 472 } | |
|
mmenke
2016/06/14 15:25:44
nit: Remove braces
maksims (do not use this acc)
2016/06/15 07:51:45
Done.
| |
| 464 } else { | 473 } else { |
| 465 CHECK_GT(request_body_buf_size_, 0); | 474 CHECK_GT(request_body_buf_size_, 0); |
| 466 } | 475 } |
| 467 stream_->SendData(request_body_buf_.get(), | 476 stream_->SendData(request_body_buf_.get(), |
| 468 request_body_buf_size_, | 477 request_body_buf_size_, |
| 469 eof ? NO_MORE_DATA_TO_SEND : MORE_DATA_TO_SEND); | 478 eof ? NO_MORE_DATA_TO_SEND : MORE_DATA_TO_SEND); |
| 470 } | 479 } |
| 471 | 480 |
| 472 void SpdyHttpStream::ScheduleBufferedReadCallback() { | 481 void SpdyHttpStream::ScheduleBufferedReadCallback() { |
| 473 // If there is already a scheduled DoBufferedReadCallback, don't issue | 482 // If there is already a scheduled DoBufferedReadCallback, don't issue |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 CHECK_NE(rv, ERR_IO_PENDING); | 535 CHECK_NE(rv, ERR_IO_PENDING); |
| 527 user_buffer_ = NULL; | 536 user_buffer_ = NULL; |
| 528 user_buffer_len_ = 0; | 537 user_buffer_len_ = 0; |
| 529 DoResponseCallback(rv); | 538 DoResponseCallback(rv); |
| 530 } | 539 } |
| 531 } | 540 } |
| 532 | 541 |
| 533 void SpdyHttpStream::DoRequestCallback(int rv) { | 542 void SpdyHttpStream::DoRequestCallback(int rv) { |
| 534 CHECK_NE(rv, ERR_IO_PENDING); | 543 CHECK_NE(rv, ERR_IO_PENDING); |
| 535 CHECK(!request_callback_.is_null()); | 544 CHECK(!request_callback_.is_null()); |
| 536 | |
| 537 // Since Run may result in being called back, reset request_callback_ in | 545 // Since Run may result in being called back, reset request_callback_ in |
| 538 // advance. | 546 // advance. |
| 539 base::ResetAndReturn(&request_callback_).Run(rv); | 547 base::ResetAndReturn(&request_callback_).Run(rv); |
| 540 } | 548 } |
| 541 | 549 |
| 542 void SpdyHttpStream::DoResponseCallback(int rv) { | 550 void SpdyHttpStream::DoResponseCallback(int rv) { |
| 543 CHECK_NE(rv, ERR_IO_PENDING); | 551 CHECK_NE(rv, ERR_IO_PENDING); |
| 544 CHECK(!response_callback_.is_null()); | 552 CHECK(!response_callback_.is_null()); |
| 545 | 553 |
| 546 // Since Run may result in being called back, reset response_callback_ in | 554 // Since Run may result in being called back, reset response_callback_ in |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 584 details->connection_info = HttpResponseInfo::CONNECTION_INFO_HTTP2; | 592 details->connection_info = HttpResponseInfo::CONNECTION_INFO_HTTP2; |
| 585 return; | 593 return; |
| 586 } | 594 } |
| 587 | 595 |
| 588 void SpdyHttpStream::SetPriority(RequestPriority priority) { | 596 void SpdyHttpStream::SetPriority(RequestPriority priority) { |
| 589 // TODO(akalin): Plumb this through to |stream_request_| and | 597 // TODO(akalin): Plumb this through to |stream_request_| and |
| 590 // |stream_|. | 598 // |stream_|. |
| 591 } | 599 } |
| 592 | 600 |
| 593 } // namespace net | 601 } // namespace net |
| OLD | NEW |