| 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/spdy/spdy_stream.h" | 5 #include "net/spdy/spdy_stream.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 send_time_ = base::TimeTicks::Now(); | 130 send_time_ = base::TimeTicks::Now(); |
| 131 return frame; | 131 return frame; |
| 132 } else { | 132 } else { |
| 133 CHECK(!cancelled()); | 133 CHECK(!cancelled()); |
| 134 // We must need to write stream data. | 134 // We must need to write stream data. |
| 135 // Until the headers have been completely sent, we can not be sure | 135 // Until the headers have been completely sent, we can not be sure |
| 136 // that our stream_id is correct. | 136 // that our stream_id is correct. |
| 137 DCHECK_GT(io_state_, STATE_SEND_HEADERS_COMPLETE); | 137 DCHECK_GT(io_state_, STATE_SEND_HEADERS_COMPLETE); |
| 138 DCHECK_GT(stream_id_, 0u); | 138 DCHECK_GT(stream_id_, 0u); |
| 139 DCHECK(!pending_data_frames_.empty()); | 139 DCHECK(!pending_data_frames_.empty()); |
| 140 SpdyFrame* frame = pending_data_frames_.front(); | 140 |
| 141 PendingFrame frame = pending_data_frames_.front(); |
| 142 SpdyHeaderBlock* headers = frame.first; |
| 143 SpdyDataFrame* data_frame = frame.second; |
| 141 pending_data_frames_.pop_front(); | 144 pending_data_frames_.pop_front(); |
| 142 return frame; | 145 |
| 146 // |frame| should have one valid data. |
| 147 DCHECK(!headers != !data_frame); |
| 148 |
| 149 // Send queued data frame. |
| 150 if (data_frame) |
| 151 return data_frame; |
| 152 |
| 153 // Create actual HEADERS frame just in time because it depends on |
| 154 // compression context and should not be reordered after the creation. |
| 155 SpdyFrame* header_frame = session_->CreateHeadersFrame( |
| 156 stream_id_, *headers, SpdyControlFlags()); |
| 157 delete headers; |
| 158 return header_frame; |
| 143 } | 159 } |
| 144 } | 160 } |
| 145 | 161 |
| 146 SpdyStream::~SpdyStream() { | 162 SpdyStream::~SpdyStream() { |
| 147 UpdateHistograms(); | 163 UpdateHistograms(); |
| 148 while (!pending_data_frames_.empty()) { | 164 while (!pending_data_frames_.empty()) { |
| 149 SpdyFrame* frame = pending_data_frames_.back(); | 165 PendingFrame frame = pending_data_frames_.back(); |
| 166 SpdyHeaderBlock* headers = frame.first; |
| 167 SpdyDataFrame* data_frame = frame.second; |
| 150 pending_data_frames_.pop_back(); | 168 pending_data_frames_.pop_back(); |
| 151 delete frame; | 169 if (headers) |
| 170 delete headers; |
| 171 if (data_frame) |
| 172 delete data_frame; |
| 152 } | 173 } |
| 153 } | 174 } |
| 154 | 175 |
| 155 void SpdyStream::SetDelegate(Delegate* delegate) { | 176 void SpdyStream::SetDelegate(Delegate* delegate) { |
| 156 CHECK(delegate); | 177 CHECK(delegate); |
| 157 delegate_ = delegate; | 178 delegate_ = delegate; |
| 158 | 179 |
| 159 if (pushed_) { | 180 if (pushed_) { |
| 160 CHECK(response_received()); | 181 CHECK(response_received()); |
| 161 MessageLoop::current()->PostTask( | 182 MessageLoop::current()->PostTask( |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 send_time_ = base::TimeTicks::Now(); | 569 send_time_ = base::TimeTicks::Now(); |
| 549 DCHECK(!has_upload_data_); | 570 DCHECK(!has_upload_data_); |
| 550 DCHECK(response_received()); | 571 DCHECK(response_received()); |
| 551 return ERR_IO_PENDING; | 572 return ERR_IO_PENDING; |
| 552 } | 573 } |
| 553 CHECK_EQ(STATE_NONE, io_state_); | 574 CHECK_EQ(STATE_NONE, io_state_); |
| 554 io_state_ = STATE_GET_DOMAIN_BOUND_CERT; | 575 io_state_ = STATE_GET_DOMAIN_BOUND_CERT; |
| 555 return DoLoop(OK); | 576 return DoLoop(OK); |
| 556 } | 577 } |
| 557 | 578 |
| 558 int SpdyStream::WriteStreamData(IOBuffer* data, int length, | 579 int SpdyStream::WriteHeaders(SpdyHeaderBlock* headers) { |
| 580 // Until the first headers by SYN_STREAM have been completely sent, we can |
| 581 // not be sure that our stream_id is correct. |
| 582 DCHECK_GT(io_state_, STATE_SEND_HEADERS_COMPLETE); |
| 583 CHECK_GT(stream_id_, 0u); |
| 584 |
| 585 pending_data_frames_.push_back(PendingFrame(headers, NULL)); |
| 586 |
| 587 SetHasWriteAvailable(); |
| 588 return ERR_IO_PENDING; |
| 589 } |
| 590 |
| 591 int SpdyStream::WriteStreamData(IOBuffer* data, |
| 592 int length, |
| 559 SpdyDataFlags flags) { | 593 SpdyDataFlags flags) { |
| 560 // Until the headers have been completely sent, we can not be sure | 594 // Until the headers have been completely sent, we can not be sure |
| 561 // that our stream_id is correct. | 595 // that our stream_id is correct. |
| 562 DCHECK_GT(io_state_, STATE_SEND_HEADERS_COMPLETE); | 596 DCHECK_GT(io_state_, STATE_SEND_HEADERS_COMPLETE); |
| 563 CHECK_GT(stream_id_, 0u); | 597 CHECK_GT(stream_id_, 0u); |
| 564 | 598 |
| 565 pending_data_frames_.push_back( | 599 SpdyDataFrame* frame = session_->CreateDataFrame( |
| 566 session_->CreateDataFrame(stream_id_, data, length, flags)); | 600 stream_id_, data, length, flags); |
| 567 | 601 if (frame) { |
| 568 SetHasWriteAvailable(); | 602 pending_data_frames_.push_back(PendingFrame(NULL, frame)); |
| 603 SetHasWriteAvailable(); |
| 604 } |
| 569 return ERR_IO_PENDING; | 605 return ERR_IO_PENDING; |
| 570 } | 606 } |
| 571 | 607 |
| 572 bool SpdyStream::GetSSLInfo(SSLInfo* ssl_info, | 608 bool SpdyStream::GetSSLInfo(SSLInfo* ssl_info, |
| 573 bool* was_npn_negotiated, | 609 bool* was_npn_negotiated, |
| 574 NextProto* protocol_negotiated) { | 610 NextProto* protocol_negotiated) { |
| 575 return session_->GetSSLInfo( | 611 return session_->GetSSLInfo( |
| 576 ssl_info, was_npn_negotiated, protocol_negotiated); | 612 ssl_info, was_npn_negotiated, protocol_negotiated); |
| 577 } | 613 } |
| 578 | 614 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 UMA_HISTOGRAM_TIMES("Net.SpdyStreamDownloadTime", | 834 UMA_HISTOGRAM_TIMES("Net.SpdyStreamDownloadTime", |
| 799 recv_last_byte_time_ - recv_first_byte_time_); | 835 recv_last_byte_time_ - recv_first_byte_time_); |
| 800 UMA_HISTOGRAM_TIMES("Net.SpdyStreamTime", | 836 UMA_HISTOGRAM_TIMES("Net.SpdyStreamTime", |
| 801 recv_last_byte_time_ - send_time_); | 837 recv_last_byte_time_ - send_time_); |
| 802 | 838 |
| 803 UMA_HISTOGRAM_COUNTS("Net.SpdySendBytes", send_bytes_); | 839 UMA_HISTOGRAM_COUNTS("Net.SpdySendBytes", send_bytes_); |
| 804 UMA_HISTOGRAM_COUNTS("Net.SpdyRecvBytes", recv_bytes_); | 840 UMA_HISTOGRAM_COUNTS("Net.SpdyRecvBytes", recv_bytes_); |
| 805 } | 841 } |
| 806 | 842 |
| 807 } // namespace net | 843 } // namespace net |
| OLD | NEW |