| 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 24 matching lines...) Expand all Loading... |
| 35 has_sent_headers_(false), | 35 has_sent_headers_(false), |
| 36 has_received_headers_(false), | 36 has_received_headers_(false), |
| 37 send_request_headers_automatically_(true), | 37 send_request_headers_automatically_(true), |
| 38 waiting_for_confirmation_(false), | 38 waiting_for_confirmation_(false), |
| 39 weak_factory_(this) { | 39 weak_factory_(this) { |
| 40 DCHECK(session_); | 40 DCHECK(session_); |
| 41 session_->AddObserver(this); | 41 session_->AddObserver(this); |
| 42 } | 42 } |
| 43 | 43 |
| 44 BidirectionalStreamQuicImpl::~BidirectionalStreamQuicImpl() { | 44 BidirectionalStreamQuicImpl::~BidirectionalStreamQuicImpl() { |
| 45 Cancel(); | 45 if (stream_) { |
| 46 delegate_ = nullptr; |
| 47 stream_->Reset(QUIC_STREAM_CANCELLED); |
| 48 } |
| 49 |
| 46 if (session_) | 50 if (session_) |
| 47 session_->RemoveObserver(this); | 51 session_->RemoveObserver(this); |
| 48 } | 52 } |
| 49 | 53 |
| 50 void BidirectionalStreamQuicImpl::Start( | 54 void BidirectionalStreamQuicImpl::Start( |
| 51 const BidirectionalStreamRequestInfo* request_info, | 55 const BidirectionalStreamRequestInfo* request_info, |
| 52 const BoundNetLog& net_log, | 56 const BoundNetLog& net_log, |
| 53 bool send_request_headers_automatically, | 57 bool send_request_headers_automatically, |
| 54 BidirectionalStreamImpl::Delegate* delegate, | 58 BidirectionalStreamImpl::Delegate* delegate, |
| 55 std::unique_ptr<base::Timer> /* timer */) { | 59 std::unique_ptr<base::Timer> /* timer */) { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 weak_factory_.GetWeakPtr())); | 192 weak_factory_.GetWeakPtr())); |
| 189 | 193 |
| 190 DCHECK(rv == OK || rv == ERR_IO_PENDING); | 194 DCHECK(rv == OK || rv == ERR_IO_PENDING); |
| 191 if (rv == OK) { | 195 if (rv == OK) { |
| 192 base::ThreadTaskRunnerHandle::Get()->PostTask( | 196 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 193 FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete, | 197 FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete, |
| 194 weak_factory_.GetWeakPtr(), OK)); | 198 weak_factory_.GetWeakPtr(), OK)); |
| 195 } | 199 } |
| 196 } | 200 } |
| 197 | 201 |
| 198 void BidirectionalStreamQuicImpl::Cancel() { | |
| 199 if (delegate_) { | |
| 200 delegate_ = nullptr; | |
| 201 // Cancel any pending callbacks. | |
| 202 weak_factory_.InvalidateWeakPtrs(); | |
| 203 } | |
| 204 if (stream_) { | |
| 205 stream_->Reset(QUIC_STREAM_CANCELLED); | |
| 206 ResetStream(); | |
| 207 } | |
| 208 } | |
| 209 | |
| 210 NextProto BidirectionalStreamQuicImpl::GetProtocol() const { | 202 NextProto BidirectionalStreamQuicImpl::GetProtocol() const { |
| 211 return negotiated_protocol_; | 203 return negotiated_protocol_; |
| 212 } | 204 } |
| 213 | 205 |
| 214 int64_t BidirectionalStreamQuicImpl::GetTotalReceivedBytes() const { | 206 int64_t BidirectionalStreamQuicImpl::GetTotalReceivedBytes() const { |
| 215 if (stream_) | 207 if (stream_) |
| 216 return headers_bytes_received_ + stream_->stream_bytes_read(); | 208 return headers_bytes_received_ + stream_->stream_bytes_read(); |
| 217 return headers_bytes_received_ + closed_stream_received_bytes_; | 209 return headers_bytes_received_ + closed_stream_received_bytes_; |
| 218 } | 210 } |
| 219 | 211 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 void BidirectionalStreamQuicImpl::ResetStream() { | 339 void BidirectionalStreamQuicImpl::ResetStream() { |
| 348 if (!stream_) | 340 if (!stream_) |
| 349 return; | 341 return; |
| 350 closed_stream_received_bytes_ = stream_->stream_bytes_read(); | 342 closed_stream_received_bytes_ = stream_->stream_bytes_read(); |
| 351 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); | 343 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); |
| 352 stream_->SetDelegate(nullptr); | 344 stream_->SetDelegate(nullptr); |
| 353 stream_ = nullptr; | 345 stream_ = nullptr; |
| 354 } | 346 } |
| 355 | 347 |
| 356 } // namespace net | 348 } // namespace net |
| OLD | NEW |