| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 // We must need to write stream data. | 135 // We must need to write stream data. |
| 136 // Until the headers have been completely sent, we can not be sure | 136 // Until the headers have been completely sent, we can not be sure |
| 137 // that our stream_id is correct. | 137 // that our stream_id is correct. |
| 138 DCHECK_GT(io_state_, STATE_SEND_HEADERS_COMPLETE); | 138 DCHECK_GT(io_state_, STATE_SEND_HEADERS_COMPLETE); |
| 139 DCHECK_GT(stream_id_, 0u); | 139 DCHECK_GT(stream_id_, 0u); |
| 140 DCHECK(!pending_frames_.empty()); | 140 DCHECK(!pending_frames_.empty()); |
| 141 | 141 |
| 142 PendingFrame frame = pending_frames_.front(); | 142 PendingFrame frame = pending_frames_.front(); |
| 143 pending_frames_.pop_front(); | 143 pending_frames_.pop_front(); |
| 144 | 144 |
| 145 waiting_completions_.push_back(frame.type); |
| 146 |
| 145 if (frame.type == TYPE_DATA) { | 147 if (frame.type == TYPE_DATA) { |
| 146 // Send queued data frame. | 148 // Send queued data frame. |
| 147 return frame.data_frame; | 149 return frame.data_frame; |
| 148 } else { | 150 } else { |
| 149 DCHECK(frame.type == TYPE_HEADER); | 151 DCHECK(frame.type == TYPE_HEADERS); |
| 150 // Create actual HEADERS frame just in time because it depends on | 152 // Create actual HEADERS frame just in time because it depends on |
| 151 // compression context and should not be reordered after the creation. | 153 // compression context and should not be reordered after the creation. |
| 152 SpdyFrame* header_frame = session_->CreateHeadersFrame( | 154 SpdyFrame* header_frame = session_->CreateHeadersFrame( |
| 153 stream_id_, *frame.header_block, SpdyControlFlags()); | 155 stream_id_, *frame.header_block, SpdyControlFlags()); |
| 154 delete frame.header_block; | 156 delete frame.header_block; |
| 155 return header_frame; | 157 return header_frame; |
| 156 } | 158 } |
| 157 } | 159 } |
| 158 NOTREACHED(); | 160 NOTREACHED(); |
| 159 } | 161 } |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 return DoLoop(OK); | 584 return DoLoop(OK); |
| 583 } | 585 } |
| 584 | 586 |
| 585 int SpdyStream::WriteHeaders(SpdyHeaderBlock* headers) { | 587 int SpdyStream::WriteHeaders(SpdyHeaderBlock* headers) { |
| 586 // Until the first headers by SYN_STREAM have been completely sent, we can | 588 // Until the first headers by SYN_STREAM have been completely sent, we can |
| 587 // not be sure that our stream_id is correct. | 589 // not be sure that our stream_id is correct. |
| 588 DCHECK_GT(io_state_, STATE_SEND_HEADERS_COMPLETE); | 590 DCHECK_GT(io_state_, STATE_SEND_HEADERS_COMPLETE); |
| 589 CHECK_GT(stream_id_, 0u); | 591 CHECK_GT(stream_id_, 0u); |
| 590 | 592 |
| 591 PendingFrame frame; | 593 PendingFrame frame; |
| 592 frame.type = TYPE_HEADER; | 594 frame.type = TYPE_HEADERS; |
| 593 frame.header_block = headers; | 595 frame.header_block = headers; |
| 594 pending_frames_.push_back(frame); | 596 pending_frames_.push_back(frame); |
| 595 | 597 |
| 596 SetHasWriteAvailable(); | 598 SetHasWriteAvailable(); |
| 597 return ERR_IO_PENDING; | 599 return ERR_IO_PENDING; |
| 598 } | 600 } |
| 599 | 601 |
| 600 int SpdyStream::WriteStreamData(IOBuffer* data, | 602 int SpdyStream::WriteStreamData(IOBuffer* data, |
| 601 int length, | 603 int length, |
| 602 SpdyDataFlags flags) { | 604 SpdyDataFlags flags) { |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 result = delegate_->OnSendBodyComplete(result, &eof); | 826 result = delegate_->OnSendBodyComplete(result, &eof); |
| 825 if (!eof) | 827 if (!eof) |
| 826 io_state_ = STATE_SEND_BODY; | 828 io_state_ = STATE_SEND_BODY; |
| 827 else | 829 else |
| 828 io_state_ = STATE_WAITING_FOR_RESPONSE; | 830 io_state_ = STATE_WAITING_FOR_RESPONSE; |
| 829 | 831 |
| 830 return result; | 832 return result; |
| 831 } | 833 } |
| 832 | 834 |
| 833 int SpdyStream::DoOpen(int result) { | 835 int SpdyStream::DoOpen(int result) { |
| 834 if (delegate_) | 836 if (delegate_) { |
| 835 delegate_->OnDataSent(result); | 837 FrameType type = waiting_completions_.front(); |
| 838 waiting_completions_.pop_front(); |
| 839 if (type == TYPE_DATA) { |
| 840 delegate_->OnDataSent(result); |
| 841 } else { |
| 842 DCHECK(type == TYPE_HEADERS); |
| 843 delegate_->OnHeadersSent(); |
| 844 } |
| 845 } |
| 836 io_state_ = STATE_OPEN; | 846 io_state_ = STATE_OPEN; |
| 837 return result; | 847 return result; |
| 838 } | 848 } |
| 839 | 849 |
| 840 void SpdyStream::UpdateHistograms() { | 850 void SpdyStream::UpdateHistograms() { |
| 841 // We need all timers to be filled in, otherwise metrics can be bogus. | 851 // We need all timers to be filled in, otherwise metrics can be bogus. |
| 842 if (send_time_.is_null() || recv_first_byte_time_.is_null() || | 852 if (send_time_.is_null() || recv_first_byte_time_.is_null() || |
| 843 recv_last_byte_time_.is_null()) | 853 recv_last_byte_time_.is_null()) |
| 844 return; | 854 return; |
| 845 | 855 |
| 846 UMA_HISTOGRAM_TIMES("Net.SpdyStreamTimeToFirstByte", | 856 UMA_HISTOGRAM_TIMES("Net.SpdyStreamTimeToFirstByte", |
| 847 recv_first_byte_time_ - send_time_); | 857 recv_first_byte_time_ - send_time_); |
| 848 UMA_HISTOGRAM_TIMES("Net.SpdyStreamDownloadTime", | 858 UMA_HISTOGRAM_TIMES("Net.SpdyStreamDownloadTime", |
| 849 recv_last_byte_time_ - recv_first_byte_time_); | 859 recv_last_byte_time_ - recv_first_byte_time_); |
| 850 UMA_HISTOGRAM_TIMES("Net.SpdyStreamTime", | 860 UMA_HISTOGRAM_TIMES("Net.SpdyStreamTime", |
| 851 recv_last_byte_time_ - send_time_); | 861 recv_last_byte_time_ - send_time_); |
| 852 | 862 |
| 853 UMA_HISTOGRAM_COUNTS("Net.SpdySendBytes", send_bytes_); | 863 UMA_HISTOGRAM_COUNTS("Net.SpdySendBytes", send_bytes_); |
| 854 UMA_HISTOGRAM_COUNTS("Net.SpdyRecvBytes", recv_bytes_); | 864 UMA_HISTOGRAM_COUNTS("Net.SpdyRecvBytes", recv_bytes_); |
| 855 } | 865 } |
| 856 | 866 |
| 857 } // namespace net | 867 } // namespace net |
| OLD | NEW |