| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/bidirectional_stream_spdy_impl.h" | 5 #include "net/spdy/bidirectional_stream_spdy_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 : spdy_session_(spdy_session), | 31 : spdy_session_(spdy_session), |
| 32 request_info_(nullptr), | 32 request_info_(nullptr), |
| 33 delegate_(nullptr), | 33 delegate_(nullptr), |
| 34 negotiated_protocol_(kProtoUnknown), | 34 negotiated_protocol_(kProtoUnknown), |
| 35 more_read_data_pending_(false), | 35 more_read_data_pending_(false), |
| 36 read_buffer_len_(0), | 36 read_buffer_len_(0), |
| 37 stream_closed_(false), | 37 stream_closed_(false), |
| 38 closed_stream_status_(ERR_FAILED), | 38 closed_stream_status_(ERR_FAILED), |
| 39 closed_stream_received_bytes_(0), | 39 closed_stream_received_bytes_(0), |
| 40 closed_stream_sent_bytes_(0), | 40 closed_stream_sent_bytes_(0), |
| 41 disable_auto_flush_(false), | |
| 42 weak_factory_(this) {} | 41 weak_factory_(this) {} |
| 43 | 42 |
| 44 BidirectionalStreamSpdyImpl::~BidirectionalStreamSpdyImpl() { | 43 BidirectionalStreamSpdyImpl::~BidirectionalStreamSpdyImpl() { |
| 45 if (stream_) { | 44 if (stream_) { |
| 46 stream_->DetachDelegate(); | 45 stream_->DetachDelegate(); |
| 47 DCHECK(!stream_); | 46 DCHECK(!stream_); |
| 48 } | 47 } |
| 49 } | 48 } |
| 50 | 49 |
| 51 void BidirectionalStreamSpdyImpl::Start( | 50 void BidirectionalStreamSpdyImpl::Start( |
| 52 const BidirectionalStreamRequestInfo* request_info, | 51 const BidirectionalStreamRequestInfo* request_info, |
| 53 const BoundNetLog& net_log, | 52 const BoundNetLog& net_log, |
| 54 bool disable_auto_flush, | 53 bool /*delay_headers_until_next_send_data*/, |
| 55 BidirectionalStreamImpl::Delegate* delegate, | 54 BidirectionalStreamImpl::Delegate* delegate, |
| 56 std::unique_ptr<base::Timer> timer) { | 55 std::unique_ptr<base::Timer> timer) { |
| 57 DCHECK(!stream_); | 56 DCHECK(!stream_); |
| 58 DCHECK(timer); | 57 DCHECK(timer); |
| 59 | 58 |
| 60 disable_auto_flush_ = disable_auto_flush; | |
| 61 delegate_ = delegate; | 59 delegate_ = delegate; |
| 62 timer_ = std::move(timer); | 60 timer_ = std::move(timer); |
| 63 | 61 |
| 64 if (!spdy_session_) { | 62 if (!spdy_session_) { |
| 65 delegate_->OnFailed(ERR_CONNECTION_CLOSED); | 63 delegate_->OnFailed(ERR_CONNECTION_CLOSED); |
| 66 return; | 64 return; |
| 67 } | 65 } |
| 68 | 66 |
| 69 request_info_ = request_info; | 67 request_info_ = request_info; |
| 70 | 68 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 96 read_buffer_ = buf; | 94 read_buffer_ = buf; |
| 97 read_buffer_len_ = buf_len; | 95 read_buffer_len_ = buf_len; |
| 98 return ERR_IO_PENDING; | 96 return ERR_IO_PENDING; |
| 99 } | 97 } |
| 100 | 98 |
| 101 void BidirectionalStreamSpdyImpl::SendData(const scoped_refptr<IOBuffer>& data, | 99 void BidirectionalStreamSpdyImpl::SendData(const scoped_refptr<IOBuffer>& data, |
| 102 int length, | 100 int length, |
| 103 bool end_stream) { | 101 bool end_stream) { |
| 104 DCHECK(!stream_closed_); | 102 DCHECK(!stream_closed_); |
| 105 DCHECK(stream_); | 103 DCHECK(stream_); |
| 106 DCHECK(!disable_auto_flush_); | |
| 107 | 104 |
| 108 stream_->SendData(data.get(), length, | 105 stream_->SendData(data.get(), length, |
| 109 end_stream ? NO_MORE_DATA_TO_SEND : MORE_DATA_TO_SEND); | 106 end_stream ? NO_MORE_DATA_TO_SEND : MORE_DATA_TO_SEND); |
| 110 } | 107 } |
| 111 | 108 |
| 112 void BidirectionalStreamSpdyImpl::SendvData( | 109 void BidirectionalStreamSpdyImpl::SendvData( |
| 113 const std::vector<scoped_refptr<IOBuffer>>& buffers, | 110 const std::vector<scoped_refptr<IOBuffer>>& buffers, |
| 114 const std::vector<int>& lengths, | 111 const std::vector<int>& lengths, |
| 115 bool end_stream) { | 112 bool end_stream) { |
| 116 DCHECK(!stream_closed_); | 113 DCHECK(!stream_closed_); |
| 117 DCHECK(stream_); | 114 DCHECK(stream_); |
| 118 DCHECK(disable_auto_flush_); | |
| 119 DCHECK_EQ(buffers.size(), lengths.size()); | 115 DCHECK_EQ(buffers.size(), lengths.size()); |
| 120 | 116 |
| 121 int total_len = 0; | 117 int total_len = 0; |
| 122 for (int len : lengths) { | 118 for (int len : lengths) { |
| 123 total_len += len; | 119 total_len += len; |
| 124 } | 120 } |
| 125 | 121 |
| 126 pending_combined_buffer_ = new net::IOBuffer(total_len); | 122 pending_combined_buffer_ = new net::IOBuffer(total_len); |
| 127 int len = 0; | 123 int len = 0; |
| 128 // TODO(xunjieli): Get rid of extra copy. Coalesce headers and data frames. | 124 // TODO(xunjieli): Get rid of extra copy. Coalesce headers and data frames. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 // Handing small chunks of data to the caller creates measurable overhead. | 194 // Handing small chunks of data to the caller creates measurable overhead. |
| 199 // So buffer data in short time-spans and send a single read notification. | 195 // So buffer data in short time-spans and send a single read notification. |
| 200 ScheduleBufferedRead(); | 196 ScheduleBufferedRead(); |
| 201 } | 197 } |
| 202 } | 198 } |
| 203 | 199 |
| 204 void BidirectionalStreamSpdyImpl::OnDataSent() { | 200 void BidirectionalStreamSpdyImpl::OnDataSent() { |
| 205 DCHECK(stream_); | 201 DCHECK(stream_); |
| 206 DCHECK(!stream_closed_); | 202 DCHECK(!stream_closed_); |
| 207 | 203 |
| 208 if (disable_auto_flush_) { | 204 pending_combined_buffer_ = nullptr; |
| 209 DCHECK(pending_combined_buffer_); | |
| 210 pending_combined_buffer_ = nullptr; | |
| 211 } | |
| 212 delegate_->OnDataSent(); | 205 delegate_->OnDataSent(); |
| 213 } | 206 } |
| 214 | 207 |
| 215 void BidirectionalStreamSpdyImpl::OnTrailers(const SpdyHeaderBlock& trailers) { | 208 void BidirectionalStreamSpdyImpl::OnTrailers(const SpdyHeaderBlock& trailers) { |
| 216 DCHECK(stream_); | 209 DCHECK(stream_); |
| 217 DCHECK(!stream_closed_); | 210 DCHECK(!stream_closed_); |
| 218 | 211 |
| 219 delegate_->OnTrailersReceived(trailers); | 212 delegate_->OnTrailersReceived(trailers); |
| 220 } | 213 } |
| 221 | 214 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 | 299 |
| 307 bool BidirectionalStreamSpdyImpl::ShouldWaitForMoreBufferedData() const { | 300 bool BidirectionalStreamSpdyImpl::ShouldWaitForMoreBufferedData() const { |
| 308 if (stream_closed_) | 301 if (stream_closed_) |
| 309 return false; | 302 return false; |
| 310 DCHECK_GT(read_buffer_len_, 0); | 303 DCHECK_GT(read_buffer_len_, 0); |
| 311 return read_data_queue_.GetTotalSize() < | 304 return read_data_queue_.GetTotalSize() < |
| 312 static_cast<size_t>(read_buffer_len_); | 305 static_cast<size_t>(read_buffer_len_); |
| 313 } | 306 } |
| 314 | 307 |
| 315 } // namespace net | 308 } // namespace net |
| OLD | NEW |