| 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/quic/chromium/quic_http_stream.h" | 5 #include "net/quic/chromium/quic_http_stream.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // rendezvous has failed so proceed as with a non-push request. | 128 // rendezvous has failed so proceed as with a non-push request. |
| 129 next_state_ = STATE_REQUEST_STREAM; | 129 next_state_ = STATE_REQUEST_STREAM; |
| 130 OnIOComplete(OK); | 130 OnIOComplete(OK); |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 int QuicHttpStream::InitializeStream(const HttpRequestInfo* request_info, | 134 int QuicHttpStream::InitializeStream(const HttpRequestInfo* request_info, |
| 135 RequestPriority priority, | 135 RequestPriority priority, |
| 136 const BoundNetLog& stream_net_log, | 136 const BoundNetLog& stream_net_log, |
| 137 const CompletionCallback& callback) { | 137 const CompletionCallback& callback) { |
| 138 CHECK(callback_.is_null()); |
| 138 DCHECK(!stream_); | 139 DCHECK(!stream_); |
| 139 if (!session_) | 140 if (!session_) |
| 140 return was_handshake_confirmed_ ? ERR_CONNECTION_CLOSED | 141 return was_handshake_confirmed_ ? ERR_CONNECTION_CLOSED |
| 141 : ERR_QUIC_HANDSHAKE_FAILED; | 142 : ERR_QUIC_HANDSHAKE_FAILED; |
| 142 | 143 |
| 143 stream_net_log.AddEvent( | 144 stream_net_log.AddEvent( |
| 144 NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_QUIC_SESSION, | 145 NetLog::TYPE_HTTP_STREAM_REQUEST_BOUND_TO_QUIC_SESSION, |
| 145 session_->net_log().source().ToEventParametersCallback()); | 146 session_->net_log().source().ToEventParametersCallback()); |
| 146 | 147 |
| 147 stream_net_log_ = stream_net_log; | 148 stream_net_log_ = stream_net_log; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 break; | 247 break; |
| 247 } | 248 } |
| 248 return DoLoop(OK); | 249 return DoLoop(OK); |
| 249 } | 250 } |
| 250 | 251 |
| 251 int QuicHttpStream::SendRequest(const HttpRequestHeaders& request_headers, | 252 int QuicHttpStream::SendRequest(const HttpRequestHeaders& request_headers, |
| 252 HttpResponseInfo* response, | 253 HttpResponseInfo* response, |
| 253 const CompletionCallback& callback) { | 254 const CompletionCallback& callback) { |
| 254 CHECK(!request_body_stream_); | 255 CHECK(!request_body_stream_); |
| 255 CHECK(!response_info_); | 256 CHECK(!response_info_); |
| 257 CHECK(callback_.is_null()); |
| 256 CHECK(!callback.is_null()); | 258 CHECK(!callback.is_null()); |
| 257 CHECK(response); | 259 CHECK(response); |
| 258 | 260 |
| 259 // TODO(rch): remove this once we figure out why channel ID is not being | 261 // TODO(rch): remove this once we figure out why channel ID is not being |
| 260 // sent when it should be. | 262 // sent when it should be. |
| 261 HostPortPair origin = HostPortPair::FromURL(request_info_->url); | 263 HostPortPair origin = HostPortPair::FromURL(request_info_->url); |
| 262 if (origin.Equals(HostPortPair("accounts.google.com", 443)) && | 264 if (origin.Equals(HostPortPair("accounts.google.com", 443)) && |
| 263 request_headers.HasHeader(HttpRequestHeaders::kCookie)) { | 265 request_headers.HasHeader(HttpRequestHeaders::kCookie)) { |
| 264 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.CookieSentToAccountsOverChannelId", | 266 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.CookieSentToAccountsOverChannelId", |
| 265 ssl_info_.channel_id_sent); | 267 ssl_info_.channel_id_sent); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 311 |
| 310 UploadProgress QuicHttpStream::GetUploadProgress() const { | 312 UploadProgress QuicHttpStream::GetUploadProgress() const { |
| 311 if (!request_body_stream_) | 313 if (!request_body_stream_) |
| 312 return UploadProgress(); | 314 return UploadProgress(); |
| 313 | 315 |
| 314 return UploadProgress(request_body_stream_->position(), | 316 return UploadProgress(request_body_stream_->position(), |
| 315 request_body_stream_->size()); | 317 request_body_stream_->size()); |
| 316 } | 318 } |
| 317 | 319 |
| 318 int QuicHttpStream::ReadResponseHeaders(const CompletionCallback& callback) { | 320 int QuicHttpStream::ReadResponseHeaders(const CompletionCallback& callback) { |
| 321 CHECK(callback_.is_null()); |
| 319 CHECK(!callback.is_null()); | 322 CHECK(!callback.is_null()); |
| 320 | 323 |
| 321 if (stream_ == nullptr) | 324 if (stream_ == nullptr) |
| 322 return response_status_; | 325 return response_status_; |
| 323 | 326 |
| 324 // Check if we already have the response headers. If so, return synchronously. | 327 // Check if we already have the response headers. If so, return synchronously. |
| 325 if (response_headers_received_) | 328 if (response_headers_received_) |
| 326 return OK; | 329 return OK; |
| 327 | 330 |
| 328 // Still waiting for the response, return IO_PENDING. | 331 // Still waiting for the response, return IO_PENDING. |
| 329 CHECK(callback_.is_null()); | 332 CHECK(callback_.is_null()); |
| 330 callback_ = callback; | 333 callback_ = callback; |
| 331 return ERR_IO_PENDING; | 334 return ERR_IO_PENDING; |
| 332 } | 335 } |
| 333 | 336 |
| 334 int QuicHttpStream::ReadResponseBody(IOBuffer* buf, | 337 int QuicHttpStream::ReadResponseBody(IOBuffer* buf, |
| 335 int buf_len, | 338 int buf_len, |
| 336 const CompletionCallback& callback) { | 339 const CompletionCallback& callback) { |
| 340 CHECK(callback_.is_null()); |
| 341 CHECK(!callback.is_null()); |
| 342 CHECK(!user_buffer_.get()); |
| 343 CHECK_EQ(0, user_buffer_len_); |
| 344 |
| 337 if (!stream_) { | 345 if (!stream_) { |
| 338 // If the stream is already closed, there is no body to read. | 346 // If the stream is already closed, there is no body to read. |
| 339 return response_status_; | 347 return response_status_; |
| 340 } | 348 } |
| 341 | 349 |
| 342 int rv = ReadAvailableData(buf, buf_len); | 350 int rv = ReadAvailableData(buf, buf_len); |
| 343 if (rv != ERR_IO_PENDING) | 351 if (rv != ERR_IO_PENDING) |
| 344 return rv; | 352 return rv; |
| 345 | 353 |
| 346 CHECK(callback_.is_null()); | |
| 347 CHECK(!user_buffer_.get()); | |
| 348 CHECK_EQ(0, user_buffer_len_); | |
| 349 | |
| 350 callback_ = callback; | 354 callback_ = callback; |
| 351 user_buffer_ = buf; | 355 user_buffer_ = buf; |
| 352 user_buffer_len_ = buf_len; | 356 user_buffer_len_ = buf_len; |
| 353 return ERR_IO_PENDING; | 357 return ERR_IO_PENDING; |
| 354 } | 358 } |
| 355 | 359 |
| 356 void QuicHttpStream::Close(bool not_reusable) { | 360 void QuicHttpStream::Close(bool not_reusable) { |
| 357 // Note: the not_reusable flag has no meaning for SPDY streams. | 361 // Note: the not_reusable flag has no meaning for SPDY streams. |
| 358 if (stream_) { | 362 if (stream_) { |
| 359 stream_->SetDelegate(nullptr); | 363 stream_->SetDelegate(nullptr); |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); | 831 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); |
| 828 stream_ = nullptr; | 832 stream_ = nullptr; |
| 829 | 833 |
| 830 // If |request_body_stream_| is non-NULL, Reset it, to abort any in progress | 834 // If |request_body_stream_| is non-NULL, Reset it, to abort any in progress |
| 831 // read. | 835 // read. |
| 832 if (request_body_stream_) | 836 if (request_body_stream_) |
| 833 request_body_stream_->Reset(); | 837 request_body_stream_->Reset(); |
| 834 } | 838 } |
| 835 | 839 |
| 836 } // namespace net | 840 } // namespace net |
| OLD | NEW |