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_session.h" | 5 #include "net/spdy/spdy_session.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 const int kReadBufferSize = 8 * 1024; | 45 const int kReadBufferSize = 8 * 1024; |
46 const int kDefaultConnectionAtRiskOfLossSeconds = 10; | 46 const int kDefaultConnectionAtRiskOfLossSeconds = 10; |
47 const int kHungIntervalSeconds = 10; | 47 const int kHungIntervalSeconds = 10; |
48 | 48 |
49 // Always start at 1 for the first stream id. | 49 // Always start at 1 for the first stream id. |
50 const SpdyStreamId kFirstStreamId = 1; | 50 const SpdyStreamId kFirstStreamId = 1; |
51 | 51 |
52 // Minimum seconds that unclaimed pushed streams will be kept in memory. | 52 // Minimum seconds that unclaimed pushed streams will be kept in memory. |
53 const int kMinPushedStreamLifetimeSeconds = 300; | 53 const int kMinPushedStreamLifetimeSeconds = 300; |
54 | 54 |
| 55 int NPNToSpdyVersion(NextProto next_proto) { |
| 56 switch (next_proto) { |
| 57 case kProtoSPDY2: |
| 58 return kSpdyVersion2; |
| 59 case kProtoSPDY3: |
| 60 case kProtoSPDY31: |
| 61 return kSpdyVersion3; |
| 62 case kProtoSPDY4a1: |
| 63 return kSpdyVersion4; |
| 64 default: |
| 65 NOTREACHED(); |
| 66 } |
| 67 return kSpdyVersion2; |
| 68 } |
| 69 |
55 base::Value* NetLogSpdySynCallback(const SpdyHeaderBlock* headers, | 70 base::Value* NetLogSpdySynCallback(const SpdyHeaderBlock* headers, |
56 bool fin, | 71 bool fin, |
57 bool unidirectional, | 72 bool unidirectional, |
58 SpdyStreamId stream_id, | 73 SpdyStreamId stream_id, |
59 SpdyStreamId associated_stream, | 74 SpdyStreamId associated_stream, |
60 NetLog::LogLevel /* log_level */) { | 75 NetLog::LogLevel /* log_level */) { |
61 base::DictionaryValue* dict = new base::DictionaryValue(); | 76 base::DictionaryValue* dict = new base::DictionaryValue(); |
62 base::ListValue* headers_list = new base::ListValue(); | 77 base::ListValue* headers_list = new base::ListValue(); |
63 for (SpdyHeaderBlock::const_iterator it = headers->begin(); | 78 for (SpdyHeaderBlock::const_iterator it = headers->begin(); |
64 it != headers->end(); ++it) { | 79 it != headers->end(); ++it) { |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 | 434 |
420 SSLClientSocket* ssl_socket = GetSSLClientSocket(); | 435 SSLClientSocket* ssl_socket = GetSSLClientSocket(); |
421 if (ssl_socket && ssl_socket->WasChannelIDSent()) { | 436 if (ssl_socket && ssl_socket->WasChannelIDSent()) { |
422 // According to the SPDY spec, the credential associated with the TLS | 437 // According to the SPDY spec, the credential associated with the TLS |
423 // connection is stored in slot[1]. | 438 // connection is stored in slot[1]. |
424 credential_state_.SetHasCredential(GURL("https://" + | 439 credential_state_.SetHasCredential(GURL("https://" + |
425 host_port_pair().ToString())); | 440 host_port_pair().ToString())); |
426 } | 441 } |
427 | 442 |
428 DCHECK_GE(protocol, kProtoSPDY2); | 443 DCHECK_GE(protocol, kProtoSPDY2); |
429 DCHECK_LE(protocol, kProtoSPDY31); | 444 DCHECK_LE(protocol, kProtoSPDY4a1); |
430 int version = (protocol >= kProtoSPDY3) ? kSpdyVersion3 : kSpdyVersion2; | |
431 if (protocol >= kProtoSPDY31) { | 445 if (protocol >= kProtoSPDY31) { |
432 flow_control_state_ = FLOW_CONTROL_STREAM_AND_SESSION; | 446 flow_control_state_ = FLOW_CONTROL_STREAM_AND_SESSION; |
433 session_send_window_size_ = kSpdySessionInitialWindowSize; | 447 session_send_window_size_ = kSpdySessionInitialWindowSize; |
434 session_recv_window_size_ = kSpdySessionInitialWindowSize; | 448 session_recv_window_size_ = kSpdySessionInitialWindowSize; |
435 } else if (protocol >= kProtoSPDY3) { | 449 } else if (protocol >= kProtoSPDY3) { |
436 flow_control_state_ = FLOW_CONTROL_STREAM; | 450 flow_control_state_ = FLOW_CONTROL_STREAM; |
437 } else { | 451 } else { |
438 flow_control_state_ = FLOW_CONTROL_NONE; | 452 flow_control_state_ = FLOW_CONTROL_NONE; |
439 } | 453 } |
440 | 454 |
441 buffered_spdy_framer_.reset(new BufferedSpdyFramer(version, | 455 buffered_spdy_framer_.reset( |
442 enable_compression_)); | 456 new BufferedSpdyFramer(NPNToSpdyVersion(protocol), enable_compression_)); |
443 buffered_spdy_framer_->set_visitor(this); | 457 buffered_spdy_framer_->set_visitor(this); |
444 SendInitialSettings(); | 458 SendInitialSettings(); |
445 UMA_HISTOGRAM_ENUMERATION("Net.SpdyVersion", protocol, kProtoMaximumVersion); | 459 UMA_HISTOGRAM_ENUMERATION("Net.SpdyVersion", protocol, kProtoMaximumVersion); |
446 | 460 |
447 if (flow_control_state_ == FLOW_CONTROL_STREAM_AND_SESSION) { | 461 if (flow_control_state_ == FLOW_CONTROL_STREAM_AND_SESSION) { |
448 // Bump up the receive window size to the real initial value. This | 462 // Bump up the receive window size to the real initial value. This |
449 // has to go here since the WINDOW_UPDATE frame sent by | 463 // has to go here since the WINDOW_UPDATE frame sent by |
450 // IncreaseRecvWindowSize() call uses |buffered_spdy_framer_|. | 464 // IncreaseRecvWindowSize() call uses |buffered_spdy_framer_|. |
451 DCHECK_GT(kDefaultInitialRecvWindowSize, session_recv_window_size_); | 465 DCHECK_GT(kDefaultInitialRecvWindowSize, session_recv_window_size_); |
452 // This condition implies that |kDefaultInitialRecvWindowSize| - | 466 // This condition implies that |kDefaultInitialRecvWindowSize| - |
(...skipping 1837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2290 } | 2304 } |
2291 | 2305 |
2292 session_recv_window_size_ -= delta_window_size; | 2306 session_recv_window_size_ -= delta_window_size; |
2293 net_log_.AddEvent( | 2307 net_log_.AddEvent( |
2294 NetLog::TYPE_SPDY_SESSION_UPDATE_RECV_WINDOW, | 2308 NetLog::TYPE_SPDY_SESSION_UPDATE_RECV_WINDOW, |
2295 base::Bind(&NetLogSpdySessionWindowUpdateCallback, | 2309 base::Bind(&NetLogSpdySessionWindowUpdateCallback, |
2296 -delta_window_size, session_recv_window_size_)); | 2310 -delta_window_size, session_recv_window_size_)); |
2297 } | 2311 } |
2298 | 2312 |
2299 } // namespace net | 2313 } // namespace net |
OLD | NEW |