| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/bidirectional_stream_quic_impl.h" | 5 #include "net/quic/chromium/bidirectional_stream_quic_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 is_first_stream = stream_->IsFirstStream(); | 220 is_first_stream = stream_->IsFirstStream(); |
| 221 if (is_first_stream) { | 221 if (is_first_stream) { |
| 222 load_timing_info->socket_reused = false; | 222 load_timing_info->socket_reused = false; |
| 223 load_timing_info->connect_timing = connect_timing_; | 223 load_timing_info->connect_timing = connect_timing_; |
| 224 } else { | 224 } else { |
| 225 load_timing_info->socket_reused = true; | 225 load_timing_info->socket_reused = true; |
| 226 } | 226 } |
| 227 return true; | 227 return true; |
| 228 } | 228 } |
| 229 | 229 |
| 230 void BidirectionalStreamQuicImpl::OnInitialHeadersAvailable( | |
| 231 const SpdyHeaderBlock& headers, | |
| 232 size_t frame_len) { | |
| 233 headers_bytes_received_ += frame_len; | |
| 234 negotiated_protocol_ = kProtoQUIC; | |
| 235 connect_timing_ = session_->GetConnectTiming(); | |
| 236 if (delegate_) | |
| 237 delegate_->OnHeadersReceived(headers); | |
| 238 } | |
| 239 | |
| 240 void BidirectionalStreamQuicImpl::OnTrailingHeadersAvailable( | 230 void BidirectionalStreamQuicImpl::OnTrailingHeadersAvailable( |
| 241 const SpdyHeaderBlock& headers, | 231 const SpdyHeaderBlock& headers, |
| 242 size_t frame_len) { | 232 size_t frame_len) { |
| 243 headers_bytes_received_ += frame_len; | 233 headers_bytes_received_ += frame_len; |
| 244 if (delegate_) | 234 if (delegate_) |
| 245 delegate_->OnTrailersReceived(headers); | 235 delegate_->OnTrailersReceived(headers); |
| 246 // |this| can be destroyed after this point. | 236 // |this| can be destroyed after this point. |
| 247 } | 237 } |
| 248 | 238 |
| 249 void BidirectionalStreamQuicImpl::OnDataAvailable() { | 239 void BidirectionalStreamQuicImpl::OnDataAvailable() { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 void BidirectionalStreamQuicImpl::OnError(int error) { | 278 void BidirectionalStreamQuicImpl::OnError(int error) { |
| 289 NotifyError(error); | 279 NotifyError(error); |
| 290 } | 280 } |
| 291 | 281 |
| 292 void BidirectionalStreamQuicImpl::OnStreamReady(int rv) { | 282 void BidirectionalStreamQuicImpl::OnStreamReady(int rv) { |
| 293 DCHECK_NE(ERR_IO_PENDING, rv); | 283 DCHECK_NE(ERR_IO_PENDING, rv); |
| 294 DCHECK(rv == OK || !stream_); | 284 DCHECK(rv == OK || !stream_); |
| 295 if (rv == OK) { | 285 if (rv == OK) { |
| 296 stream_ = session_->ReleaseStream(this); | 286 stream_ = session_->ReleaseStream(this); |
| 297 NotifyStreamReady(); | 287 NotifyStreamReady(); |
| 288 |
| 289 rv = stream_->ReadInitialHeaders( |
| 290 &initial_headers_, |
| 291 base::Bind(&BidirectionalStreamQuicImpl::OnReadInitialHeadersComplete, |
| 292 weak_factory_.GetWeakPtr())); |
| 293 if (rv == ERR_IO_PENDING) |
| 294 return; |
| 295 |
| 296 OnReadInitialHeadersComplete(rv); |
| 298 } else { | 297 } else { |
| 299 NotifyError(rv); | 298 NotifyError(rv); |
| 300 } | 299 } |
| 301 } | 300 } |
| 302 | 301 |
| 303 void BidirectionalStreamQuicImpl::OnSendDataComplete(int rv) { | 302 void BidirectionalStreamQuicImpl::OnSendDataComplete(int rv) { |
| 304 DCHECK(rv == OK || !stream_); | 303 DCHECK(rv == OK || !stream_); |
| 305 if (rv == OK) { | 304 if (rv == OK) { |
| 306 if (delegate_) | 305 if (delegate_) |
| 307 delegate_->OnDataSent(); | 306 delegate_->OnDataSent(); |
| 308 } else { | 307 } else { |
| 309 NotifyError(rv); | 308 NotifyError(rv); |
| 310 } | 309 } |
| 311 } | 310 } |
| 312 | 311 |
| 312 void BidirectionalStreamQuicImpl::OnReadInitialHeadersComplete(int rv) { |
| 313 DCHECK_NE(ERR_IO_PENDING, rv); |
| 314 if (rv < 0) { |
| 315 NotifyError(rv); |
| 316 return; |
| 317 } |
| 318 |
| 319 headers_bytes_received_ += rv; |
| 320 negotiated_protocol_ = kProtoQUIC; |
| 321 connect_timing_ = session_->GetConnectTiming(); |
| 322 if (delegate_) |
| 323 delegate_->OnHeadersReceived(initial_headers_); |
| 324 } |
| 325 |
| 313 void BidirectionalStreamQuicImpl::NotifyError(int error) { | 326 void BidirectionalStreamQuicImpl::NotifyError(int error) { |
| 314 DCHECK_NE(OK, error); | 327 DCHECK_NE(OK, error); |
| 315 DCHECK_NE(ERR_IO_PENDING, error); | 328 DCHECK_NE(ERR_IO_PENDING, error); |
| 316 | 329 |
| 317 ResetStream(); | 330 ResetStream(); |
| 318 if (delegate_) { | 331 if (delegate_) { |
| 319 response_status_ = error; | 332 response_status_ = error; |
| 320 BidirectionalStreamImpl::Delegate* delegate = delegate_; | 333 BidirectionalStreamImpl::Delegate* delegate = delegate_; |
| 321 delegate_ = nullptr; | 334 delegate_ = nullptr; |
| 322 // Cancel any pending callback. | 335 // Cancel any pending callback. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 338 if (!stream_) | 351 if (!stream_) |
| 339 return; | 352 return; |
| 340 closed_stream_received_bytes_ = stream_->stream_bytes_read(); | 353 closed_stream_received_bytes_ = stream_->stream_bytes_read(); |
| 341 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); | 354 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); |
| 342 closed_is_first_stream_ = stream_->IsFirstStream(); | 355 closed_is_first_stream_ = stream_->IsFirstStream(); |
| 343 stream_->ClearDelegate(); | 356 stream_->ClearDelegate(); |
| 344 stream_ = nullptr; | 357 stream_ = nullptr; |
| 345 } | 358 } |
| 346 | 359 |
| 347 } // namespace net | 360 } // namespace net |
| OLD | NEW |