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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 delayed_write_pending_(false), | 288 delayed_write_pending_(false), |
289 is_secure_(false), | 289 is_secure_(false), |
290 certificate_error_code_(OK), | 290 certificate_error_code_(OK), |
291 error_(OK), | 291 error_(OK), |
292 state_(IDLE), | 292 state_(IDLE), |
293 max_concurrent_streams_(init_max_concurrent_streams_), | 293 max_concurrent_streams_(init_max_concurrent_streams_), |
294 streams_initiated_count_(0), | 294 streams_initiated_count_(0), |
295 streams_pushed_count_(0), | 295 streams_pushed_count_(0), |
296 streams_pushed_and_claimed_count_(0), | 296 streams_pushed_and_claimed_count_(0), |
297 streams_abandoned_count_(0), | 297 streams_abandoned_count_(0), |
298 frames_received_(0), | |
299 bytes_received_(0), | 298 bytes_received_(0), |
300 sent_settings_(false), | 299 sent_settings_(false), |
301 received_settings_(false), | 300 received_settings_(false), |
302 stalled_streams_(0), | 301 stalled_streams_(0), |
303 pings_in_flight_(0), | 302 pings_in_flight_(0), |
304 next_ping_id_(1), | 303 next_ping_id_(1), |
305 received_data_time_(base::TimeTicks::Now()), | 304 received_data_time_(base::TimeTicks::Now()), |
306 trailing_ping_pending_(false), | 305 trailing_ping_pending_(false), |
307 check_ping_status_pending_(false), | 306 check_ping_status_pending_(false), |
308 need_to_send_ping_(false), | 307 need_to_send_ping_(false), |
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 dict->SetBoolean("is_secure", is_secure_); | 1097 dict->SetBoolean("is_secure", is_secure_); |
1099 | 1098 |
1100 dict->SetInteger("error", error_); | 1099 dict->SetInteger("error", error_); |
1101 dict->SetInteger("max_concurrent_streams", max_concurrent_streams_); | 1100 dict->SetInteger("max_concurrent_streams", max_concurrent_streams_); |
1102 | 1101 |
1103 dict->SetInteger("streams_initiated_count", streams_initiated_count_); | 1102 dict->SetInteger("streams_initiated_count", streams_initiated_count_); |
1104 dict->SetInteger("streams_pushed_count", streams_pushed_count_); | 1103 dict->SetInteger("streams_pushed_count", streams_pushed_count_); |
1105 dict->SetInteger("streams_pushed_and_claimed_count", | 1104 dict->SetInteger("streams_pushed_and_claimed_count", |
1106 streams_pushed_and_claimed_count_); | 1105 streams_pushed_and_claimed_count_); |
1107 dict->SetInteger("streams_abandoned_count", streams_abandoned_count_); | 1106 dict->SetInteger("streams_abandoned_count", streams_abandoned_count_); |
1108 dict->SetInteger("frames_received", frames_received_); | 1107 dict->SetInteger("frames_received", buffered_spdy_framer_.frames_received()); |
1109 | 1108 |
1110 dict->SetBoolean("sent_settings", sent_settings_); | 1109 dict->SetBoolean("sent_settings", sent_settings_); |
1111 dict->SetBoolean("received_settings", received_settings_); | 1110 dict->SetBoolean("received_settings", received_settings_); |
1112 return dict; | 1111 return dict; |
1113 } | 1112 } |
1114 | 1113 |
1115 int SpdySession::GetPeerAddress(AddressList* address) const { | 1114 int SpdySession::GetPeerAddress(AddressList* address) const { |
1116 if (!connection_->socket()) | 1115 if (!connection_->socket()) |
1117 return ERR_SOCKET_NOT_CONNECTED; | 1116 return ERR_SOCKET_NOT_CONNECTED; |
1118 | 1117 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 | 1222 |
1224 SSLClientCertType SpdySession::GetOriginBoundCertType() const { | 1223 SSLClientCertType SpdySession::GetOriginBoundCertType() const { |
1225 if (!is_secure_) { | 1224 if (!is_secure_) { |
1226 return CLIENT_CERT_INVALID_TYPE; | 1225 return CLIENT_CERT_INVALID_TYPE; |
1227 } | 1226 } |
1228 SSLClientSocket* ssl_socket = | 1227 SSLClientSocket* ssl_socket = |
1229 reinterpret_cast<SSLClientSocket*>(connection_->socket()); | 1228 reinterpret_cast<SSLClientSocket*>(connection_->socket()); |
1230 return ssl_socket->origin_bound_cert_type(); | 1229 return ssl_socket->origin_bound_cert_type(); |
1231 } | 1230 } |
1232 | 1231 |
1233 void SpdySession::OnError(spdy::SpdyFramer* framer) { | 1232 void SpdySession::OnError() { |
1234 CloseSessionOnError(net::ERR_SPDY_PROTOCOL_ERROR, true); | 1233 CloseSessionOnError(net::ERR_SPDY_PROTOCOL_ERROR, true); |
1235 } | 1234 } |
1236 | 1235 |
| 1236 void SpdySession::OnStreamError(spdy::SpdyStreamId stream_id) { |
| 1237 if (IsStreamActive(stream_id)) |
| 1238 ResetStream(stream_id, spdy::PROTOCOL_ERROR, ""); |
| 1239 } |
| 1240 |
1237 void SpdySession::OnStreamFrameData(spdy::SpdyStreamId stream_id, | 1241 void SpdySession::OnStreamFrameData(spdy::SpdyStreamId stream_id, |
1238 const char* data, | 1242 const char* data, |
1239 size_t len) { | 1243 size_t len) { |
1240 if (net_log().IsLoggingAllEvents()) { | 1244 if (net_log().IsLoggingAllEvents()) { |
1241 net_log().AddEvent( | 1245 net_log().AddEvent( |
1242 NetLog::TYPE_SPDY_SESSION_RECV_DATA, | 1246 NetLog::TYPE_SPDY_SESSION_RECV_DATA, |
1243 make_scoped_refptr(new NetLogSpdyDataParameter( | 1247 make_scoped_refptr(new NetLogSpdyDataParameter( |
1244 stream_id, len, spdy::SpdyDataFlags()))); | 1248 stream_id, len, spdy::SpdyDataFlags()))); |
1245 } | 1249 } |
1246 | 1250 |
(...skipping 13 matching lines...) Expand all Loading... |
1260 rv = stream->OnResponseReceived(headers); | 1264 rv = stream->OnResponseReceived(headers); |
1261 if (rv < 0) { | 1265 if (rv < 0) { |
1262 DCHECK_NE(rv, ERR_IO_PENDING); | 1266 DCHECK_NE(rv, ERR_IO_PENDING); |
1263 const spdy::SpdyStreamId stream_id = stream->stream_id(); | 1267 const spdy::SpdyStreamId stream_id = stream->stream_id(); |
1264 DeleteStream(stream_id, rv); | 1268 DeleteStream(stream_id, rv); |
1265 return false; | 1269 return false; |
1266 } | 1270 } |
1267 return true; | 1271 return true; |
1268 } | 1272 } |
1269 | 1273 |
1270 void SpdySession::OnSyn(const spdy::SpdySynStreamControlFrame& frame, | 1274 void SpdySession::OnSynStream( |
1271 const linked_ptr<spdy::SpdyHeaderBlock>& headers) { | 1275 const spdy::SpdySynStreamControlFrame& frame, |
| 1276 const linked_ptr<spdy::SpdyHeaderBlock>& headers) { |
1272 spdy::SpdyStreamId stream_id = frame.stream_id(); | 1277 spdy::SpdyStreamId stream_id = frame.stream_id(); |
1273 spdy::SpdyStreamId associated_stream_id = frame.associated_stream_id(); | 1278 spdy::SpdyStreamId associated_stream_id = frame.associated_stream_id(); |
1274 | 1279 |
1275 if (net_log_.IsLoggingAllEvents()) { | 1280 if (net_log_.IsLoggingAllEvents()) { |
1276 net_log_.AddEvent( | 1281 net_log_.AddEvent( |
1277 NetLog::TYPE_SPDY_SESSION_PUSHED_SYN_STREAM, | 1282 NetLog::TYPE_SPDY_SESSION_PUSHED_SYN_STREAM, |
1278 make_scoped_refptr(new NetLogSpdySynParameter( | 1283 make_scoped_refptr(new NetLogSpdySynParameter( |
1279 headers, static_cast<spdy::SpdyControlFlags>(frame.flags()), | 1284 headers, static_cast<spdy::SpdyControlFlags>(frame.flags()), |
1280 stream_id, associated_stream_id))); | 1285 stream_id, associated_stream_id))); |
1281 } | 1286 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1431 } | 1436 } |
1432 | 1437 |
1433 int rv = stream->OnHeaders(*headers); | 1438 int rv = stream->OnHeaders(*headers); |
1434 if (rv < 0) { | 1439 if (rv < 0) { |
1435 DCHECK_NE(rv, ERR_IO_PENDING); | 1440 DCHECK_NE(rv, ERR_IO_PENDING); |
1436 const spdy::SpdyStreamId stream_id = stream->stream_id(); | 1441 const spdy::SpdyStreamId stream_id = stream->stream_id(); |
1437 DeleteStream(stream_id, rv); | 1442 DeleteStream(stream_id, rv); |
1438 } | 1443 } |
1439 } | 1444 } |
1440 | 1445 |
1441 void SpdySession::OnControl(const spdy::SpdyControlFrame* frame) { | 1446 void SpdySession::OnRstStream(const spdy::SpdyRstStreamControlFrame& frame) { |
1442 uint32 type = frame->type(); | |
1443 if (type == spdy::SYN_STREAM || | |
1444 type == spdy::SYN_REPLY || | |
1445 type == spdy::HEADERS) { | |
1446 buffered_spdy_framer_.OnControl(frame); | |
1447 return; | |
1448 } | |
1449 | |
1450 frames_received_++; | |
1451 | |
1452 switch (type) { | |
1453 case spdy::GOAWAY: | |
1454 OnGoAway(*reinterpret_cast<const spdy::SpdyGoAwayControlFrame*>(frame)); | |
1455 break; | |
1456 case spdy::PING: | |
1457 OnPing(*reinterpret_cast<const spdy::SpdyPingControlFrame*>(frame)); | |
1458 break; | |
1459 case spdy::SETTINGS: | |
1460 OnSettings( | |
1461 *reinterpret_cast<const spdy::SpdySettingsControlFrame*>(frame)); | |
1462 break; | |
1463 case spdy::RST_STREAM: | |
1464 OnRst(*reinterpret_cast<const spdy::SpdyRstStreamControlFrame*>(frame)); | |
1465 break; | |
1466 case spdy::WINDOW_UPDATE: | |
1467 OnWindowUpdate( | |
1468 *reinterpret_cast<const spdy::SpdyWindowUpdateControlFrame*>(frame)); | |
1469 break; | |
1470 default: | |
1471 DCHECK(false); // Error! | |
1472 } | |
1473 } | |
1474 | |
1475 bool SpdySession::OnControlFrameHeaderData(spdy::SpdyStreamId stream_id, | |
1476 const char* header_data, | |
1477 size_t len) { | |
1478 if (!buffered_spdy_framer_.OnControlFrameHeaderData( | |
1479 stream_id, header_data, len)) { | |
1480 if (IsStreamActive(stream_id)) | |
1481 ResetStream(stream_id, spdy::PROTOCOL_ERROR, ""); | |
1482 return false; | |
1483 } | |
1484 if (len == 0) { | |
1485 // Indicates end-of-header-block. | |
1486 frames_received_++; | |
1487 } | |
1488 return true; | |
1489 } | |
1490 | |
1491 bool SpdySession::OnCredentialFrameData(const char* frame_data, | |
1492 size_t len) { | |
1493 DCHECK(false); | |
1494 return false; | |
1495 } | |
1496 | |
1497 void SpdySession::OnDataFrameHeader(const spdy::SpdyDataFrame* frame) { | |
1498 buffered_spdy_framer_.OnDataFrameHeader(frame); | |
1499 } | |
1500 | |
1501 void SpdySession::OnRst(const spdy::SpdyRstStreamControlFrame& frame) { | |
1502 spdy::SpdyStreamId stream_id = frame.stream_id(); | 1447 spdy::SpdyStreamId stream_id = frame.stream_id(); |
1503 | 1448 |
1504 net_log().AddEvent( | 1449 net_log().AddEvent( |
1505 NetLog::TYPE_SPDY_SESSION_RST_STREAM, | 1450 NetLog::TYPE_SPDY_SESSION_RST_STREAM, |
1506 make_scoped_refptr( | 1451 make_scoped_refptr( |
1507 new NetLogSpdyRstParameter(stream_id, frame.status(), ""))); | 1452 new NetLogSpdyRstParameter(stream_id, frame.status(), ""))); |
1508 | 1453 |
1509 bool valid_stream = IsStreamActive(stream_id); | 1454 bool valid_stream = IsStreamActive(stream_id); |
1510 if (!valid_stream) { | 1455 if (!valid_stream) { |
1511 // NOTE: it may just be that the stream was cancelled. | 1456 // NOTE: it may just be that the stream was cancelled. |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1922 if (it == pending_callback_map_.end()) | 1867 if (it == pending_callback_map_.end()) |
1923 return; | 1868 return; |
1924 | 1869 |
1925 CompletionCallback callback = it->second.callback; | 1870 CompletionCallback callback = it->second.callback; |
1926 int result = it->second.result; | 1871 int result = it->second.result; |
1927 pending_callback_map_.erase(it); | 1872 pending_callback_map_.erase(it); |
1928 callback.Run(result); | 1873 callback.Run(result); |
1929 } | 1874 } |
1930 | 1875 |
1931 } // namespace net | 1876 } // namespace net |
OLD | NEW |