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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 if (rv == OK) { | 428 if (rv == OK) { |
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 if (request_info_->upload_data_stream->IsEOF()) { |
440 if (request_info_->upload_data_stream->IsEOF()) | 439 if (!request_callback_.is_null()) { |
440 // Temporary for the review. | |
441 // Never called!!! | |
mmenke
2016/06/15 16:15:18
What if we have a chunked upload with no data? - i
maksims (do not use this acc)
2016/06/16 05:12:46
Nope, check the SendChunkedPostLastEmpty unit test
maksims (do not use this acc)
2016/06/16 05:28:08
And we know about the eof only after upload_data_s
maksims (do not use this acc)
2016/06/16 06:52:28
And I guess the only way to envoke the first eof i
| |
442 DCHECK(false); | |
443 DoRequestCallback(OK); | |
444 } | |
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 all data is sent. | |
470 if (!request_callback_.is_null()) | |
471 DoRequestCallback(OK); | |
464 } else { | 472 } else { |
465 CHECK_GT(request_body_buf_size_, 0); | 473 CHECK_GT(request_body_buf_size_, 0); |
466 } | 474 } |
467 stream_->SendData(request_body_buf_.get(), | 475 stream_->SendData(request_body_buf_.get(), |
468 request_body_buf_size_, | 476 request_body_buf_size_, |
469 eof ? NO_MORE_DATA_TO_SEND : MORE_DATA_TO_SEND); | 477 eof ? NO_MORE_DATA_TO_SEND : MORE_DATA_TO_SEND); |
470 } | 478 } |
471 | 479 |
472 void SpdyHttpStream::ScheduleBufferedReadCallback() { | 480 void SpdyHttpStream::ScheduleBufferedReadCallback() { |
473 // If there is already a scheduled DoBufferedReadCallback, don't issue | 481 // 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); | 534 CHECK_NE(rv, ERR_IO_PENDING); |
527 user_buffer_ = NULL; | 535 user_buffer_ = NULL; |
528 user_buffer_len_ = 0; | 536 user_buffer_len_ = 0; |
529 DoResponseCallback(rv); | 537 DoResponseCallback(rv); |
530 } | 538 } |
531 } | 539 } |
532 | 540 |
533 void SpdyHttpStream::DoRequestCallback(int rv) { | 541 void SpdyHttpStream::DoRequestCallback(int rv) { |
534 CHECK_NE(rv, ERR_IO_PENDING); | 542 CHECK_NE(rv, ERR_IO_PENDING); |
535 CHECK(!request_callback_.is_null()); | 543 CHECK(!request_callback_.is_null()); |
536 | |
537 // Since Run may result in being called back, reset request_callback_ in | 544 // Since Run may result in being called back, reset request_callback_ in |
538 // advance. | 545 // advance. |
539 base::ResetAndReturn(&request_callback_).Run(rv); | 546 base::ResetAndReturn(&request_callback_).Run(rv); |
540 } | 547 } |
541 | 548 |
542 void SpdyHttpStream::DoResponseCallback(int rv) { | 549 void SpdyHttpStream::DoResponseCallback(int rv) { |
543 CHECK_NE(rv, ERR_IO_PENDING); | 550 CHECK_NE(rv, ERR_IO_PENDING); |
544 CHECK(!response_callback_.is_null()); | 551 CHECK(!response_callback_.is_null()); |
545 | 552 |
546 // Since Run may result in being called back, reset response_callback_ in | 553 // 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; | 591 details->connection_info = HttpResponseInfo::CONNECTION_INFO_HTTP2; |
585 return; | 592 return; |
586 } | 593 } |
587 | 594 |
588 void SpdyHttpStream::SetPriority(RequestPriority priority) { | 595 void SpdyHttpStream::SetPriority(RequestPriority priority) { |
589 // TODO(akalin): Plumb this through to |stream_request_| and | 596 // TODO(akalin): Plumb this through to |stream_request_| and |
590 // |stream_|. | 597 // |stream_|. |
591 } | 598 } |
592 | 599 |
593 } // namespace net | 600 } // namespace net |
OLD | NEW |