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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 weak_factory_.GetWeakPtr(), callback)); | 92 weak_factory_.GetWeakPtr(), callback)); |
93 | 93 |
94 if (rv == OK) { | 94 if (rv == OK) { |
95 stream_ = stream_request_.ReleaseStream(); | 95 stream_ = stream_request_.ReleaseStream(); |
96 InitializeStreamHelper(); | 96 InitializeStreamHelper(); |
97 } | 97 } |
98 | 98 |
99 return rv; | 99 return rv; |
100 } | 100 } |
101 | 101 |
102 UploadProgress SpdyHttpStream::GetUploadProgress() const { | |
103 if (!request_info_ || !HasUploadData()) | |
104 return UploadProgress(); | |
105 | |
106 return UploadProgress(request_info_->upload_data_stream->position(), | |
107 request_info_->upload_data_stream->size()); | |
108 } | |
109 | |
110 int SpdyHttpStream::ReadResponseHeaders(const CompletionCallback& callback) { | 102 int SpdyHttpStream::ReadResponseHeaders(const CompletionCallback& callback) { |
111 CHECK(!callback.is_null()); | 103 CHECK(!callback.is_null()); |
112 if (stream_closed_) | 104 if (stream_closed_) |
113 return closed_stream_status_; | 105 return closed_stream_status_; |
114 | 106 |
115 CHECK(stream_.get()); | 107 CHECK(stream_.get()); |
116 | 108 |
117 // Check if we already have the response headers. If so, return synchronously. | 109 // Check if we already have the response headers. If so, return synchronously. |
118 if (response_headers_status_ == RESPONSE_HEADERS_ARE_COMPLETE) { | 110 if (response_headers_status_ == RESPONSE_HEADERS_ARE_COMPLETE) { |
119 CHECK(!stream_->IsIdle()); | 111 CHECK(!stream_->IsIdle()); |
120 return OK; | 112 return OK; |
121 } | 113 } |
122 | 114 |
123 // Still waiting for the response, return IO_PENDING. | 115 // Still waiting for the response, return IO_PENDING. |
124 CHECK(response_callback_.is_null()); | 116 CHECK(response_callback_.is_null()); |
125 response_callback_ = callback; | 117 response_callback_ = callback; |
126 return ERR_IO_PENDING; | 118 return ERR_IO_PENDING; |
127 } | 119 } |
128 | 120 |
129 int SpdyHttpStream::ReadResponseBody( | 121 int SpdyHttpStream::ReadResponseBody( |
130 IOBuffer* buf, int buf_len, const CompletionCallback& callback) { | 122 IOBuffer* buf, int buf_len, const CompletionCallback& callback) { |
| 123 // Invalidate HttpRequestInfo pointer. This is to allow the stream to be |
| 124 // shared across multiple transactions which might require this |
| 125 // stream to outlive the request_'s owner. |
| 126 if (request_info_) |
| 127 ResetRequestInfo(); |
| 128 |
131 if (stream_.get()) | 129 if (stream_.get()) |
132 CHECK(!stream_->IsIdle()); | 130 CHECK(!stream_->IsIdle()); |
133 | 131 |
134 CHECK(buf); | 132 CHECK(buf); |
135 CHECK(buf_len); | 133 CHECK(buf_len); |
136 CHECK(!callback.is_null()); | 134 CHECK(!callback.is_null()); |
137 | 135 |
138 // If we have data buffered, complete the IO immediately. | 136 // If we have data buffered, complete the IO immediately. |
139 if (!response_body_queue_.IsEmpty()) { | 137 if (!response_body_queue_.IsEmpty()) { |
140 return response_body_queue_.Dequeue(buf->data(), buf_len); | 138 return response_body_queue_.Dequeue(buf->data(), buf_len); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 void SpdyHttpStream::OnDataSent() { | 366 void SpdyHttpStream::OnDataSent() { |
369 request_body_buf_size_ = 0; | 367 request_body_buf_size_ = 0; |
370 ReadAndSendRequestBodyData(); | 368 ReadAndSendRequestBodyData(); |
371 } | 369 } |
372 | 370 |
373 // TODO(xunjieli): Maybe do something with the trailers. crbug.com/422958. | 371 // TODO(xunjieli): Maybe do something with the trailers. crbug.com/422958. |
374 void SpdyHttpStream::OnTrailers(const SpdyHeaderBlock& trailers) {} | 372 void SpdyHttpStream::OnTrailers(const SpdyHeaderBlock& trailers) {} |
375 | 373 |
376 void SpdyHttpStream::OnClose(int status) { | 374 void SpdyHttpStream::OnClose(int status) { |
377 // Cancel any pending reads from the upload data stream. | 375 // Cancel any pending reads from the upload data stream. |
378 if (request_info_->upload_data_stream) | 376 if (request_info_ && request_info_->upload_data_stream) |
379 request_info_->upload_data_stream->Reset(); | 377 request_info_->upload_data_stream->Reset(); |
380 | 378 |
381 if (stream_.get()) { | 379 if (stream_.get()) { |
382 stream_closed_ = true; | 380 stream_closed_ = true; |
383 closed_stream_status_ = status; | 381 closed_stream_status_ = status; |
384 closed_stream_id_ = stream_->stream_id(); | 382 closed_stream_id_ = stream_->stream_id(); |
385 closed_stream_has_load_timing_info_ = | 383 closed_stream_has_load_timing_info_ = |
386 stream_->GetLoadTimingInfo(&closed_stream_load_timing_info_); | 384 stream_->GetLoadTimingInfo(&closed_stream_load_timing_info_); |
387 closed_stream_received_bytes_ = stream_->raw_received_bytes(); | 385 closed_stream_received_bytes_ = stream_->raw_received_bytes(); |
388 closed_stream_sent_bytes_ = stream_->raw_sent_bytes(); | 386 closed_stream_sent_bytes_ = stream_->raw_sent_bytes(); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 void SpdyHttpStream::PopulateNetErrorDetails(NetErrorDetails* details) { | 611 void SpdyHttpStream::PopulateNetErrorDetails(NetErrorDetails* details) { |
614 details->connection_info = HttpResponseInfo::CONNECTION_INFO_HTTP2; | 612 details->connection_info = HttpResponseInfo::CONNECTION_INFO_HTTP2; |
615 return; | 613 return; |
616 } | 614 } |
617 | 615 |
618 void SpdyHttpStream::SetPriority(RequestPriority priority) { | 616 void SpdyHttpStream::SetPriority(RequestPriority priority) { |
619 // TODO(akalin): Plumb this through to |stream_request_| and | 617 // TODO(akalin): Plumb this through to |stream_request_| and |
620 // |stream_|. | 618 // |stream_|. |
621 } | 619 } |
622 | 620 |
| 621 void SpdyHttpStream::ResetRequestInfo() { |
| 622 // Only allowed when Reading of response body starts. It is safe to reset it |
| 623 // at this point since request_->upload_data_stream is also not needed |
| 624 // anymore. |
| 625 |
| 626 request_info_ = nullptr; |
| 627 } |
| 628 |
623 } // namespace net | 629 } // namespace net |
OLD | NEW |