| 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 <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 bool SpdyHttpStream::IsConnectionReusable() const { | 180 bool SpdyHttpStream::IsConnectionReusable() const { |
| 181 // SPDY streams aren't considered reusable. | 181 // SPDY streams aren't considered reusable. |
| 182 return false; | 182 return false; |
| 183 } | 183 } |
| 184 | 184 |
| 185 void SpdyHttpStream::set_chunk_callback(ChunkCallback* callback) { | 185 void SpdyHttpStream::set_chunk_callback(ChunkCallback* callback) { |
| 186 if (request_body_stream_ != NULL) | 186 if (request_body_stream_ != NULL) |
| 187 request_body_stream_->set_chunk_callback(callback); | 187 request_body_stream_->set_chunk_callback(callback); |
| 188 } | 188 } |
| 189 | 189 |
| 190 bool SpdyHttpStream::IsRequestBodyChunked() { |
| 191 return request_body_stream_ != NULL && request_body_stream_->is_chunked(); |
| 192 } |
| 193 |
| 190 int SpdyHttpStream::SendRequest(const HttpRequestHeaders& request_headers, | 194 int SpdyHttpStream::SendRequest(const HttpRequestHeaders& request_headers, |
| 191 scoped_ptr<UploadDataStream> request_body, | 195 scoped_ptr<UploadDataStream> request_body, |
| 192 HttpResponseInfo* response, | 196 HttpResponseInfo* response, |
| 193 const CompletionCallback& callback) { | 197 const CompletionCallback& callback) { |
| 194 base::Time request_time = base::Time::Now(); | 198 base::Time request_time = base::Time::Now(); |
| 195 CHECK(stream_.get()); | 199 CHECK(stream_.get()); |
| 196 | 200 |
| 197 stream_->SetDelegate(this); | 201 stream_->SetDelegate(this); |
| 198 | 202 |
| 199 linked_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); | 203 linked_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 } | 268 } |
| 265 | 269 |
| 266 void SpdyHttpStream::Cancel() { | 270 void SpdyHttpStream::Cancel() { |
| 267 if (spdy_session_) | 271 if (spdy_session_) |
| 268 spdy_session_->CancelPendingCreateStreams(&stream_); | 272 spdy_session_->CancelPendingCreateStreams(&stream_); |
| 269 callback_.Reset(); | 273 callback_.Reset(); |
| 270 if (stream_) | 274 if (stream_) |
| 271 stream_->Cancel(); | 275 stream_->Cancel(); |
| 272 } | 276 } |
| 273 | 277 |
| 274 bool SpdyHttpStream::OnSendHeadersComplete(int status) { | 278 int SpdyHttpStream::SendBody() { |
| 275 if (!callback_.is_null()) | |
| 276 DoCallback(status); | |
| 277 return request_body_stream_.get() == NULL; | |
| 278 } | |
| 279 | |
| 280 int SpdyHttpStream::OnSendBody() { | |
| 281 CHECK(request_body_stream_.get()); | 279 CHECK(request_body_stream_.get()); |
| 282 | 280 |
| 283 // TODO(satorux): Clean up the logic here. This behavior is weird. Reading | 281 // TODO(satorux): Clean up the logic here. This behavior is weird. Reading |
| 284 // of upload data should happen in OnSendBody(). crbug.com/113107. | 282 // of upload data should happen in OnSendBody(). crbug.com/113107. |
| 285 // | 283 // |
| 286 // Nothing to send. This happens when OnSendBody() is first called. | 284 // Nothing to send. This happens when OnSendBody() is first called. |
| 287 // A read of the upload data stream is initiated in OnSendBodyComplete(). | 285 // A read of the upload data stream is initiated in OnSendBodyComplete(). |
| 288 if (request_body_buf_->BytesRemaining() == 0) | 286 if (request_body_buf_->BytesRemaining() == 0) |
| 289 return OK; | 287 return OK; |
| 290 | 288 |
| 291 const bool eof = request_body_stream_->IsEOF(); | 289 const bool eof = request_body_stream_->IsEOF(); |
| 292 return stream_->WriteStreamData( | 290 return stream_->WriteStreamData( |
| 293 request_body_buf_, | 291 request_body_buf_, |
| 294 request_body_buf_->BytesRemaining(), | 292 request_body_buf_->BytesRemaining(), |
| 295 eof ? DATA_FLAG_FIN : DATA_FLAG_NONE); | 293 eof ? DATA_FLAG_FIN : DATA_FLAG_NONE); |
| 296 } | 294 } |
| 297 | 295 |
| 298 int SpdyHttpStream::OnSendBodyComplete(int status, bool* eof) { | 296 int SpdyHttpStream::SendBodyComplete(int status, bool* eof) { |
| 299 // |status| is the number of bytes written to the SPDY stream. | 297 // |status| is the number of bytes written to the SPDY stream. |
| 300 CHECK(request_body_stream_.get()); | 298 CHECK(request_body_stream_.get()); |
| 301 *eof = false; | 299 *eof = false; |
| 302 | 300 |
| 303 if (status > 0) { | 301 if (status > 0) { |
| 304 request_body_buf_->DidConsume(status); | 302 request_body_buf_->DidConsume(status); |
| 305 if (request_body_buf_->BytesRemaining()) { | 303 if (request_body_buf_->BytesRemaining()) { |
| 306 // Go back to OnSendBody() to send the remaining data. | 304 // Go back to OnSendBody() to send the remaining data. |
| 307 return OK; | 305 return OK; |
| 308 } | 306 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 320 if (request_body_stream_->is_chunked() && bytes_read == ERR_IO_PENDING) | 318 if (request_body_stream_->is_chunked() && bytes_read == ERR_IO_PENDING) |
| 321 return ERR_IO_PENDING; | 319 return ERR_IO_PENDING; |
| 322 // ERR_IO_PENDING with chunked encoding is the only possible error. | 320 // ERR_IO_PENDING with chunked encoding is the only possible error. |
| 323 DCHECK_GE(bytes_read, 0); | 321 DCHECK_GE(bytes_read, 0); |
| 324 | 322 |
| 325 request_body_buf_ = new DrainableIOBuffer(raw_request_body_buf_, | 323 request_body_buf_ = new DrainableIOBuffer(raw_request_body_buf_, |
| 326 bytes_read); | 324 bytes_read); |
| 327 return OK; | 325 return OK; |
| 328 } | 326 } |
| 329 | 327 |
| 328 bool SpdyHttpStream::OnSendHeadersComplete(int status) { |
| 329 if (!callback_.is_null()) |
| 330 DoCallback(status); |
| 331 return request_body_stream_.get() == NULL; |
| 332 } |
| 333 |
| 334 int SpdyHttpStream::OnSendBody() { |
| 335 return SendBody(); |
| 336 } |
| 337 |
| 338 int SpdyHttpStream::OnSendBodyComplete(int status, bool* eof) { |
| 339 return SendBodyComplete(status, eof); |
| 340 } |
| 341 |
| 342 int SpdyHttpStream::OnSendChunkedBody() { |
| 343 return OnSendBody(); |
| 344 } |
| 345 |
| 346 int SpdyHttpStream::OnSendChunkedBodyComplete(int status, bool* eof) { |
| 347 return OnSendBodyComplete(status, eof); |
| 348 } |
| 349 |
| 330 int SpdyHttpStream::OnResponseReceived(const SpdyHeaderBlock& response, | 350 int SpdyHttpStream::OnResponseReceived(const SpdyHeaderBlock& response, |
| 331 base::Time response_time, | 351 base::Time response_time, |
| 332 int status) { | 352 int status) { |
| 333 if (!response_info_) { | 353 if (!response_info_) { |
| 334 DCHECK(stream_->pushed()); | 354 DCHECK(stream_->pushed()); |
| 335 push_response_info_.reset(new HttpResponseInfo); | 355 push_response_info_.reset(new HttpResponseInfo); |
| 336 response_info_ = push_response_info_.get(); | 356 response_info_ = push_response_info_.get(); |
| 337 } | 357 } |
| 338 | 358 |
| 339 // If the response is already received, these headers are too late. | 359 // If the response is already received, these headers are too late. |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 bool SpdyHttpStream::IsSpdyHttpStream() const { | 524 bool SpdyHttpStream::IsSpdyHttpStream() const { |
| 505 return true; | 525 return true; |
| 506 } | 526 } |
| 507 | 527 |
| 508 void SpdyHttpStream::Drain(HttpNetworkSession* session) { | 528 void SpdyHttpStream::Drain(HttpNetworkSession* session) { |
| 509 Close(false); | 529 Close(false); |
| 510 delete this; | 530 delete this; |
| 511 } | 531 } |
| 512 | 532 |
| 513 } // namespace net | 533 } // namespace net |
| OLD | NEW |