xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 5 | #include "net/spdy/bidirectional_stream_spdy_impl.h" |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 6 | |
| 7 | #include "base/bind.h" |
| 8 | #include "base/location.h" |
| 9 | #include "base/logging.h" |
| 10 | #include "base/time/time.h" |
| 11 | #include "base/timer/timer.h" |
| 12 | #include "net/http/bidirectional_stream_request_info.h" |
| 13 | #include "net/spdy/spdy_buffer.h" |
| 14 | #include "net/spdy/spdy_header_block.h" |
| 15 | #include "net/spdy/spdy_http_utils.h" |
| 16 | #include "net/spdy/spdy_stream.h" |
| 17 | |
| 18 | namespace net { |
| 19 | |
| 20 | namespace { |
| 21 | |
| 22 | // Time to wait in millisecond to notify |delegate_| of data received. |
| 23 | // Handing small chunks of data to the caller creates measurable overhead. |
| 24 | // So buffer data in short time-spans and send a single read notification. |
mef | e666e9a | 2015-12-30 23:41:30 | [diff] [blame] | 25 | const int kBufferTimeMs = 1; |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 26 | |
| 27 | } // namespace |
| 28 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 29 | BidirectionalStreamSpdyImpl::BidirectionalStreamSpdyImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 30 | const base::WeakPtr<SpdySession>& spdy_session) |
| 31 | : spdy_session_(spdy_session), |
| 32 | request_info_(nullptr), |
| 33 | delegate_(nullptr), |
| 34 | negotiated_protocol_(kProtoUnknown), |
| 35 | more_read_data_pending_(false), |
| 36 | read_buffer_len_(0), |
| 37 | stream_closed_(false), |
| 38 | closed_stream_status_(ERR_FAILED), |
| 39 | closed_stream_received_bytes_(0), |
| 40 | closed_stream_sent_bytes_(0), |
| 41 | weak_factory_(this) {} |
| 42 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 43 | BidirectionalStreamSpdyImpl::~BidirectionalStreamSpdyImpl() { |
xunjieli | 9ff75c56 | 2016-08-10 20:26:16 | [diff] [blame] | 44 | // Sends a RST to the remote if the stream is destroyed before it completes. |
| 45 | ResetStream(); |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 46 | } |
| 47 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 48 | void BidirectionalStreamSpdyImpl::Start( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 49 | const BidirectionalStreamRequestInfo* request_info, |
| 50 | const BoundNetLog& net_log, |
xunjieli | bcb0f86e | 2016-06-03 00:49:29 | [diff] [blame] | 51 | bool /*send_request_headers_automatically*/, |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 52 | BidirectionalStreamImpl::Delegate* delegate, |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 53 | std::unique_ptr<base::Timer> timer) { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 54 | DCHECK(!stream_); |
| 55 | DCHECK(timer); |
| 56 | |
| 57 | delegate_ = delegate; |
| 58 | timer_ = std::move(timer); |
| 59 | |
| 60 | if (!spdy_session_) { |
xunjieli | 707f895 | 2016-06-06 15:22:06 | [diff] [blame] | 61 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 62 | FROM_HERE, |
| 63 | base::Bind(&BidirectionalStreamSpdyImpl::NotifyError, |
| 64 | weak_factory_.GetWeakPtr(), ERR_CONNECTION_CLOSED)); |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 65 | return; |
| 66 | } |
| 67 | |
| 68 | request_info_ = request_info; |
| 69 | |
| 70 | int rv = stream_request_.StartRequest( |
| 71 | SPDY_BIDIRECTIONAL_STREAM, spdy_session_, request_info_->url, |
| 72 | request_info_->priority, net_log, |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 73 | base::Bind(&BidirectionalStreamSpdyImpl::OnStreamInitialized, |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 74 | weak_factory_.GetWeakPtr())); |
| 75 | if (rv != ERR_IO_PENDING) |
| 76 | OnStreamInitialized(rv); |
| 77 | } |
| 78 | |
xunjieli | bcb0f86e | 2016-06-03 00:49:29 | [diff] [blame] | 79 | void BidirectionalStreamSpdyImpl::SendRequestHeaders() { |
| 80 | // Request headers will be sent automatically. |
| 81 | NOTREACHED(); |
| 82 | } |
| 83 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 84 | int BidirectionalStreamSpdyImpl::ReadData(IOBuffer* buf, int buf_len) { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 85 | if (stream_) |
| 86 | DCHECK(!stream_->IsIdle()); |
| 87 | |
| 88 | DCHECK(buf); |
| 89 | DCHECK(buf_len); |
| 90 | DCHECK(!timer_->IsRunning()) << "There should be only one ReadData in flight"; |
| 91 | |
| 92 | // If there is data buffered, complete the IO immediately. |
| 93 | if (!read_data_queue_.IsEmpty()) { |
| 94 | return read_data_queue_.Dequeue(buf->data(), buf_len); |
| 95 | } else if (stream_closed_) { |
| 96 | return closed_stream_status_; |
| 97 | } |
| 98 | // Read will complete asynchronously and Delegate::OnReadCompleted will be |
| 99 | // called upon completion. |
| 100 | read_buffer_ = buf; |
| 101 | read_buffer_len_ = buf_len; |
| 102 | return ERR_IO_PENDING; |
| 103 | } |
| 104 | |
xunjieli | 2328a268 | 2016-05-16 19:38:25 | [diff] [blame] | 105 | void BidirectionalStreamSpdyImpl::SendData(const scoped_refptr<IOBuffer>& data, |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 106 | int length, |
| 107 | bool end_stream) { |
xunjieli | 707f895 | 2016-06-06 15:22:06 | [diff] [blame] | 108 | DCHECK(length > 0 || (length == 0 && end_stream)); |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 109 | |
xunjieli | 707f895 | 2016-06-06 15:22:06 | [diff] [blame] | 110 | if (!stream_) { |
| 111 | LOG(ERROR) << "Trying to send data after stream has been destroyed."; |
| 112 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 113 | FROM_HERE, base::Bind(&BidirectionalStreamSpdyImpl::NotifyError, |
| 114 | weak_factory_.GetWeakPtr(), ERR_UNEXPECTED)); |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | DCHECK(!stream_closed_); |
xunjieli | 2328a268 | 2016-05-16 19:38:25 | [diff] [blame] | 119 | stream_->SendData(data.get(), length, |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 120 | end_stream ? NO_MORE_DATA_TO_SEND : MORE_DATA_TO_SEND); |
| 121 | } |
| 122 | |
xunjieli | 07a42ce | 2016-04-26 20:05:31 | [diff] [blame] | 123 | void BidirectionalStreamSpdyImpl::SendvData( |
xunjieli | 2328a268 | 2016-05-16 19:38:25 | [diff] [blame] | 124 | const std::vector<scoped_refptr<IOBuffer>>& buffers, |
xunjieli | 07a42ce | 2016-04-26 20:05:31 | [diff] [blame] | 125 | const std::vector<int>& lengths, |
| 126 | bool end_stream) { |
xunjieli | 07a42ce | 2016-04-26 20:05:31 | [diff] [blame] | 127 | DCHECK_EQ(buffers.size(), lengths.size()); |
| 128 | |
xunjieli | 707f895 | 2016-06-06 15:22:06 | [diff] [blame] | 129 | if (!stream_) { |
| 130 | LOG(ERROR) << "Trying to send data after stream has been destroyed."; |
| 131 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 132 | FROM_HERE, base::Bind(&BidirectionalStreamSpdyImpl::NotifyError, |
| 133 | weak_factory_.GetWeakPtr(), ERR_UNEXPECTED)); |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | DCHECK(!stream_closed_); |
xunjieli | 07a42ce | 2016-04-26 20:05:31 | [diff] [blame] | 138 | int total_len = 0; |
| 139 | for (int len : lengths) { |
| 140 | total_len += len; |
| 141 | } |
| 142 | |
| 143 | pending_combined_buffer_ = new net::IOBuffer(total_len); |
| 144 | int len = 0; |
| 145 | // TODO(xunjieli): Get rid of extra copy. Coalesce headers and data frames. |
| 146 | for (size_t i = 0; i < buffers.size(); ++i) { |
| 147 | memcpy(pending_combined_buffer_->data() + len, buffers[i]->data(), |
| 148 | lengths[i]); |
| 149 | len += lengths[i]; |
| 150 | } |
| 151 | stream_->SendData(pending_combined_buffer_.get(), total_len, |
| 152 | end_stream ? NO_MORE_DATA_TO_SEND : MORE_DATA_TO_SEND); |
| 153 | } |
| 154 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 155 | NextProto BidirectionalStreamSpdyImpl::GetProtocol() const { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 156 | return negotiated_protocol_; |
| 157 | } |
| 158 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 159 | int64_t BidirectionalStreamSpdyImpl::GetTotalReceivedBytes() const { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 160 | if (stream_closed_) |
| 161 | return closed_stream_received_bytes_; |
| 162 | |
| 163 | if (!stream_) |
| 164 | return 0; |
| 165 | |
| 166 | return stream_->raw_received_bytes(); |
| 167 | } |
| 168 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 169 | int64_t BidirectionalStreamSpdyImpl::GetTotalSentBytes() const { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 170 | if (stream_closed_) |
| 171 | return closed_stream_sent_bytes_; |
| 172 | |
| 173 | if (!stream_) |
| 174 | return 0; |
| 175 | |
| 176 | return stream_->raw_sent_bytes(); |
| 177 | } |
| 178 | |
xunjieli | ba8de432 | 2016-09-20 21:57:54 | [diff] [blame^] | 179 | bool BidirectionalStreamSpdyImpl::GetLoadTimingInfo( |
| 180 | LoadTimingInfo* load_timing_info) const { |
| 181 | // TODO(xunjieli): Implement this crbug.com/648346 |
| 182 | return true; |
| 183 | } |
| 184 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 185 | void BidirectionalStreamSpdyImpl::OnRequestHeadersSent() { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 186 | DCHECK(stream_); |
| 187 | |
bnc | bca843ba | 2016-07-14 13:05:48 | [diff] [blame] | 188 | negotiated_protocol_ = kProtoHTTP2; |
xunjieli | 707f895 | 2016-06-06 15:22:06 | [diff] [blame] | 189 | if (delegate_) |
| 190 | delegate_->OnStreamReady(/*request_headers_sent=*/true); |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 191 | } |
| 192 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 193 | SpdyResponseHeadersStatus BidirectionalStreamSpdyImpl::OnResponseHeadersUpdated( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 194 | const SpdyHeaderBlock& response_headers) { |
| 195 | DCHECK(stream_); |
| 196 | |
xunjieli | 707f895 | 2016-06-06 15:22:06 | [diff] [blame] | 197 | if (delegate_) |
| 198 | delegate_->OnHeadersReceived(response_headers); |
| 199 | |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 200 | return RESPONSE_HEADERS_ARE_COMPLETE; |
| 201 | } |
| 202 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 203 | void BidirectionalStreamSpdyImpl::OnDataReceived( |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 204 | std::unique_ptr<SpdyBuffer> buffer) { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 205 | DCHECK(stream_); |
| 206 | DCHECK(!stream_closed_); |
| 207 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 208 | // If |buffer| is null, BidirectionalStreamSpdyImpl::OnClose will be invoked |
| 209 | // by SpdyStream to indicate the end of stream. |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 210 | if (!buffer) |
| 211 | return; |
| 212 | |
| 213 | // When buffer is consumed, SpdyStream::OnReadBufferConsumed will adjust |
| 214 | // recv window size accordingly. |
| 215 | read_data_queue_.Enqueue(std::move(buffer)); |
| 216 | if (read_buffer_) { |
| 217 | // Handing small chunks of data to the caller creates measurable overhead. |
| 218 | // So buffer data in short time-spans and send a single read notification. |
| 219 | ScheduleBufferedRead(); |
| 220 | } |
| 221 | } |
| 222 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 223 | void BidirectionalStreamSpdyImpl::OnDataSent() { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 224 | DCHECK(stream_); |
| 225 | DCHECK(!stream_closed_); |
| 226 | |
xunjieli | bcb0f86e | 2016-06-03 00:49:29 | [diff] [blame] | 227 | pending_combined_buffer_ = nullptr; |
xunjieli | 707f895 | 2016-06-06 15:22:06 | [diff] [blame] | 228 | if (delegate_) |
| 229 | delegate_->OnDataSent(); |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 230 | } |
| 231 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 232 | void BidirectionalStreamSpdyImpl::OnTrailers(const SpdyHeaderBlock& trailers) { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 233 | DCHECK(stream_); |
| 234 | DCHECK(!stream_closed_); |
| 235 | |
xunjieli | 707f895 | 2016-06-06 15:22:06 | [diff] [blame] | 236 | if (delegate_) |
| 237 | delegate_->OnTrailersReceived(trailers); |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 238 | } |
| 239 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 240 | void BidirectionalStreamSpdyImpl::OnClose(int status) { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 241 | DCHECK(stream_); |
| 242 | |
| 243 | stream_closed_ = true; |
| 244 | closed_stream_status_ = status; |
| 245 | closed_stream_received_bytes_ = stream_->raw_received_bytes(); |
| 246 | closed_stream_sent_bytes_ = stream_->raw_sent_bytes(); |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 247 | |
| 248 | if (status != OK) { |
xunjieli | 707f895 | 2016-06-06 15:22:06 | [diff] [blame] | 249 | NotifyError(status); |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 250 | return; |
| 251 | } |
xunjieli | 707f895 | 2016-06-06 15:22:06 | [diff] [blame] | 252 | ResetStream(); |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 253 | // Complete any remaining read, as all data has been buffered. |
| 254 | // If user has not called ReadData (i.e |read_buffer_| is nullptr), this will |
| 255 | // do nothing. |
| 256 | timer_->Stop(); |
| 257 | DoBufferedRead(); |
| 258 | } |
| 259 | |
xunjieli | bcb0f86e | 2016-06-03 00:49:29 | [diff] [blame] | 260 | int BidirectionalStreamSpdyImpl::SendRequestHeadersHelper() { |
bnc | 1d1d8646 | 2016-07-20 16:51:55 | [diff] [blame] | 261 | SpdyHeaderBlock headers; |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 262 | HttpRequestInfo http_request_info; |
| 263 | http_request_info.url = request_info_->url; |
| 264 | http_request_info.method = request_info_->method; |
| 265 | http_request_info.extra_headers = request_info_->extra_headers; |
| 266 | |
| 267 | CreateSpdyHeadersFromHttpRequest( |
bnc | 1d1d8646 | 2016-07-20 16:51:55 | [diff] [blame] | 268 | http_request_info, http_request_info.extra_headers, true, &headers); |
xunjieli | bcb0f86e | 2016-06-03 00:49:29 | [diff] [blame] | 269 | return stream_->SendRequestHeaders(std::move(headers), |
| 270 | request_info_->end_stream_on_headers |
| 271 | ? NO_MORE_DATA_TO_SEND |
| 272 | : MORE_DATA_TO_SEND); |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 273 | } |
| 274 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 275 | void BidirectionalStreamSpdyImpl::OnStreamInitialized(int rv) { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 276 | DCHECK_NE(ERR_IO_PENDING, rv); |
| 277 | if (rv == OK) { |
| 278 | stream_ = stream_request_.ReleaseStream(); |
| 279 | stream_->SetDelegate(this); |
xunjieli | bcb0f86e | 2016-06-03 00:49:29 | [diff] [blame] | 280 | rv = SendRequestHeadersHelper(); |
| 281 | if (rv == OK) { |
| 282 | OnRequestHeadersSent(); |
| 283 | return; |
| 284 | } else if (rv == ERR_IO_PENDING) { |
| 285 | return; |
| 286 | } |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 287 | } |
xunjieli | 707f895 | 2016-06-06 15:22:06 | [diff] [blame] | 288 | NotifyError(rv); |
| 289 | } |
| 290 | |
| 291 | void BidirectionalStreamSpdyImpl::NotifyError(int rv) { |
| 292 | ResetStream(); |
| 293 | if (delegate_) { |
| 294 | BidirectionalStreamImpl::Delegate* delegate = delegate_; |
| 295 | delegate_ = nullptr; |
| 296 | // Cancel any pending callback. |
| 297 | weak_factory_.InvalidateWeakPtrs(); |
| 298 | delegate->OnFailed(rv); |
| 299 | // |this| can be null when returned from delegate. |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | void BidirectionalStreamSpdyImpl::ResetStream() { |
| 304 | if (!stream_) |
| 305 | return; |
| 306 | if (!stream_->IsClosed()) { |
| 307 | // This sends a RST to the remote. |
| 308 | stream_->DetachDelegate(); |
| 309 | DCHECK(!stream_); |
| 310 | } else { |
| 311 | // Stream is already closed, so it is not legal to call DetachDelegate. |
| 312 | stream_.reset(); |
| 313 | } |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 314 | } |
| 315 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 316 | void BidirectionalStreamSpdyImpl::ScheduleBufferedRead() { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 317 | // If there is already a scheduled DoBufferedRead, don't issue |
| 318 | // another one. Mark that we have received more data and return. |
| 319 | if (timer_->IsRunning()) { |
| 320 | more_read_data_pending_ = true; |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | more_read_data_pending_ = false; |
| 325 | timer_->Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kBufferTimeMs), |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 326 | base::Bind(&BidirectionalStreamSpdyImpl::DoBufferedRead, |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 327 | weak_factory_.GetWeakPtr())); |
| 328 | } |
| 329 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 330 | void BidirectionalStreamSpdyImpl::DoBufferedRead() { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 331 | DCHECK(!timer_->IsRunning()); |
| 332 | // Check to see that the stream has not errored out. |
| 333 | DCHECK(stream_ || stream_closed_); |
| 334 | DCHECK(!stream_closed_ || closed_stream_status_ == OK); |
| 335 | |
| 336 | // When |more_read_data_pending_| is true, it means that more data has arrived |
| 337 | // since started waiting. Wait a little longer and continue to buffer. |
| 338 | if (more_read_data_pending_ && ShouldWaitForMoreBufferedData()) { |
| 339 | ScheduleBufferedRead(); |
| 340 | return; |
| 341 | } |
| 342 | |
| 343 | int rv = 0; |
| 344 | if (read_buffer_) { |
| 345 | rv = ReadData(read_buffer_.get(), read_buffer_len_); |
| 346 | DCHECK_NE(ERR_IO_PENDING, rv); |
| 347 | read_buffer_ = nullptr; |
| 348 | read_buffer_len_ = 0; |
xunjieli | 707f895 | 2016-06-06 15:22:06 | [diff] [blame] | 349 | if (delegate_) |
| 350 | delegate_->OnDataRead(rv); |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
xunjieli | 5749218c | 2016-03-22 16:43:06 | [diff] [blame] | 354 | bool BidirectionalStreamSpdyImpl::ShouldWaitForMoreBufferedData() const { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 355 | if (stream_closed_) |
| 356 | return false; |
| 357 | DCHECK_GT(read_buffer_len_, 0); |
| 358 | return read_data_queue_.GetTotalSize() < |
| 359 | static_cast<size_t>(read_buffer_len_); |
| 360 | } |
| 361 | |
| 362 | } // namespace net |