Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(872)

Side by Side Diff: net/spdy/spdy_stream.cc

Issue 10810069: SPDY: Add WriteHeaders interface to SpdySession and SpdyStream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: spdy3 Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 stream_id_, priority_, slot_, flags, *request_); 129 stream_id_, priority_, slot_, flags, *request_);
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_frames_.empty());
140 SpdyFrame* frame = pending_data_frames_.front(); 140
141 pending_data_frames_.pop_front(); 141 PendingFrame frame = pending_frames_.front();
142 return frame; 142 pending_frames_.pop_front();
143
144 // Send queued data frame.
145 if (frame.type == TYPE_DATA)
Ryan Hamilton 2012/08/02 16:32:23 This code is much cleaner now. Nice! nit: I wou
Takashi Toyoshima 2012/08/03 05:11:12 looks safer. I follow your idea. Also, I added NO
146 return frame.data.data_frame;
147
148 // Create actual HEADERS frame just in time because it depends on
149 // compression context and should not be reordered after the creation.
150 SpdyFrame* header_frame = session_->CreateHeadersFrame(
151 stream_id_, *frame.data.header_block, SpdyControlFlags());
152 delete frame.data.header_block;
153 return header_frame;
143 } 154 }
144 } 155 }
145 156
146 SpdyStream::~SpdyStream() { 157 SpdyStream::~SpdyStream() {
147 UpdateHistograms(); 158 UpdateHistograms();
148 while (!pending_data_frames_.empty()) { 159 while (!pending_frames_.empty()) {
149 SpdyFrame* frame = pending_data_frames_.back(); 160 PendingFrame frame = pending_frames_.back();
150 pending_data_frames_.pop_back(); 161 pending_frames_.pop_back();
151 delete frame; 162 if (frame.type == TYPE_DATA)
163 delete frame.data.data_frame;
164 else
165 delete frame.data.header_block;
152 } 166 }
153 } 167 }
154 168
155 void SpdyStream::SetDelegate(Delegate* delegate) { 169 void SpdyStream::SetDelegate(Delegate* delegate) {
156 CHECK(delegate); 170 CHECK(delegate);
157 delegate_ = delegate; 171 delegate_ = delegate;
158 172
159 if (pushed_) { 173 if (pushed_) {
160 CHECK(response_received()); 174 CHECK(response_received());
161 MessageLoop::current()->PostTask( 175 MessageLoop::current()->PostTask(
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 send_time_ = base::TimeTicks::Now(); 562 send_time_ = base::TimeTicks::Now();
549 DCHECK(!has_upload_data_); 563 DCHECK(!has_upload_data_);
550 DCHECK(response_received()); 564 DCHECK(response_received());
551 return ERR_IO_PENDING; 565 return ERR_IO_PENDING;
552 } 566 }
553 CHECK_EQ(STATE_NONE, io_state_); 567 CHECK_EQ(STATE_NONE, io_state_);
554 io_state_ = STATE_GET_DOMAIN_BOUND_CERT; 568 io_state_ = STATE_GET_DOMAIN_BOUND_CERT;
555 return DoLoop(OK); 569 return DoLoop(OK);
556 } 570 }
557 571
558 int SpdyStream::WriteStreamData(IOBuffer* data, int length, 572 int SpdyStream::WriteHeaders(SpdyHeaderBlock* headers) {
573 // Until the first headers by SYN_STREAM have been completely sent, we can
574 // not be sure that our stream_id is correct.
575 DCHECK_GT(io_state_, STATE_SEND_HEADERS_COMPLETE);
576 CHECK_GT(stream_id_, 0u);
577
578 PendingFrame frame;
579 frame.type = TYPE_HEADER;
580 frame.data.header_block = headers;
581 pending_frames_.push_back(frame);
582
583 SetHasWriteAvailable();
584 return ERR_IO_PENDING;
585 }
586
587 int SpdyStream::WriteStreamData(IOBuffer* data,
588 int length,
559 SpdyDataFlags flags) { 589 SpdyDataFlags flags) {
560 // Until the headers have been completely sent, we can not be sure 590 // Until the headers have been completely sent, we can not be sure
561 // that our stream_id is correct. 591 // that our stream_id is correct.
562 DCHECK_GT(io_state_, STATE_SEND_HEADERS_COMPLETE); 592 DCHECK_GT(io_state_, STATE_SEND_HEADERS_COMPLETE);
563 CHECK_GT(stream_id_, 0u); 593 CHECK_GT(stream_id_, 0u);
564 594
565 pending_data_frames_.push_back( 595 SpdyDataFrame* data_frame = session_->CreateDataFrame(
566 session_->CreateDataFrame(stream_id_, data, length, flags)); 596 stream_id_, data, length, flags);
597 if (!data_frame)
598 return ERR_IO_PENDING;
599
600 PendingFrame frame;
601 frame.type = TYPE_DATA;
602 frame.data.data_frame = data_frame;
603 pending_frames_.push_back(frame);
567 604
568 SetHasWriteAvailable(); 605 SetHasWriteAvailable();
569 return ERR_IO_PENDING; 606 return ERR_IO_PENDING;
570 } 607 }
571 608
572 bool SpdyStream::GetSSLInfo(SSLInfo* ssl_info, 609 bool SpdyStream::GetSSLInfo(SSLInfo* ssl_info,
573 bool* was_npn_negotiated, 610 bool* was_npn_negotiated,
574 NextProto* protocol_negotiated) { 611 NextProto* protocol_negotiated) {
575 return session_->GetSSLInfo( 612 return session_->GetSSLInfo(
576 ssl_info, was_npn_negotiated, protocol_negotiated); 613 ssl_info, was_npn_negotiated, protocol_negotiated);
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 UMA_HISTOGRAM_TIMES("Net.SpdyStreamDownloadTime", 835 UMA_HISTOGRAM_TIMES("Net.SpdyStreamDownloadTime",
799 recv_last_byte_time_ - recv_first_byte_time_); 836 recv_last_byte_time_ - recv_first_byte_time_);
800 UMA_HISTOGRAM_TIMES("Net.SpdyStreamTime", 837 UMA_HISTOGRAM_TIMES("Net.SpdyStreamTime",
801 recv_last_byte_time_ - send_time_); 838 recv_last_byte_time_ - send_time_);
802 839
803 UMA_HISTOGRAM_COUNTS("Net.SpdySendBytes", send_bytes_); 840 UMA_HISTOGRAM_COUNTS("Net.SpdySendBytes", send_bytes_);
804 UMA_HISTOGRAM_COUNTS("Net.SpdyRecvBytes", recv_bytes_); 841 UMA_HISTOGRAM_COUNTS("Net.SpdyRecvBytes", recv_bytes_);
805 } 842 }
806 843
807 } // namespace net 844 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698