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 <limits> | 8 #include <limits> |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "net/http/http_util.h" | 38 #include "net/http/http_util.h" |
39 #include "net/http/transport_security_state.h" | 39 #include "net/http/transport_security_state.h" |
40 #include "net/log/net_log.h" | 40 #include "net/log/net_log.h" |
41 #include "net/log/net_log_capture_mode.h" | 41 #include "net/log/net_log_capture_mode.h" |
42 #include "net/log/net_log_event_type.h" | 42 #include "net/log/net_log_event_type.h" |
43 #include "net/log/net_log_source.h" | 43 #include "net/log/net_log_source.h" |
44 #include "net/log/net_log_source_type.h" | 44 #include "net/log/net_log_source_type.h" |
45 #include "net/log/net_log_with_source.h" | 45 #include "net/log/net_log_with_source.h" |
46 #include "net/proxy/proxy_server.h" | 46 #include "net/proxy/proxy_server.h" |
47 #include "net/socket/ssl_client_socket.h" | 47 #include "net/socket/ssl_client_socket.h" |
| 48 #include "net/spdy/push_promise_helper.h" |
48 #include "net/spdy/spdy_buffer_producer.h" | 49 #include "net/spdy/spdy_buffer_producer.h" |
49 #include "net/spdy/spdy_frame_builder.h" | 50 #include "net/spdy/spdy_frame_builder.h" |
50 #include "net/spdy/spdy_http_utils.h" | 51 #include "net/spdy/spdy_http_utils.h" |
51 #include "net/spdy/spdy_protocol.h" | 52 #include "net/spdy/spdy_protocol.h" |
52 #include "net/spdy/spdy_session_pool.h" | 53 #include "net/spdy/spdy_session_pool.h" |
53 #include "net/spdy/spdy_stream.h" | 54 #include "net/spdy/spdy_stream.h" |
54 #include "net/ssl/channel_id_service.h" | 55 #include "net/ssl/channel_id_service.h" |
55 #include "net/ssl/ssl_cipher_suite_names.h" | 56 #include "net/ssl/ssl_cipher_suite_names.h" |
56 #include "net/ssl/ssl_connection_status_flags.h" | 57 #include "net/ssl/ssl_connection_status_flags.h" |
57 | 58 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 } | 289 } |
289 | 290 |
290 private: | 291 private: |
291 const base::WeakPtr<SpdyStreamRequest> request_; | 292 const base::WeakPtr<SpdyStreamRequest> request_; |
292 }; | 293 }; |
293 | 294 |
294 // The maximum number of concurrent streams we will ever create. Even if | 295 // The maximum number of concurrent streams we will ever create. Even if |
295 // the server permits more, we will never exceed this limit. | 296 // the server permits more, we will never exceed this limit. |
296 const size_t kMaxConcurrentStreamLimit = 256; | 297 const size_t kMaxConcurrentStreamLimit = 256; |
297 | 298 |
| 299 class SpdyPushPromiseHelper : public PushPromiseHelper { |
| 300 public: |
| 301 explicit SpdyPushPromiseHelper(base::WeakPtr<SpdySession> session, |
| 302 const GURL& url) |
| 303 : session_(session), request_url_(url) {} |
| 304 |
| 305 void Cancel() override { |
| 306 if (session_) { |
| 307 session_->CancelPush(request_url_); |
| 308 } |
| 309 } |
| 310 |
| 311 const GURL& GetURL() override { return request_url_; } |
| 312 |
| 313 private: |
| 314 base::WeakPtr<SpdySession> session_; |
| 315 const GURL request_url_; |
| 316 }; |
| 317 |
298 } // namespace | 318 } // namespace |
299 | 319 |
300 SpdyProtocolErrorDetails MapFramerErrorToProtocolError( | 320 SpdyProtocolErrorDetails MapFramerErrorToProtocolError( |
301 SpdyFramer::SpdyError err) { | 321 SpdyFramer::SpdyError err) { |
302 switch (err) { | 322 switch (err) { |
303 case SpdyFramer::SPDY_NO_ERROR: | 323 case SpdyFramer::SPDY_NO_ERROR: |
304 return SPDY_ERROR_NO_ERROR; | 324 return SPDY_ERROR_NO_ERROR; |
305 case SpdyFramer::SPDY_INVALID_STREAM_ID: | 325 case SpdyFramer::SPDY_INVALID_STREAM_ID: |
306 return SPDY_ERROR_INVALID_STREAM_ID; | 326 return SPDY_ERROR_INVALID_STREAM_ID; |
307 case SpdyFramer::SPDY_INVALID_CONTROL_FRAME: | 327 case SpdyFramer::SPDY_INVALID_CONTROL_FRAME: |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 return ERR_CONNECTION_CLOSED; | 793 return ERR_CONNECTION_CLOSED; |
774 | 794 |
775 *stream = GetActivePushStream(url); | 795 *stream = GetActivePushStream(url); |
776 if (*stream) { | 796 if (*stream) { |
777 DCHECK_LT(streams_pushed_and_claimed_count_, streams_pushed_count_); | 797 DCHECK_LT(streams_pushed_and_claimed_count_, streams_pushed_count_); |
778 streams_pushed_and_claimed_count_++; | 798 streams_pushed_and_claimed_count_++; |
779 } | 799 } |
780 return OK; | 800 return OK; |
781 } | 801 } |
782 | 802 |
| 803 void SpdySession::CancelPush(const GURL& url) { |
| 804 UnclaimedPushedStreamContainer::const_iterator unclaimed_it = |
| 805 unclaimed_pushed_streams_.find(url); |
| 806 if (unclaimed_it == unclaimed_pushed_streams_.end()) |
| 807 return; |
| 808 |
| 809 SpdyStreamId stream_id = unclaimed_it->second.stream_id; |
| 810 |
| 811 if (active_streams_.find(stream_id) == active_streams_.end()) { |
| 812 ResetStream(stream_id, RST_STREAM_CANCEL, |
| 813 "Cancelled push stream with url: " + url.spec()); |
| 814 } |
| 815 unclaimed_pushed_streams_.erase(unclaimed_it); |
| 816 } |
| 817 |
783 // {,Try}CreateStream() can be called with |in_io_loop_| set if a stream is | 818 // {,Try}CreateStream() can be called with |in_io_loop_| set if a stream is |
784 // being created in response to another being closed due to received data. | 819 // being created in response to another being closed due to received data. |
785 | 820 |
786 int SpdySession::TryCreateStream( | 821 int SpdySession::TryCreateStream( |
787 const base::WeakPtr<SpdyStreamRequest>& request, | 822 const base::WeakPtr<SpdyStreamRequest>& request, |
788 base::WeakPtr<SpdyStream>* stream) { | 823 base::WeakPtr<SpdyStream>* stream) { |
789 DCHECK(request); | 824 DCHECK(request); |
790 | 825 |
791 if (availability_state_ == STATE_GOING_AWAY) | 826 if (availability_state_ == STATE_GOING_AWAY) |
792 return ERR_FAILED; | 827 return ERR_FAILED; |
(...skipping 1837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2630 NOTREACHED(); | 2665 NOTREACHED(); |
2631 return false; | 2666 return false; |
2632 } | 2667 } |
2633 | 2668 |
2634 active_it->second.stream->OnPushPromiseHeadersReceived(std::move(headers)); | 2669 active_it->second.stream->OnPushPromiseHeadersReceived(std::move(headers)); |
2635 DCHECK(active_it->second.stream->IsReservedRemote()); | 2670 DCHECK(active_it->second.stream->IsReservedRemote()); |
2636 num_pushed_streams_++; | 2671 num_pushed_streams_++; |
2637 return true; | 2672 return true; |
2638 } | 2673 } |
2639 | 2674 |
2640 void SpdySession::CancelPush(const GURL& url) { | |
2641 UnclaimedPushedStreamContainer::const_iterator unclaimed_it = | |
2642 unclaimed_pushed_streams_.find(url); | |
2643 if (unclaimed_it == unclaimed_pushed_streams_.end()) | |
2644 return; | |
2645 | |
2646 SpdyStreamId stream_id = unclaimed_it->second.stream_id; | |
2647 | |
2648 if (active_streams_.find(stream_id) == active_streams_.end()) { | |
2649 ResetStream(stream_id, RST_STREAM_CANCEL, | |
2650 "Cancelled push stream with url: " + url.spec()); | |
2651 } | |
2652 unclaimed_pushed_streams_.erase(unclaimed_it); | |
2653 } | |
2654 | |
2655 void SpdySession::OnPushPromise(SpdyStreamId stream_id, | 2675 void SpdySession::OnPushPromise(SpdyStreamId stream_id, |
2656 SpdyStreamId promised_stream_id, | 2676 SpdyStreamId promised_stream_id, |
2657 SpdyHeaderBlock headers) { | 2677 SpdyHeaderBlock headers) { |
2658 CHECK(in_io_loop_); | 2678 CHECK(in_io_loop_); |
2659 | 2679 |
2660 if (net_log_.IsCapturing()) { | 2680 if (net_log_.IsCapturing()) { |
2661 net_log_.AddEvent(NetLogEventType::HTTP2_SESSION_RECV_PUSH_PROMISE, | 2681 net_log_.AddEvent(NetLogEventType::HTTP2_SESSION_RECV_PUSH_PROMISE, |
2662 base::Bind(&NetLogSpdyPushPromiseReceivedCallback, | 2682 base::Bind(&NetLogSpdyPushPromiseReceivedCallback, |
2663 &headers, stream_id, promised_stream_id)); | 2683 &headers, stream_id, promised_stream_id)); |
2664 } | 2684 } |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3131 if (!queue->empty()) { | 3151 if (!queue->empty()) { |
3132 SpdyStreamId stream_id = queue->front(); | 3152 SpdyStreamId stream_id = queue->front(); |
3133 queue->pop_front(); | 3153 queue->pop_front(); |
3134 return stream_id; | 3154 return stream_id; |
3135 } | 3155 } |
3136 } | 3156 } |
3137 return 0; | 3157 return 0; |
3138 } | 3158 } |
3139 | 3159 |
3140 } // namespace net | 3160 } // namespace net |
OLD | NEW |