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 <limits> | 7 #include <limits> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "net/log/net_log_event_type.h" |
21 #include "net/spdy/spdy_buffer_producer.h" | 22 #include "net/spdy/spdy_buffer_producer.h" |
22 #include "net/spdy/spdy_http_utils.h" | 23 #include "net/spdy/spdy_http_utils.h" |
23 #include "net/spdy/spdy_session.h" | 24 #include "net/spdy/spdy_session.h" |
24 | 25 |
25 namespace net { | 26 namespace net { |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 std::unique_ptr<base::Value> NetLogSpdyStreamErrorCallback( | 30 std::unique_ptr<base::Value> NetLogSpdyStreamErrorCallback( |
30 SpdyStreamId stream_id, | 31 SpdyStreamId stream_id, |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 "send_window_size_ [current: %d]", delta_window_size, stream_id_, | 273 "send_window_size_ [current: %d]", delta_window_size, stream_id_, |
273 send_window_size_); | 274 send_window_size_); |
274 session_->ResetStream(stream_id_, RST_STREAM_FLOW_CONTROL_ERROR, desc); | 275 session_->ResetStream(stream_id_, RST_STREAM_FLOW_CONTROL_ERROR, desc); |
275 return; | 276 return; |
276 } | 277 } |
277 } | 278 } |
278 | 279 |
279 send_window_size_ += delta_window_size; | 280 send_window_size_ += delta_window_size; |
280 | 281 |
281 net_log_.AddEvent( | 282 net_log_.AddEvent( |
282 NetLog::TYPE_HTTP2_STREAM_UPDATE_SEND_WINDOW, | 283 NetLogEventType::HTTP2_STREAM_UPDATE_SEND_WINDOW, |
283 base::Bind(&NetLogSpdyStreamWindowUpdateCallback, stream_id_, | 284 base::Bind(&NetLogSpdyStreamWindowUpdateCallback, stream_id_, |
284 delta_window_size, send_window_size_)); | 285 delta_window_size, send_window_size_)); |
285 | 286 |
286 PossiblyResumeIfSendStalled(); | 287 PossiblyResumeIfSendStalled(); |
287 } | 288 } |
288 | 289 |
289 void SpdyStream::DecreaseSendWindowSize(int32_t delta_window_size) { | 290 void SpdyStream::DecreaseSendWindowSize(int32_t delta_window_size) { |
290 if (IsClosed()) | 291 if (IsClosed()) |
291 return; | 292 return; |
292 | 293 |
293 // We only call this method when sending a frame. Therefore, | 294 // We only call this method when sending a frame. Therefore, |
294 // |delta_window_size| should be within the valid frame size range. | 295 // |delta_window_size| should be within the valid frame size range. |
295 DCHECK_GE(delta_window_size, 1); | 296 DCHECK_GE(delta_window_size, 1); |
296 DCHECK_LE(delta_window_size, kMaxSpdyFrameChunkSize); | 297 DCHECK_LE(delta_window_size, kMaxSpdyFrameChunkSize); |
297 | 298 |
298 // |send_window_size_| should have been at least |delta_window_size| for | 299 // |send_window_size_| should have been at least |delta_window_size| for |
299 // this call to happen. | 300 // this call to happen. |
300 DCHECK_GE(send_window_size_, delta_window_size); | 301 DCHECK_GE(send_window_size_, delta_window_size); |
301 | 302 |
302 send_window_size_ -= delta_window_size; | 303 send_window_size_ -= delta_window_size; |
303 | 304 |
304 net_log_.AddEvent( | 305 net_log_.AddEvent( |
305 NetLog::TYPE_HTTP2_STREAM_UPDATE_SEND_WINDOW, | 306 NetLogEventType::HTTP2_STREAM_UPDATE_SEND_WINDOW, |
306 base::Bind(&NetLogSpdyStreamWindowUpdateCallback, stream_id_, | 307 base::Bind(&NetLogSpdyStreamWindowUpdateCallback, stream_id_, |
307 -delta_window_size, send_window_size_)); | 308 -delta_window_size, send_window_size_)); |
308 } | 309 } |
309 | 310 |
310 void SpdyStream::OnReadBufferConsumed( | 311 void SpdyStream::OnReadBufferConsumed( |
311 size_t consume_size, | 312 size_t consume_size, |
312 SpdyBuffer::ConsumeSource consume_source) { | 313 SpdyBuffer::ConsumeSource consume_source) { |
313 DCHECK_GE(consume_size, 1u); | 314 DCHECK_GE(consume_size, 1u); |
314 DCHECK_LE(consume_size, | 315 DCHECK_LE(consume_size, |
315 static_cast<size_t>(std::numeric_limits<int32_t>::max())); | 316 static_cast<size_t>(std::numeric_limits<int32_t>::max())); |
316 IncreaseRecvWindowSize(static_cast<int32_t>(consume_size)); | 317 IncreaseRecvWindowSize(static_cast<int32_t>(consume_size)); |
317 } | 318 } |
318 | 319 |
319 void SpdyStream::IncreaseRecvWindowSize(int32_t delta_window_size) { | 320 void SpdyStream::IncreaseRecvWindowSize(int32_t delta_window_size) { |
320 // By the time a read is processed by the delegate, this stream may | 321 // By the time a read is processed by the delegate, this stream may |
321 // already be inactive. | 322 // already be inactive. |
322 if (!session_->IsStreamActive(stream_id_)) | 323 if (!session_->IsStreamActive(stream_id_)) |
323 return; | 324 return; |
324 | 325 |
325 DCHECK_GE(unacked_recv_window_bytes_, 0); | 326 DCHECK_GE(unacked_recv_window_bytes_, 0); |
326 DCHECK_GE(recv_window_size_, unacked_recv_window_bytes_); | 327 DCHECK_GE(recv_window_size_, unacked_recv_window_bytes_); |
327 DCHECK_GE(delta_window_size, 1); | 328 DCHECK_GE(delta_window_size, 1); |
328 // Check for overflow. | 329 // Check for overflow. |
329 DCHECK_LE(delta_window_size, | 330 DCHECK_LE(delta_window_size, |
330 std::numeric_limits<int32_t>::max() - recv_window_size_); | 331 std::numeric_limits<int32_t>::max() - recv_window_size_); |
331 | 332 |
332 recv_window_size_ += delta_window_size; | 333 recv_window_size_ += delta_window_size; |
333 net_log_.AddEvent( | 334 net_log_.AddEvent( |
334 NetLog::TYPE_HTTP2_STREAM_UPDATE_RECV_WINDOW, | 335 NetLogEventType::HTTP2_STREAM_UPDATE_RECV_WINDOW, |
335 base::Bind(&NetLogSpdyStreamWindowUpdateCallback, stream_id_, | 336 base::Bind(&NetLogSpdyStreamWindowUpdateCallback, stream_id_, |
336 delta_window_size, recv_window_size_)); | 337 delta_window_size, recv_window_size_)); |
337 | 338 |
338 unacked_recv_window_bytes_ += delta_window_size; | 339 unacked_recv_window_bytes_ += delta_window_size; |
339 if (unacked_recv_window_bytes_ > max_recv_window_size_ / 2) { | 340 if (unacked_recv_window_bytes_ > max_recv_window_size_ / 2) { |
340 session_->SendStreamWindowUpdate( | 341 session_->SendStreamWindowUpdate( |
341 stream_id_, static_cast<uint32_t>(unacked_recv_window_bytes_)); | 342 stream_id_, static_cast<uint32_t>(unacked_recv_window_bytes_)); |
342 unacked_recv_window_bytes_ = 0; | 343 unacked_recv_window_bytes_ = 0; |
343 } | 344 } |
344 } | 345 } |
345 | 346 |
346 void SpdyStream::DecreaseRecvWindowSize(int32_t delta_window_size) { | 347 void SpdyStream::DecreaseRecvWindowSize(int32_t delta_window_size) { |
347 DCHECK(session_->IsStreamActive(stream_id_)); | 348 DCHECK(session_->IsStreamActive(stream_id_)); |
348 DCHECK_GE(delta_window_size, 1); | 349 DCHECK_GE(delta_window_size, 1); |
349 | 350 |
350 // The receiving window size as the peer knows it is | 351 // The receiving window size as the peer knows it is |
351 // |recv_window_size_ - unacked_recv_window_bytes_|, if more data are sent by | 352 // |recv_window_size_ - unacked_recv_window_bytes_|, if more data are sent by |
352 // the peer, that means that the receive window is not being respected. | 353 // the peer, that means that the receive window is not being respected. |
353 if (delta_window_size > recv_window_size_ - unacked_recv_window_bytes_) { | 354 if (delta_window_size > recv_window_size_ - unacked_recv_window_bytes_) { |
354 session_->ResetStream( | 355 session_->ResetStream( |
355 stream_id_, RST_STREAM_FLOW_CONTROL_ERROR, | 356 stream_id_, RST_STREAM_FLOW_CONTROL_ERROR, |
356 "delta_window_size is " + base::IntToString(delta_window_size) + | 357 "delta_window_size is " + base::IntToString(delta_window_size) + |
357 " in DecreaseRecvWindowSize, which is larger than the receive " + | 358 " in DecreaseRecvWindowSize, which is larger than the receive " + |
358 "window size of " + base::IntToString(recv_window_size_)); | 359 "window size of " + base::IntToString(recv_window_size_)); |
359 return; | 360 return; |
360 } | 361 } |
361 | 362 |
362 recv_window_size_ -= delta_window_size; | 363 recv_window_size_ -= delta_window_size; |
363 net_log_.AddEvent( | 364 net_log_.AddEvent( |
364 NetLog::TYPE_HTTP2_STREAM_UPDATE_RECV_WINDOW, | 365 NetLogEventType::HTTP2_STREAM_UPDATE_RECV_WINDOW, |
365 base::Bind(&NetLogSpdyStreamWindowUpdateCallback, stream_id_, | 366 base::Bind(&NetLogSpdyStreamWindowUpdateCallback, stream_id_, |
366 -delta_window_size, recv_window_size_)); | 367 -delta_window_size, recv_window_size_)); |
367 } | 368 } |
368 | 369 |
369 int SpdyStream::GetPeerAddress(IPEndPoint* address) const { | 370 int SpdyStream::GetPeerAddress(IPEndPoint* address) const { |
370 return session_->GetPeerAddress(address); | 371 return session_->GetPeerAddress(address); |
371 } | 372 } |
372 | 373 |
373 int SpdyStream::GetLocalAddress(IPEndPoint* address) const { | 374 int SpdyStream::GetLocalAddress(IPEndPoint* address) const { |
374 return session_->GetLocalAddress(address); | 375 return session_->GetLocalAddress(address); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 if (pending_send_data_->BytesRemaining() > 0) { | 629 if (pending_send_data_->BytesRemaining() > 0) { |
629 QueueNextDataFrame(); | 630 QueueNextDataFrame(); |
630 return ERR_IO_PENDING; | 631 return ERR_IO_PENDING; |
631 } else { | 632 } else { |
632 pending_send_data_ = NULL; | 633 pending_send_data_ = NULL; |
633 return OK; | 634 return OK; |
634 } | 635 } |
635 } | 636 } |
636 | 637 |
637 void SpdyStream::LogStreamError(int status, const std::string& description) { | 638 void SpdyStream::LogStreamError(int status, const std::string& description) { |
638 net_log_.AddEvent(NetLog::TYPE_HTTP2_STREAM_ERROR, | 639 net_log_.AddEvent(NetLogEventType::HTTP2_STREAM_ERROR, |
639 base::Bind(&NetLogSpdyStreamErrorCallback, stream_id_, | 640 base::Bind(&NetLogSpdyStreamErrorCallback, stream_id_, |
640 status, &description)); | 641 status, &description)); |
641 } | 642 } |
642 | 643 |
643 void SpdyStream::OnClose(int status) { | 644 void SpdyStream::OnClose(int status) { |
644 // In most cases, the stream should already be CLOSED. The exception is when a | 645 // In most cases, the stream should already be CLOSED. The exception is when a |
645 // SpdySession is shutting down while the stream is in an intermediate state. | 646 // SpdySession is shutting down while the stream is in an intermediate state. |
646 io_state_ = STATE_CLOSED; | 647 io_state_ = STATE_CLOSED; |
647 response_status_ = status; | 648 response_status_ = status; |
648 Delegate* delegate = delegate_; | 649 Delegate* delegate = delegate_; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 NextProto SpdyStream::GetNegotiatedProtocol() const { | 725 NextProto SpdyStream::GetNegotiatedProtocol() const { |
725 return session_->GetNegotiatedProtocol(); | 726 return session_->GetNegotiatedProtocol(); |
726 } | 727 } |
727 | 728 |
728 void SpdyStream::PossiblyResumeIfSendStalled() { | 729 void SpdyStream::PossiblyResumeIfSendStalled() { |
729 if (IsLocallyClosed()) { | 730 if (IsLocallyClosed()) { |
730 return; | 731 return; |
731 } | 732 } |
732 if (send_stalled_by_flow_control_ && !session_->IsSendStalled() && | 733 if (send_stalled_by_flow_control_ && !session_->IsSendStalled() && |
733 send_window_size_ > 0) { | 734 send_window_size_ > 0) { |
734 net_log_.AddEvent(NetLog::TYPE_HTTP2_STREAM_FLOW_CONTROL_UNSTALLED, | 735 net_log_.AddEvent(NetLogEventType::HTTP2_STREAM_FLOW_CONTROL_UNSTALLED, |
735 NetLog::IntCallback("stream_id", stream_id_)); | 736 NetLog::IntCallback("stream_id", stream_id_)); |
736 send_stalled_by_flow_control_ = false; | 737 send_stalled_by_flow_control_ = false; |
737 QueueNextDataFrame(); | 738 QueueNextDataFrame(); |
738 } | 739 } |
739 } | 740 } |
740 | 741 |
741 bool SpdyStream::IsClosed() const { | 742 bool SpdyStream::IsClosed() const { |
742 return io_state_ == STATE_CLOSED; | 743 return io_state_ == STATE_CLOSED; |
743 } | 744 } |
744 | 745 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, | 936 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, |
936 state); | 937 state); |
937 break; | 938 break; |
938 } | 939 } |
939 return description; | 940 return description; |
940 } | 941 } |
941 | 942 |
942 #undef STATE_CASE | 943 #undef STATE_CASE |
943 | 944 |
944 } // namespace net | 945 } // namespace net |
OLD | NEW |