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 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 PROTOCOL_ERROR_REQUEST_FOR_SECURE_CONTENT_OVER_INSECURE_SESSION); | 549 PROTOCOL_ERROR_REQUEST_FOR_SECURE_CONTENT_OVER_INSECURE_SESSION); |
550 CloseSessionOnError( | 550 CloseSessionOnError( |
551 static_cast<net::Error>(certificate_error_code_), | 551 static_cast<net::Error>(certificate_error_code_), |
552 true, | 552 true, |
553 "Tried to create SPDY stream for secure content over an " | 553 "Tried to create SPDY stream for secure content over an " |
554 "unauthenticated session."); | 554 "unauthenticated session."); |
555 return ERR_SPDY_PROTOCOL_ERROR; | 555 return ERR_SPDY_PROTOCOL_ERROR; |
556 } | 556 } |
557 | 557 |
558 const std::string& path = request.url().PathForRequest(); | 558 const std::string& path = request.url().PathForRequest(); |
559 | 559 *stream = new SpdyStream(this, path, request.priority(), |
560 *stream = new SpdyStream(this, false, request.net_log()); | 560 stream_initial_send_window_size_, |
561 | 561 stream_initial_recv_window_size_, |
562 (*stream)->set_priority(request.priority()); | 562 false, request.net_log()); |
563 (*stream)->set_path(path); | |
564 (*stream)->set_send_window_size(stream_initial_send_window_size_); | |
565 (*stream)->set_recv_window_size(stream_initial_recv_window_size_); | |
566 created_streams_.insert(*stream); | 563 created_streams_.insert(*stream); |
567 | 564 |
568 UMA_HISTOGRAM_CUSTOM_COUNTS( | 565 UMA_HISTOGRAM_CUSTOM_COUNTS( |
569 "Net.SpdyPriorityCount", | 566 "Net.SpdyPriorityCount", |
570 static_cast<int>(request.priority()), 0, 10, 11); | 567 static_cast<int>(request.priority()), 0, 10, 11); |
571 | 568 |
572 // TODO(mbelshe): Optimize memory allocations | 569 // TODO(mbelshe): Optimize memory allocations |
573 | 570 |
574 return OK; | 571 return OK; |
575 } | 572 } |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 weak_factory_.GetWeakPtr())); | 923 weak_factory_.GetWeakPtr())); |
927 return ERR_IO_PENDING; | 924 return ERR_IO_PENDING; |
928 } | 925 } |
929 | 926 |
930 CHECK(connection_.get()); | 927 CHECK(connection_.get()); |
931 CHECK(connection_->socket()); | 928 CHECK(connection_->socket()); |
932 state_ = STATE_DO_READ_COMPLETE; | 929 state_ = STATE_DO_READ_COMPLETE; |
933 return connection_->socket()->Read( | 930 return connection_->socket()->Read( |
934 read_buffer_.get(), | 931 read_buffer_.get(), |
935 kReadBufferSize, | 932 kReadBufferSize, |
936 base::Bind(&SpdySession::OnReadComplete, base::Unretained(this))); | 933 base::Bind(&SpdySession::OnReadComplete, weak_factory_.GetWeakPtr())); |
937 } | 934 } |
938 | 935 |
939 int SpdySession::DoReadComplete(int result) { | 936 int SpdySession::DoReadComplete(int result) { |
940 // Parse a frame. For now this code requires that the frame fit into our | 937 // Parse a frame. For now this code requires that the frame fit into our |
941 // buffer (32KB). | 938 // buffer (32KB). |
942 // TODO(mbelshe): support arbitrarily large frames! | 939 // TODO(mbelshe): support arbitrarily large frames! |
943 | 940 |
944 if (result <= 0) { | 941 if (result <= 0) { |
945 // Session is tearing down. | 942 // Session is tearing down. |
946 net::Error error = static_cast<net::Error>(result); | 943 net::Error error = static_cast<net::Error>(result); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 | 1069 |
1073 in_flight_write_ = *buffer; | 1070 in_flight_write_ = *buffer; |
1074 } else { | 1071 } else { |
1075 DCHECK(in_flight_write_.buffer()->BytesRemaining()); | 1072 DCHECK(in_flight_write_.buffer()->BytesRemaining()); |
1076 } | 1073 } |
1077 | 1074 |
1078 write_pending_ = true; | 1075 write_pending_ = true; |
1079 int rv = connection_->socket()->Write( | 1076 int rv = connection_->socket()->Write( |
1080 in_flight_write_.buffer(), | 1077 in_flight_write_.buffer(), |
1081 in_flight_write_.buffer()->BytesRemaining(), | 1078 in_flight_write_.buffer()->BytesRemaining(), |
1082 base::Bind(&SpdySession::OnWriteComplete, base::Unretained(this))); | 1079 base::Bind(&SpdySession::OnWriteComplete, weak_factory_.GetWeakPtr())); |
1083 if (rv == net::ERR_IO_PENDING) | 1080 if (rv == net::ERR_IO_PENDING) |
1084 break; | 1081 break; |
1085 | 1082 |
1086 // We sent the frame successfully. | 1083 // We sent the frame successfully. |
1087 OnWriteComplete(rv); | 1084 OnWriteComplete(rv); |
1088 | 1085 |
1089 // TODO(mbelshe): Test this error case. Maybe we should mark the socket | 1086 // TODO(mbelshe): Test this error case. Maybe we should mark the socket |
1090 // as in an error state. | 1087 // as in an error state. |
1091 if (rv < 0) | 1088 if (rv < 0) |
1092 break; | 1089 break; |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1547 } | 1544 } |
1548 | 1545 |
1549 // There should not be an existing pushed stream with the same path. | 1546 // There should not be an existing pushed stream with the same path. |
1550 PushedStreamMap::iterator it = unclaimed_pushed_streams_.find(url); | 1547 PushedStreamMap::iterator it = unclaimed_pushed_streams_.find(url); |
1551 if (it != unclaimed_pushed_streams_.end()) { | 1548 if (it != unclaimed_pushed_streams_.end()) { |
1552 ResetStream(stream_id, RST_STREAM_PROTOCOL_ERROR, | 1549 ResetStream(stream_id, RST_STREAM_PROTOCOL_ERROR, |
1553 "Received duplicate pushed stream with url: " + url); | 1550 "Received duplicate pushed stream with url: " + url); |
1554 return; | 1551 return; |
1555 } | 1552 } |
1556 | 1553 |
1557 scoped_refptr<SpdyStream> stream(new SpdyStream(this, true, net_log_)); | 1554 RequestPriority request_priority = |
| 1555 ConvertSpdyPriorityToRequestPriority(priority, GetProtocolVersion()); |
| 1556 scoped_refptr<SpdyStream> stream( |
| 1557 new SpdyStream(this, gurl.PathForRequest(), request_priority, |
| 1558 stream_initial_send_window_size_, |
| 1559 stream_initial_recv_window_size_, |
| 1560 true, net_log_)); |
1558 stream->set_stream_id(stream_id); | 1561 stream->set_stream_id(stream_id); |
1559 | 1562 |
1560 stream->set_path(gurl.PathForRequest()); | |
1561 stream->set_send_window_size(stream_initial_send_window_size_); | |
1562 stream->set_recv_window_size(stream_initial_recv_window_size_); | |
1563 | |
1564 DeleteExpiredPushedStreams(); | 1563 DeleteExpiredPushedStreams(); |
1565 unclaimed_pushed_streams_[url] = | 1564 unclaimed_pushed_streams_[url] = |
1566 std::pair<scoped_refptr<SpdyStream>, base::TimeTicks> ( | 1565 std::pair<scoped_refptr<SpdyStream>, base::TimeTicks> ( |
1567 stream, time_func_()); | 1566 stream, time_func_()); |
1568 | 1567 |
1569 | 1568 |
1570 ActivateStream(stream); | 1569 ActivateStream(stream); |
1571 stream->set_response_received(); | 1570 stream->set_response_received(); |
1572 | 1571 |
1573 // Parse the headers. | 1572 // Parse the headers. |
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2303 } | 2302 } |
2304 | 2303 |
2305 session_recv_window_size_ -= delta_window_size; | 2304 session_recv_window_size_ -= delta_window_size; |
2306 net_log_.AddEvent( | 2305 net_log_.AddEvent( |
2307 NetLog::TYPE_SPDY_SESSION_UPDATE_RECV_WINDOW, | 2306 NetLog::TYPE_SPDY_SESSION_UPDATE_RECV_WINDOW, |
2308 base::Bind(&NetLogSpdySessionWindowUpdateCallback, | 2307 base::Bind(&NetLogSpdySessionWindowUpdateCallback, |
2309 -delta_window_size, session_recv_window_size_)); | 2308 -delta_window_size, session_recv_window_size_)); |
2310 } | 2309 } |
2311 | 2310 |
2312 } // namespace net | 2311 } // namespace net |
OLD | NEW |