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 QuicWriteBlockedList();
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
);
67 void PushBack(QuicStreamId stream_id
, QuicPriority priority
) {
68 if (stream_id
== kCryptoStreamId
) {
69 DCHECK_EQ(kHighestPriority
, priority
);
70 // TODO(avd) Add DCHECK(!crypto_stream_blocked_)
71 crypto_stream_blocked_
= true;
75 if (stream_id
== kHeadersStreamId
) {
76 DCHECK_EQ(kHighestPriority
, priority
);
77 // TODO(avd) Add DCHECK(!headers_stream_blocked_);
78 headers_stream_blocked_
= true;
82 base_write_blocked_list_
.PushBack(
83 stream_id
, static_cast<SpdyPriority
>(priority
));
87 bool crypto_stream_blocked() const { return crypto_stream_blocked_
; }
88 bool headers_stream_blocked() const { return headers_stream_blocked_
; }
91 QuicWriteBlockedListBase base_write_blocked_list_
;
92 bool crypto_stream_blocked_
;
93 bool headers_stream_blocked_
;
95 DISALLOW_COPY_AND_ASSIGN(QuicWriteBlockedList
);
101 #endif // NET_QUIC_QUIC_WRITE_BLOCKED_LIST_H_