1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_QUIC_QUIC_WRITE_BLOCKED_LIST_H_
6 #define NET_QUIC_QUIC_WRITE_BLOCKED_LIST_H_
10 #include "net/base/net_export.h"
11 #include "net/quic/quic_protocol.h"
12 #include "net/spdy/write_blocked_list.h"
16 // Keeps tracks of the QUIC streams that have data to write, sorted by
17 // priority. QUIC stream priority order is:
18 // Crypto stream > Headers stream > Data streams by requested priority.
19 class NET_EXPORT_PRIVATE QuicWriteBlockedList
{
21 typedef WriteBlockedList
<QuicStreamId
> QuicWriteBlockedListBase
;
24 static const QuicPriority kHighestPriority
;
25 static const QuicPriority kLowestPriority
;
27 explicit QuicWriteBlockedList(bool avoid_duplicate_streams
);
28 ~QuicWriteBlockedList();
30 bool HasWriteBlockedDataStreams() const {
31 return base_write_blocked_list_
.HasWriteBlockedStreams();
34 bool HasWriteBlockedCryptoOrHeadersStream() const {
35 return crypto_stream_blocked_
|| headers_stream_blocked_
;
38 size_t NumBlockedStreams() const {
39 size_t num_blocked
= base_write_blocked_list_
.NumBlockedStreams();
40 if (crypto_stream_blocked_
) {
43 if (headers_stream_blocked_
) {
50 QuicStreamId
PopFront() {
51 if (crypto_stream_blocked_
) {
52 crypto_stream_blocked_
= false;
53 return kCryptoStreamId
;
56 if (headers_stream_blocked_
) {
57 headers_stream_blocked_
= false;
58 return kHeadersStreamId
;
61 SpdyPriority priority
=
62 base_write_blocked_list_
.GetHighestPriorityWriteBlockedList();
63 QuicStreamId id
= base_write_blocked_list_
.PopFront(priority
);
64 blocked_streams_
.erase(id
);
68 void PushBack(QuicStreamId stream_id
, QuicPriority priority
) {
69 if (stream_id
== kCryptoStreamId
) {
70 DCHECK_EQ(kHighestPriority
, priority
);
71 // TODO(avd) Add DCHECK(!crypto_stream_blocked_)
72 crypto_stream_blocked_
= true;
76 if (stream_id
== kHeadersStreamId
) {
77 DCHECK_EQ(kHighestPriority
, priority
);
78 // TODO(avd) Add DCHECK(!headers_stream_blocked_);
79 headers_stream_blocked_
= true;
83 if (!base_write_blocked_list_
.avoids_inserting_duplicates() &&
84 blocked_streams_
.find(stream_id
) != blocked_streams_
.end()) {
85 DVLOG(1) << "Stream " << stream_id
<< " already in write blocked list.";
89 base_write_blocked_list_
.PushBack(
90 stream_id
, static_cast<SpdyPriority
>(priority
));
91 blocked_streams_
.insert(stream_id
);
95 bool crypto_stream_blocked() const { return crypto_stream_blocked_
; }
96 bool headers_stream_blocked() const { return headers_stream_blocked_
; }
99 QuicWriteBlockedListBase base_write_blocked_list_
;
100 bool crypto_stream_blocked_
;
101 bool headers_stream_blocked_
;
103 // Keep track of write blocked streams in a set for faster membership checking
104 // than iterating over the base_write_blocked_list_. The contents of this set
105 // should mirror the contents of base_write_blocked_list_.
106 std::set
<QuicStreamId
> blocked_streams_
;
108 DISALLOW_COPY_AND_ASSIGN(QuicWriteBlockedList
);
114 #endif // NET_QUIC_QUIC_WRITE_BLOCKED_LIST_H_