OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/quic_http_stream.h" | 5 #include "net/quic/quic_http_stream.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 session_(session), | 30 session_(session), |
31 session_error_(OK), | 31 session_error_(OK), |
32 was_handshake_confirmed_(session->IsCryptoHandshakeConfirmed()), | 32 was_handshake_confirmed_(session->IsCryptoHandshakeConfirmed()), |
33 stream_(nullptr), | 33 stream_(nullptr), |
34 request_info_(nullptr), | 34 request_info_(nullptr), |
35 request_body_stream_(nullptr), | 35 request_body_stream_(nullptr), |
36 priority_(MINIMUM_PRIORITY), | 36 priority_(MINIMUM_PRIORITY), |
37 response_info_(nullptr), | 37 response_info_(nullptr), |
38 response_status_(OK), | 38 response_status_(OK), |
39 response_headers_received_(false), | 39 response_headers_received_(false), |
| 40 headers_bytes_received_(0), |
| 41 headers_bytes_sent_(0), |
40 closed_stream_received_bytes_(0), | 42 closed_stream_received_bytes_(0), |
41 closed_stream_sent_bytes_(0), | 43 closed_stream_sent_bytes_(0), |
42 user_buffer_len_(0), | 44 user_buffer_len_(0), |
43 weak_factory_(this) { | 45 weak_factory_(this) { |
44 DCHECK(session_); | 46 DCHECK(session_); |
45 session_->AddObserver(this); | 47 session_->AddObserver(this); |
46 } | 48 } |
47 | 49 |
48 QuicHttpStream::~QuicHttpStream() { | 50 QuicHttpStream::~QuicHttpStream() { |
49 Close(false); | 51 Close(false); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 void QuicHttpStream::SetConnectionReused() { | 236 void QuicHttpStream::SetConnectionReused() { |
235 // QUIC doesn't need an indicator here. | 237 // QUIC doesn't need an indicator here. |
236 } | 238 } |
237 | 239 |
238 bool QuicHttpStream::CanReuseConnection() const { | 240 bool QuicHttpStream::CanReuseConnection() const { |
239 // QUIC streams aren't considered reusable. | 241 // QUIC streams aren't considered reusable. |
240 return false; | 242 return false; |
241 } | 243 } |
242 | 244 |
243 int64_t QuicHttpStream::GetTotalReceivedBytes() const { | 245 int64_t QuicHttpStream::GetTotalReceivedBytes() const { |
244 // TODO(sclittle): Currently, this only includes response body bytes. Change | 246 // TODO(sclittle): Currently, this only includes headers and response body |
245 // this to include headers and QUIC overhead as well. | 247 // bytes. Change this to include QUIC overhead as well. |
| 248 int64_t total_received_bytes = headers_bytes_received_; |
246 if (stream_) { | 249 if (stream_) { |
247 return stream_->stream_bytes_read(); | 250 total_received_bytes += stream_->stream_bytes_read(); |
| 251 } else { |
| 252 total_received_bytes += closed_stream_received_bytes_; |
248 } | 253 } |
249 | 254 return total_received_bytes; |
250 return closed_stream_received_bytes_; | |
251 } | 255 } |
252 | 256 |
253 int64_t QuicHttpStream::GetTotalSentBytes() const { | 257 int64_t QuicHttpStream::GetTotalSentBytes() const { |
254 // TODO(sclittle): Currently, this only includes request body bytes. Change | 258 // TODO(sclittle): Currently, this only includes request headers and body |
255 // this to include headers and QUIC overhead as well. | 259 // bytes. Change this to include QUIC overhead as well. |
| 260 int64_t total_sent_bytes = headers_bytes_sent_; |
256 if (stream_) { | 261 if (stream_) { |
257 return stream_->stream_bytes_written(); | 262 total_sent_bytes += stream_->stream_bytes_written(); |
| 263 } else { |
| 264 total_sent_bytes += closed_stream_sent_bytes_; |
258 } | 265 } |
259 | 266 return total_sent_bytes; |
260 return closed_stream_sent_bytes_; | |
261 } | 267 } |
262 | 268 |
263 bool QuicHttpStream::GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const { | 269 bool QuicHttpStream::GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const { |
264 // TODO(mmenke): Figure out what to do here. | 270 // TODO(mmenke): Figure out what to do here. |
265 return true; | 271 return true; |
266 } | 272 } |
267 | 273 |
268 void QuicHttpStream::GetSSLInfo(SSLInfo* ssl_info) { | 274 void QuicHttpStream::GetSSLInfo(SSLInfo* ssl_info) { |
269 DCHECK(stream_); | 275 DCHECK(stream_); |
270 session_->GetSSLInfo(ssl_info); | 276 session_->GetSSLInfo(ssl_info); |
271 } | 277 } |
272 | 278 |
273 void QuicHttpStream::GetSSLCertRequestInfo( | 279 void QuicHttpStream::GetSSLCertRequestInfo( |
274 SSLCertRequestInfo* cert_request_info) { | 280 SSLCertRequestInfo* cert_request_info) { |
275 DCHECK(stream_); | 281 DCHECK(stream_); |
276 NOTIMPLEMENTED(); | 282 NOTIMPLEMENTED(); |
277 } | 283 } |
278 | 284 |
279 void QuicHttpStream::Drain(HttpNetworkSession* session) { | 285 void QuicHttpStream::Drain(HttpNetworkSession* session) { |
280 NOTREACHED(); | 286 NOTREACHED(); |
281 Close(false); | 287 Close(false); |
282 delete this; | 288 delete this; |
283 } | 289 } |
284 | 290 |
285 void QuicHttpStream::SetPriority(RequestPriority priority) { | 291 void QuicHttpStream::SetPriority(RequestPriority priority) { |
286 priority_ = priority; | 292 priority_ = priority; |
287 } | 293 } |
288 | 294 |
289 void QuicHttpStream::OnHeadersAvailable(const SpdyHeaderBlock& headers) { | 295 void QuicHttpStream::OnHeadersAvailable(const SpdyHeaderBlock& headers, |
| 296 size_t frame_len) { |
| 297 headers_bytes_received_ += frame_len; |
| 298 |
290 int rv = ProcessResponseHeaders(headers); | 299 int rv = ProcessResponseHeaders(headers); |
291 if (rv != ERR_IO_PENDING && !callback_.is_null()) { | 300 if (rv != ERR_IO_PENDING && !callback_.is_null()) { |
292 DoCallback(rv); | 301 DoCallback(rv); |
293 } | 302 } |
294 } | 303 } |
295 | 304 |
296 void QuicHttpStream::OnDataAvailable() { | 305 void QuicHttpStream::OnDataAvailable() { |
297 if (callback_.is_null()) { | 306 if (callback_.is_null()) { |
298 // Data is available, but can't be delivered | 307 // Data is available, but can't be delivered |
299 return; | 308 return; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 priority_)); | 424 priority_)); |
416 // Also log to the QuicSession's net log. | 425 // Also log to the QuicSession's net log. |
417 stream_->net_log().AddEvent( | 426 stream_->net_log().AddEvent( |
418 NetLog::TYPE_QUIC_HTTP_STREAM_SEND_REQUEST_HEADERS, | 427 NetLog::TYPE_QUIC_HTTP_STREAM_SEND_REQUEST_HEADERS, |
419 base::Bind(&QuicRequestNetLogCallback, stream_->id(), &request_headers_, | 428 base::Bind(&QuicRequestNetLogCallback, stream_->id(), &request_headers_, |
420 priority_)); | 429 priority_)); |
421 | 430 |
422 bool has_upload_data = request_body_stream_ != nullptr; | 431 bool has_upload_data = request_body_stream_ != nullptr; |
423 | 432 |
424 next_state_ = STATE_SEND_HEADERS_COMPLETE; | 433 next_state_ = STATE_SEND_HEADERS_COMPLETE; |
425 int rv = stream_->WriteHeaders(request_headers_, !has_upload_data, nullptr); | 434 size_t frame_len = |
| 435 stream_->WriteHeaders(request_headers_, !has_upload_data, nullptr); |
| 436 headers_bytes_sent_ += frame_len; |
| 437 |
426 request_headers_.clear(); | 438 request_headers_.clear(); |
427 return rv; | 439 return static_cast<int>(frame_len); |
428 } | 440 } |
429 | 441 |
430 int QuicHttpStream::DoSendHeadersComplete(int rv) { | 442 int QuicHttpStream::DoSendHeadersComplete(int rv) { |
431 if (rv < 0) | 443 if (rv < 0) |
432 return rv; | 444 return rv; |
433 | 445 |
434 next_state_ = request_body_stream_ ? | 446 next_state_ = request_body_stream_ ? |
435 STATE_READ_REQUEST_BODY : STATE_OPEN; | 447 STATE_READ_REQUEST_BODY : STATE_OPEN; |
436 | 448 |
437 return OK; | 449 return OK; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); | 555 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); |
544 stream_ = nullptr; | 556 stream_ = nullptr; |
545 | 557 |
546 // If |request_body_stream_| is non-NULL, Reset it, to abort any in progress | 558 // If |request_body_stream_| is non-NULL, Reset it, to abort any in progress |
547 // read. | 559 // read. |
548 if (request_body_stream_) | 560 if (request_body_stream_) |
549 request_body_stream_->Reset(); | 561 request_body_stream_->Reset(); |
550 } | 562 } |
551 | 563 |
552 } // namespace net | 564 } // namespace net |
OLD | NEW |