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 // TODO(akalin): Do this immediately after sending the request |
| 306 // headers. |
| 307 if (HasUploadData()) { |
| 308 ReadAndSendRequestBodyData(); |
| 309 return; |
| 310 } |
| 311 |
305 if (!request_callback_.is_null()) | 312 if (!request_callback_.is_null()) |
306 DoRequestCallback(OK); | 313 DoRequestCallback(OK); |
307 | |
308 // TODO(akalin): Do this immediately after sending the request | |
309 // headers. | |
310 if (HasUploadData()) | |
311 ReadAndSendRequestBodyData(); | |
312 } | 314 } |
313 | 315 |
314 SpdyResponseHeadersStatus SpdyHttpStream::OnResponseHeadersUpdated( | 316 SpdyResponseHeadersStatus SpdyHttpStream::OnResponseHeadersUpdated( |
315 const SpdyHeaderBlock& response_headers) { | 317 const SpdyHeaderBlock& response_headers) { |
316 CHECK_EQ(response_headers_status_, RESPONSE_HEADERS_ARE_INCOMPLETE); | 318 CHECK_EQ(response_headers_status_, RESPONSE_HEADERS_ARE_INCOMPLETE); |
317 | 319 |
318 if (!response_info_) { | 320 if (!response_info_) { |
319 DCHECK_EQ(stream_->type(), SPDY_PUSH_STREAM); | 321 DCHECK_EQ(stream_->type(), SPDY_PUSH_STREAM); |
320 push_response_info_.reset(new HttpResponseInfo); | 322 push_response_info_.reset(new HttpResponseInfo); |
321 response_info_ = push_response_info_.get(); | 323 response_info_ = push_response_info_.get(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 return; | 443 return; |
442 | 444 |
443 // Read the data from the request body stream. | 445 // Read the data from the request body stream. |
444 const int rv = request_info_->upload_data_stream | 446 const int rv = request_info_->upload_data_stream |
445 ->Read(request_body_buf_.get(), | 447 ->Read(request_body_buf_.get(), |
446 request_body_buf_->size(), | 448 request_body_buf_->size(), |
447 base::Bind(&SpdyHttpStream::OnRequestBodyReadCompleted, | 449 base::Bind(&SpdyHttpStream::OnRequestBodyReadCompleted, |
448 weak_factory_.GetWeakPtr())); | 450 weak_factory_.GetWeakPtr())); |
449 | 451 |
450 if (rv != ERR_IO_PENDING) { | 452 if (rv != ERR_IO_PENDING) { |
451 // ERR_IO_PENDING is the only possible error. | 453 // UploadDataStream::Read() can fail reading data |
452 CHECK_GE(rv, 0); | |
453 OnRequestBodyReadCompleted(rv); | 454 OnRequestBodyReadCompleted(rv); |
454 } | 455 } |
455 } | 456 } |
456 | 457 |
| 458 void SpdyHttpStream::ResetStreamInternal() { |
| 459 spdy_session_->ResetStream(stream()->stream_id(), RST_STREAM_INTERNAL_ERROR, |
| 460 std::string()); |
| 461 } |
| 462 |
457 void SpdyHttpStream::OnRequestBodyReadCompleted(int status) { | 463 void SpdyHttpStream::OnRequestBodyReadCompleted(int status) { |
458 CHECK_GE(status, 0); | 464 if (status < 0) { |
459 request_body_buf_size_ = status; | 465 DCHECK_NE(ERR_IO_PENDING, status); |
460 const bool eof = request_info_->upload_data_stream->IsEOF(); | 466 |
461 // Only the final fame may have a length of 0. | 467 base::ThreadTaskRunnerHandle::Get()->PostTask( |
462 if (eof) { | 468 FROM_HERE, base::Bind(&SpdyHttpStream::ResetStreamInternal, |
463 CHECK_GE(request_body_buf_size_, 0); | 469 weak_factory_.GetWeakPtr())); |
464 } else { | 470 } else { |
465 CHECK_GT(request_body_buf_size_, 0); | 471 CHECK_GE(status, 0); |
| 472 request_body_buf_size_ = status; |
| 473 const bool eof = request_info_->upload_data_stream->IsEOF(); |
| 474 // Only the final fame may have a length of 0. |
| 475 if (eof) { |
| 476 CHECK_GE(request_body_buf_size_, 0); |
| 477 } else { |
| 478 CHECK_GT(request_body_buf_size_, 0); |
| 479 } |
| 480 stream_->SendData(request_body_buf_.get(), request_body_buf_size_, |
| 481 eof ? NO_MORE_DATA_TO_SEND : MORE_DATA_TO_SEND); |
466 } | 482 } |
467 stream_->SendData(request_body_buf_.get(), | 483 |
468 request_body_buf_size_, | 484 if (!request_callback_.is_null()) { |
469 eof ? NO_MORE_DATA_TO_SEND : MORE_DATA_TO_SEND); | 485 int result = status > 0 ? OK : status; |
| 486 DoRequestCallback(result); |
| 487 } |
470 } | 488 } |
471 | 489 |
472 void SpdyHttpStream::ScheduleBufferedReadCallback() { | 490 void SpdyHttpStream::ScheduleBufferedReadCallback() { |
473 // If there is already a scheduled DoBufferedReadCallback, don't issue | 491 // If there is already a scheduled DoBufferedReadCallback, don't issue |
474 // another one. Mark that we have received more data and return. | 492 // another one. Mark that we have received more data and return. |
475 if (buffered_read_callback_pending_) { | 493 if (buffered_read_callback_pending_) { |
476 more_read_data_pending_ = true; | 494 more_read_data_pending_ = true; |
477 return; | 495 return; |
478 } | 496 } |
479 | 497 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 details->connection_info = HttpResponseInfo::CONNECTION_INFO_HTTP2; | 602 details->connection_info = HttpResponseInfo::CONNECTION_INFO_HTTP2; |
585 return; | 603 return; |
586 } | 604 } |
587 | 605 |
588 void SpdyHttpStream::SetPriority(RequestPriority priority) { | 606 void SpdyHttpStream::SetPriority(RequestPriority priority) { |
589 // TODO(akalin): Plumb this through to |stream_request_| and | 607 // TODO(akalin): Plumb this through to |stream_request_| and |
590 // |stream_|. | 608 // |stream_|. |
591 } | 609 } |
592 | 610 |
593 } // namespace net | 611 } // namespace net |
OLD | NEW |