Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / net / quic / quic_write_blocked_list.h
blob3c08badd6162d03d9e3ca605712c1cb3376a17a2
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.
4 //
5 #ifndef NET_QUIC_QUIC_WRITE_BLOCKED_LIST_H_
6 #define NET_QUIC_QUIC_WRITE_BLOCKED_LIST_H_
8 #include <set>
10 #include "net/base/net_export.h"
11 #include "net/quic/quic_protocol.h"
12 #include "net/spdy/write_blocked_list.h"
14 namespace net {
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 {
20 private:
21 typedef WriteBlockedList<QuicStreamId> QuicWriteBlockedListBase;
23 public:
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_) {
41 ++num_blocked;
43 if (headers_stream_blocked_) {
44 ++num_blocked;
47 return num_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 return id;
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;
72 return;
75 if (stream_id == kHeadersStreamId) {
76 DCHECK_EQ(kHighestPriority, priority);
77 // TODO(avd) Add DCHECK(!headers_stream_blocked_);
78 headers_stream_blocked_ = true;
79 return;
82 base_write_blocked_list_.PushBack(
83 stream_id, static_cast<SpdyPriority>(priority));
84 return;
87 bool crypto_stream_blocked() const { return crypto_stream_blocked_; }
88 bool headers_stream_blocked() const { return headers_stream_blocked_; }
90 private:
91 QuicWriteBlockedListBase base_write_blocked_list_;
92 bool crypto_stream_blocked_;
93 bool headers_stream_blocked_;
95 DISALLOW_COPY_AND_ASSIGN(QuicWriteBlockedList);
98 } // namespace net
101 #endif // NET_QUIC_QUIC_WRITE_BLOCKED_LIST_H_