| 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 closed_has_load_timing_info_(false), |
| 41 weak_factory_(this) {} | 42 weak_factory_(this) {} |
| 42 | 43 |
| 43 BidirectionalStreamSpdyImpl::~BidirectionalStreamSpdyImpl() { | 44 BidirectionalStreamSpdyImpl::~BidirectionalStreamSpdyImpl() { |
| 44 // Sends a RST to the remote if the stream is destroyed before it completes. | 45 // Sends a RST to the remote if the stream is destroyed before it completes. |
| 45 ResetStream(); | 46 ResetStream(); |
| 46 } | 47 } |
| 47 | 48 |
| 48 void BidirectionalStreamSpdyImpl::Start( | 49 void BidirectionalStreamSpdyImpl::Start( |
| 49 const BidirectionalStreamRequestInfo* request_info, | 50 const BidirectionalStreamRequestInfo* request_info, |
| 50 const BoundNetLog& net_log, | 51 const BoundNetLog& net_log, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 return closed_stream_sent_bytes_; | 172 return closed_stream_sent_bytes_; |
| 172 | 173 |
| 173 if (!stream_) | 174 if (!stream_) |
| 174 return 0; | 175 return 0; |
| 175 | 176 |
| 176 return stream_->raw_sent_bytes(); | 177 return stream_->raw_sent_bytes(); |
| 177 } | 178 } |
| 178 | 179 |
| 179 bool BidirectionalStreamSpdyImpl::GetLoadTimingInfo( | 180 bool BidirectionalStreamSpdyImpl::GetLoadTimingInfo( |
| 180 LoadTimingInfo* load_timing_info) const { | 181 LoadTimingInfo* load_timing_info) const { |
| 181 // TODO(xunjieli): Implement this crbug.com/648346 | 182 if (stream_closed_) { |
| 182 return true; | 183 if (!closed_has_load_timing_info_) |
| 184 return false; |
| 185 *load_timing_info = closed_load_timing_info_; |
| 186 return true; |
| 187 } |
| 188 |
| 189 // If |stream_| isn't created or has ID 0, return false. This is to match |
| 190 // the implementation in SpdyHttpStream. |
| 191 if (!stream_ || stream_->stream_id() == 0) |
| 192 return false; |
| 193 |
| 194 return stream_->GetLoadTimingInfo(load_timing_info); |
| 183 } | 195 } |
| 184 | 196 |
| 185 void BidirectionalStreamSpdyImpl::OnRequestHeadersSent() { | 197 void BidirectionalStreamSpdyImpl::OnRequestHeadersSent() { |
| 186 DCHECK(stream_); | 198 DCHECK(stream_); |
| 187 | 199 |
| 188 negotiated_protocol_ = kProtoHTTP2; | 200 negotiated_protocol_ = kProtoHTTP2; |
| 189 if (delegate_) | 201 if (delegate_) |
| 190 delegate_->OnStreamReady(/*request_headers_sent=*/true); | 202 delegate_->OnStreamReady(/*request_headers_sent=*/true); |
| 191 } | 203 } |
| 192 | 204 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 delegate_->OnTrailersReceived(trailers); | 249 delegate_->OnTrailersReceived(trailers); |
| 238 } | 250 } |
| 239 | 251 |
| 240 void BidirectionalStreamSpdyImpl::OnClose(int status) { | 252 void BidirectionalStreamSpdyImpl::OnClose(int status) { |
| 241 DCHECK(stream_); | 253 DCHECK(stream_); |
| 242 | 254 |
| 243 stream_closed_ = true; | 255 stream_closed_ = true; |
| 244 closed_stream_status_ = status; | 256 closed_stream_status_ = status; |
| 245 closed_stream_received_bytes_ = stream_->raw_received_bytes(); | 257 closed_stream_received_bytes_ = stream_->raw_received_bytes(); |
| 246 closed_stream_sent_bytes_ = stream_->raw_sent_bytes(); | 258 closed_stream_sent_bytes_ = stream_->raw_sent_bytes(); |
| 259 closed_has_load_timing_info_ = |
| 260 stream_->GetLoadTimingInfo(&closed_load_timing_info_); |
| 247 | 261 |
| 248 if (status != OK) { | 262 if (status != OK) { |
| 249 NotifyError(status); | 263 NotifyError(status); |
| 250 return; | 264 return; |
| 251 } | 265 } |
| 252 ResetStream(); | 266 ResetStream(); |
| 253 // Complete any remaining read, as all data has been buffered. | 267 // 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 | 268 // If user has not called ReadData (i.e |read_buffer_| is nullptr), this will |
| 255 // do nothing. | 269 // do nothing. |
| 256 timer_->Stop(); | 270 timer_->Stop(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 | 367 |
| 354 bool BidirectionalStreamSpdyImpl::ShouldWaitForMoreBufferedData() const { | 368 bool BidirectionalStreamSpdyImpl::ShouldWaitForMoreBufferedData() const { |
| 355 if (stream_closed_) | 369 if (stream_closed_) |
| 356 return false; | 370 return false; |
| 357 DCHECK_GT(read_buffer_len_, 0); | 371 DCHECK_GT(read_buffer_len_, 0); |
| 358 return read_data_queue_.GetTotalSize() < | 372 return read_data_queue_.GetTotalSize() < |
| 359 static_cast<size_t>(read_buffer_len_); | 373 static_cast<size_t>(read_buffer_len_); |
| 360 } | 374 } |
| 361 | 375 |
| 362 } // namespace net | 376 } // namespace net |
| OLD | NEW |