Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: net/spdy/spdy_session.cc

Issue 2458793002: Server push cancellation: add PushPromiseHelper which reflects information on the push promise. (Closed)
Patch Set: add PushDelegate Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 } 288 }
289 289
290 private: 290 private:
291 const base::WeakPtr<SpdyStreamRequest> request_; 291 const base::WeakPtr<SpdyStreamRequest> request_;
292 }; 292 };
293 293
294 // The maximum number of concurrent streams we will ever create. Even if 294 // The maximum number of concurrent streams we will ever create. Even if
295 // the server permits more, we will never exceed this limit. 295 // the server permits more, we will never exceed this limit.
296 const size_t kMaxConcurrentStreamLimit = 256; 296 const size_t kMaxConcurrentStreamLimit = 256;
297 297
298 class SpdyPushPromiseHelper : public PushPromiseHelper {
299 public:
300 explicit SpdyPushPromiseHelper(base::WeakPtr<SpdySession> session,
301 const GURL& url)
302 : session_(session), request_url_(url) {}
303
304 void Cancel() override {
305 if (session_) {
306 session_->CancelPush(request_url_);
307 }
Ryan Hamilton 2016/10/28 00:32:22 nit: no {}s on single line ifs in net code.
Zhongyi Shi 2016/11/07 22:07:03 Done.
308 }
309
310 const GURL& GetURL() override { return request_url_; }
311
312 private:
313 base::WeakPtr<SpdySession> session_;
314 const GURL request_url_;
315 };
316
298 } // namespace 317 } // namespace
299 318
300 SpdyProtocolErrorDetails MapFramerErrorToProtocolError( 319 SpdyProtocolErrorDetails MapFramerErrorToProtocolError(
301 SpdyFramer::SpdyError err) { 320 SpdyFramer::SpdyError err) {
302 switch (err) { 321 switch (err) {
303 case SpdyFramer::SPDY_NO_ERROR: 322 case SpdyFramer::SPDY_NO_ERROR:
304 return SPDY_ERROR_NO_ERROR; 323 return SPDY_ERROR_NO_ERROR;
305 case SpdyFramer::SPDY_INVALID_STREAM_ID: 324 case SpdyFramer::SPDY_INVALID_STREAM_ID:
306 return SPDY_ERROR_INVALID_STREAM_ID; 325 return SPDY_ERROR_INVALID_STREAM_ID;
307 case SpdyFramer::SPDY_INVALID_CONTROL_FRAME: 326 case SpdyFramer::SPDY_INVALID_CONTROL_FRAME:
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 NetLog* net_log) 656 NetLog* net_log)
638 : in_io_loop_(false), 657 : in_io_loop_(false),
639 spdy_session_key_(spdy_session_key), 658 spdy_session_key_(spdy_session_key),
640 pool_(NULL), 659 pool_(NULL),
641 http_server_properties_(http_server_properties), 660 http_server_properties_(http_server_properties),
642 transport_security_state_(transport_security_state), 661 transport_security_state_(transport_security_state),
643 read_buffer_(new IOBuffer(kReadBufferSize)), 662 read_buffer_(new IOBuffer(kReadBufferSize)),
644 stream_hi_water_mark_(kFirstStreamId), 663 stream_hi_water_mark_(kFirstStreamId),
645 last_accepted_push_stream_id_(0), 664 last_accepted_push_stream_id_(0),
646 unclaimed_pushed_streams_(this), 665 unclaimed_pushed_streams_(this),
666 push_delegate_(nullptr),
647 num_pushed_streams_(0u), 667 num_pushed_streams_(0u),
648 num_active_pushed_streams_(0u), 668 num_active_pushed_streams_(0u),
649 bytes_pushed_count_(0u), 669 bytes_pushed_count_(0u),
650 bytes_pushed_and_unclaimed_count_(0u), 670 bytes_pushed_and_unclaimed_count_(0u),
651 in_flight_write_frame_type_(DATA), 671 in_flight_write_frame_type_(DATA),
652 in_flight_write_frame_size_(0), 672 in_flight_write_frame_size_(0),
653 is_secure_(false), 673 is_secure_(false),
654 availability_state_(STATE_AVAILABLE), 674 availability_state_(STATE_AVAILABLE),
655 read_state_(READ_STATE_DO_READ), 675 read_state_(READ_STATE_DO_READ),
656 write_state_(WRITE_STATE_IDLE), 676 write_state_(WRITE_STATE_IDLE),
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 return ERR_CONNECTION_CLOSED; 795 return ERR_CONNECTION_CLOSED;
776 796
777 *stream = GetActivePushStream(url); 797 *stream = GetActivePushStream(url);
778 if (*stream) { 798 if (*stream) {
779 DCHECK_LT(streams_pushed_and_claimed_count_, streams_pushed_count_); 799 DCHECK_LT(streams_pushed_and_claimed_count_, streams_pushed_count_);
780 streams_pushed_and_claimed_count_++; 800 streams_pushed_and_claimed_count_++;
781 } 801 }
782 return OK; 802 return OK;
783 } 803 }
784 804
805 void SpdySession::CancelPush(const GURL& url) {
Ryan Hamilton 2016/10/28 00:32:22 Instead of canceling by URL, if we passed the prom
Zhongyi Shi 2016/11/07 22:07:04 We could definitely do that, but considering we wi
806 UnclaimedPushedStreamContainer::const_iterator unclaimed_it =
807 unclaimed_pushed_streams_.find(url);
808 if (unclaimed_it == unclaimed_pushed_streams_.end())
809 return;
810
811 SpdyStreamId stream_id = unclaimed_it->second.stream_id;
812
813 if (active_streams_.find(stream_id) == active_streams_.end()) {
814 ResetStream(stream_id, RST_STREAM_CANCEL,
815 "Cancelled push stream with url: " + url.spec());
816 }
817 unclaimed_pushed_streams_.erase(unclaimed_it);
818 }
819
785 // {,Try}CreateStream() can be called with |in_io_loop_| set if a stream is 820 // {,Try}CreateStream() can be called with |in_io_loop_| set if a stream is
786 // being created in response to another being closed due to received data. 821 // being created in response to another being closed due to received data.
787 822
788 int SpdySession::TryCreateStream( 823 int SpdySession::TryCreateStream(
789 const base::WeakPtr<SpdyStreamRequest>& request, 824 const base::WeakPtr<SpdyStreamRequest>& request,
790 base::WeakPtr<SpdyStream>* stream) { 825 base::WeakPtr<SpdyStream>* stream) {
791 DCHECK(request); 826 DCHECK(request);
792 827
793 if (availability_state_ == STATE_GOING_AWAY) 828 if (availability_state_ == STATE_GOING_AWAY)
794 return ERR_FAILED; 829 return ERR_FAILED;
(...skipping 1831 matching lines...) Expand 10 before | Expand all | Expand 10 after
2626 DeleteExpiredPushedStreams(); 2661 DeleteExpiredPushedStreams();
2627 2662
2628 InsertActivatedStream(std::move(stream)); 2663 InsertActivatedStream(std::move(stream));
2629 2664
2630 ActiveStreamMap::iterator active_it = active_streams_.find(stream_id); 2665 ActiveStreamMap::iterator active_it = active_streams_.find(stream_id);
2631 if (active_it == active_streams_.end()) { 2666 if (active_it == active_streams_.end()) {
2632 NOTREACHED(); 2667 NOTREACHED();
2633 return false; 2668 return false;
2634 } 2669 }
2635 2670
2671 // Notify the push_delegate that a push promise has been received.
2672 if (push_delegate_) {
2673 push_delegate_->OnPush(base::MakeUnique<SpdyPushPromiseHelper>(
2674 weak_factory_.GetWeakPtr(), gurl));
2675 }
2676
2636 active_it->second.stream->OnPushPromiseHeadersReceived(std::move(headers)); 2677 active_it->second.stream->OnPushPromiseHeadersReceived(std::move(headers));
2637 DCHECK(active_it->second.stream->IsReservedRemote()); 2678 DCHECK(active_it->second.stream->IsReservedRemote());
2638 num_pushed_streams_++; 2679 num_pushed_streams_++;
2639 return true; 2680 return true;
2640 } 2681 }
2641 2682
2642 void SpdySession::CancelPush(const GURL& url) {
2643 UnclaimedPushedStreamContainer::const_iterator unclaimed_it =
2644 unclaimed_pushed_streams_.find(url);
2645 if (unclaimed_it == unclaimed_pushed_streams_.end())
2646 return;
2647
2648 SpdyStreamId stream_id = unclaimed_it->second.stream_id;
2649
2650 if (active_streams_.find(stream_id) == active_streams_.end()) {
2651 ResetStream(stream_id, RST_STREAM_CANCEL,
2652 "Cancelled push stream with url: " + url.spec());
2653 }
2654 unclaimed_pushed_streams_.erase(unclaimed_it);
2655 }
2656
2657 void SpdySession::OnPushPromise(SpdyStreamId stream_id, 2683 void SpdySession::OnPushPromise(SpdyStreamId stream_id,
2658 SpdyStreamId promised_stream_id, 2684 SpdyStreamId promised_stream_id,
2659 SpdyHeaderBlock headers) { 2685 SpdyHeaderBlock headers) {
2660 CHECK(in_io_loop_); 2686 CHECK(in_io_loop_);
2661 2687
2662 if (net_log_.IsCapturing()) { 2688 if (net_log_.IsCapturing()) {
2663 net_log_.AddEvent(NetLogEventType::HTTP2_SESSION_RECV_PUSH_PROMISE, 2689 net_log_.AddEvent(NetLogEventType::HTTP2_SESSION_RECV_PUSH_PROMISE,
2664 base::Bind(&NetLogSpdyPushPromiseReceivedCallback, 2690 base::Bind(&NetLogSpdyPushPromiseReceivedCallback,
2665 &headers, stream_id, promised_stream_id)); 2691 &headers, stream_id, promised_stream_id));
2666 } 2692 }
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
3133 if (!queue->empty()) { 3159 if (!queue->empty()) {
3134 SpdyStreamId stream_id = queue->front(); 3160 SpdyStreamId stream_id = queue->front();
3135 queue->pop_front(); 3161 queue->pop_front();
3136 return stream_id; 3162 return stream_id;
3137 } 3163 }
3138 } 3164 }
3139 return 0; 3165 return 0;
3140 } 3166 }
3141 3167
3142 } // namespace net 3168 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698