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

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

Issue 10689034: SPDY - chunked upload - speech recognition doesn't work with SPDY/3 (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
« no previous file with comments | « net/spdy/spdy_stream.h ('k') | net/spdy/spdy_stream_spdy2_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } else { 121 } else {
122 delegate_->OnDataReceived(NULL, 0); 122 delegate_->OnDataReceived(NULL, 0);
123 session_->CloseStream(stream_id_, net::OK); 123 session_->CloseStream(stream_id_, net::OK);
124 // Note: |this| may be deleted after calling CloseStream. 124 // Note: |this| may be deleted after calling CloseStream.
125 DCHECK_EQ(buffers.size() - 1, i); 125 DCHECK_EQ(buffers.size() - 1, i);
126 } 126 }
127 } 127 }
128 } 128 }
129 129
130 void SpdyStream::DetachDelegate() { 130 void SpdyStream::DetachDelegate() {
131 if (delegate_)
132 delegate_->set_chunk_callback(NULL);
133 delegate_ = NULL; 131 delegate_ = NULL;
134 if (!closed()) 132 if (!closed())
135 Cancel(); 133 Cancel();
136 } 134 }
137 135
138 const linked_ptr<SpdyHeaderBlock>& SpdyStream::spdy_headers() const { 136 const linked_ptr<SpdyHeaderBlock>& SpdyStream::spdy_headers() const {
139 return request_; 137 return request_;
140 } 138 }
141 139
142 void SpdyStream::set_spdy_headers( 140 void SpdyStream::set_spdy_headers(
(...skipping 15 matching lines...) Expand all
158 156
159 void SpdyStream::AdjustSendWindowSize(int32 delta_window_size) { 157 void SpdyStream::AdjustSendWindowSize(int32 delta_window_size) {
160 send_window_size_ += delta_window_size; 158 send_window_size_ += delta_window_size;
161 PossiblyResumeIfStalled(); 159 PossiblyResumeIfStalled();
162 } 160 }
163 161
164 void SpdyStream::IncreaseSendWindowSize(int32 delta_window_size) { 162 void SpdyStream::IncreaseSendWindowSize(int32 delta_window_size) {
165 DCHECK(session_->is_flow_control_enabled()); 163 DCHECK(session_->is_flow_control_enabled());
166 DCHECK_GE(delta_window_size, 1); 164 DCHECK_GE(delta_window_size, 1);
167 165
166 // Ignore late WINDOW_UPDATEs.
167 if (closed())
168 return;
169
168 int32 new_window_size = send_window_size_ + delta_window_size; 170 int32 new_window_size = send_window_size_ + delta_window_size;
169 171
170 // We should ignore WINDOW_UPDATEs received before or after this state, 172 // It's valid for send_window_size_ to become negative (via an incoming
171 // since before means we've not written SYN_STREAM yet (i.e. it's too
172 // early) and after means we've written a DATA frame with FIN bit.
173 if (io_state_ != STATE_SEND_BODY_COMPLETE)
174 return;
175
176 // it's valid for send_window_size_ to become negative (via an incoming
177 // SETTINGS), in which case incoming WINDOW_UPDATEs will eventually make 173 // SETTINGS), in which case incoming WINDOW_UPDATEs will eventually make
178 // it positive; however, if send_window_size_ is positive and incoming 174 // it positive; however, if send_window_size_ is positive and incoming
179 // WINDOW_UPDATE makes it negative, we have an overflow. 175 // WINDOW_UPDATE makes it negative, we have an overflow.
180 if (send_window_size_ > 0 && new_window_size < 0) { 176 if (send_window_size_ > 0 && new_window_size < 0) {
181 std::string desc = base::StringPrintf( 177 std::string desc = base::StringPrintf(
182 "Received WINDOW_UPDATE [delta: %d] for stream %d overflows " 178 "Received WINDOW_UPDATE [delta: %d] for stream %d overflows "
183 "send_window_size_ [current: %d]", delta_window_size, stream_id_, 179 "send_window_size_ [current: %d]", delta_window_size, stream_id_,
184 send_window_size_); 180 send_window_size_);
185 session_->ResetStream(stream_id_, FLOW_CONTROL_ERROR, desc); 181 session_->ResetStream(stream_id_, FLOW_CONTROL_ERROR, desc);
186 return; 182 return;
187 } 183 }
188 184
189 send_window_size_ = new_window_size; 185 send_window_size_ = new_window_size;
190 186
191 net_log_.AddEvent( 187 net_log_.AddEvent(
192 NetLog::TYPE_SPDY_STREAM_UPDATE_SEND_WINDOW, 188 NetLog::TYPE_SPDY_STREAM_UPDATE_SEND_WINDOW,
193 base::Bind(&NetLogSpdyStreamWindowUpdateCallback, 189 base::Bind(&NetLogSpdyStreamWindowUpdateCallback,
194 stream_id_, delta_window_size, send_window_size_)); 190 stream_id_, delta_window_size, send_window_size_));
191
195 PossiblyResumeIfStalled(); 192 PossiblyResumeIfStalled();
196 } 193 }
197 194
198 void SpdyStream::DecreaseSendWindowSize(int32 delta_window_size) { 195 void SpdyStream::DecreaseSendWindowSize(int32 delta_window_size) {
199 // we only call this method when sending a frame, therefore 196 // we only call this method when sending a frame, therefore
200 // |delta_window_size| should be within the valid frame size range. 197 // |delta_window_size| should be within the valid frame size range.
201 DCHECK(session_->is_flow_control_enabled()); 198 DCHECK(session_->is_flow_control_enabled());
202 DCHECK_GE(delta_window_size, 1); 199 DCHECK_GE(delta_window_size, 1);
203 DCHECK_LE(delta_window_size, kMaxSpdyFrameChunkSize); 200 DCHECK_LE(delta_window_size, kMaxSpdyFrameChunkSize);
204 201
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 424
428 // This function is only called when an entire frame is written. 425 // This function is only called when an entire frame is written.
429 void SpdyStream::OnWriteComplete(int bytes) { 426 void SpdyStream::OnWriteComplete(int bytes) {
430 DCHECK_LE(0, bytes); 427 DCHECK_LE(0, bytes);
431 send_bytes_ += bytes; 428 send_bytes_ += bytes;
432 if (cancelled() || closed()) 429 if (cancelled() || closed())
433 return; 430 return;
434 DoLoop(bytes); 431 DoLoop(bytes);
435 } 432 }
436 433
437 void SpdyStream::OnChunkAvailable() {
438 DCHECK(io_state_ == STATE_SEND_HEADERS || io_state_ == STATE_SEND_BODY ||
439 io_state_ == STATE_SEND_BODY_COMPLETE);
440 if (io_state_ == STATE_SEND_BODY)
441 OnWriteComplete(0);
442 }
443
444 int SpdyStream::GetProtocolVersion() const { 434 int SpdyStream::GetProtocolVersion() const {
445 return session_->GetProtocolVersion(); 435 return session_->GetProtocolVersion();
446 } 436 }
447 437
448 void SpdyStream::LogStreamError(int status, const std::string& description) { 438 void SpdyStream::LogStreamError(int status, const std::string& description) {
449 net_log_.AddEvent(NetLog::TYPE_SPDY_STREAM_ERROR, 439 net_log_.AddEvent(NetLog::TYPE_SPDY_STREAM_ERROR,
450 base::Bind(&NetLogSpdyStreamErrorCallback, 440 base::Bind(&NetLogSpdyStreamErrorCallback,
451 stream_id_, status, &description)); 441 stream_id_, status, &description));
452 } 442 }
453 443
454 void SpdyStream::OnClose(int status) { 444 void SpdyStream::OnClose(int status) {
455 io_state_ = STATE_DONE; 445 io_state_ = STATE_DONE;
456 response_status_ = status; 446 response_status_ = status;
457 Delegate* delegate = delegate_; 447 Delegate* delegate = delegate_;
458 delegate_ = NULL; 448 delegate_ = NULL;
459 if (delegate) { 449 if (delegate)
460 delegate->set_chunk_callback(NULL);
461 delegate->OnClose(status); 450 delegate->OnClose(status);
462 }
463 } 451 }
464 452
465 void SpdyStream::Cancel() { 453 void SpdyStream::Cancel() {
466 if (cancelled()) 454 if (cancelled())
467 return; 455 return;
468 456
469 cancelled_ = true; 457 cancelled_ = true;
470 if (session_->IsStreamActive(stream_id_)) 458 if (session_->IsStreamActive(stream_id_))
471 session_->ResetStream(stream_id_, CANCEL, ""); 459 session_->ResetStream(stream_id_, CANCEL, "");
472 } 460 }
473 461
474 void SpdyStream::Close() { 462 void SpdyStream::Close() {
475 session_->CloseStream(stream_id_, net::OK); 463 session_->CloseStream(stream_id_, net::OK);
476 } 464 }
477 465
478 int SpdyStream::SendRequest(bool has_upload_data) { 466 int SpdyStream::SendRequest(bool has_upload_data) {
479 if (delegate_)
480 delegate_->set_chunk_callback(this);
481
482 // Pushed streams do not send any data, and should always be in STATE_OPEN or 467 // Pushed streams do not send any data, and should always be in STATE_OPEN or
483 // STATE_DONE. However, we still want to return IO_PENDING to mimic non-push 468 // STATE_DONE. However, we still want to return IO_PENDING to mimic non-push
484 // behavior. 469 // behavior.
485 has_upload_data_ = has_upload_data; 470 has_upload_data_ = has_upload_data;
486 if (pushed_) { 471 if (pushed_) {
487 send_time_ = base::TimeTicks::Now(); 472 send_time_ = base::TimeTicks::Now();
488 DCHECK(!has_upload_data_); 473 DCHECK(!has_upload_data_);
489 DCHECK(response_received()); 474 DCHECK(response_received());
490 return ERR_IO_PENDING; 475 return ERR_IO_PENDING;
491 } 476 }
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 return OK; 680 return OK;
696 } 681 }
697 682
698 io_state_ = STATE_SEND_BODY; 683 io_state_ = STATE_SEND_BODY;
699 return OK; 684 return OK;
700 } 685 }
701 686
702 // DoSendBody is called to send the optional body for the request. This call 687 // DoSendBody is called to send the optional body for the request. This call
703 // will also be called as each write of a chunk of the body completes. 688 // will also be called as each write of a chunk of the body completes.
704 int SpdyStream::DoSendBody() { 689 int SpdyStream::DoSendBody() {
705 // If we're already in the STATE_SENDING_BODY state, then we've already 690 // If we're already in the STATE_SEND_BODY state, then we've already
706 // sent a portion of the body. In that case, we need to first consume 691 // sent a portion of the body. In that case, we need to first consume
707 // the bytes written in the body stream. Note that the bytes written is 692 // the bytes written in the body stream. Note that the bytes written is
708 // the number of bytes in the frame that were written, only consume the 693 // the number of bytes in the frame that were written, only consume the
709 // data portion, of course. 694 // data portion, of course.
710 io_state_ = STATE_SEND_BODY_COMPLETE; 695 io_state_ = STATE_SEND_BODY_COMPLETE;
711 if (!delegate_) 696 if (!delegate_)
712 return ERR_UNEXPECTED; 697 return ERR_UNEXPECTED;
713 return delegate_->OnSendBody(); 698 return delegate_->OnSendBody();
714 } 699 }
715 700
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 UMA_HISTOGRAM_TIMES("Net.SpdyStreamDownloadTime", 733 UMA_HISTOGRAM_TIMES("Net.SpdyStreamDownloadTime",
749 recv_last_byte_time_ - recv_first_byte_time_); 734 recv_last_byte_time_ - recv_first_byte_time_);
750 UMA_HISTOGRAM_TIMES("Net.SpdyStreamTime", 735 UMA_HISTOGRAM_TIMES("Net.SpdyStreamTime",
751 recv_last_byte_time_ - send_time_); 736 recv_last_byte_time_ - send_time_);
752 737
753 UMA_HISTOGRAM_COUNTS("Net.SpdySendBytes", send_bytes_); 738 UMA_HISTOGRAM_COUNTS("Net.SpdySendBytes", send_bytes_);
754 UMA_HISTOGRAM_COUNTS("Net.SpdyRecvBytes", recv_bytes_); 739 UMA_HISTOGRAM_COUNTS("Net.SpdyRecvBytes", recv_bytes_);
755 } 740 }
756 741
757 } // namespace net 742 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_stream.h ('k') | net/spdy/spdy_stream_spdy2_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698