OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef NET_QUIC_QUIC_WRITE_BLOCKED_LIST_H_ | 5 #ifndef NET_QUIC_QUIC_WRITE_BLOCKED_LIST_H_ |
6 #define NET_QUIC_QUIC_WRITE_BLOCKED_LIST_H_ | 6 #define NET_QUIC_QUIC_WRITE_BLOCKED_LIST_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "net/base/net_export.h" | 10 #include "net/base/net_export.h" |
11 #include "net/quic/quic_flags.h" | 11 #include "net/quic/quic_flags.h" |
12 #include "net/quic/quic_protocol.h" | 12 #include "net/quic/quic_protocol.h" |
13 #include "net/spdy/write_blocked_list.h" | 13 #include "net/spdy/write_blocked_list.h" |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 | 16 |
17 // Keeps tracks of the QUIC streams that have data to write, sorted by | 17 // Keeps tracks of the QUIC streams that have data to write, sorted by |
18 // priority. QUIC stream priority order is: | 18 // priority. QUIC stream priority order is: |
19 // Crypto stream > Headers stream > Data streams by requested priority. | 19 // Crypto stream > Headers stream > Data streams by requested priority. |
20 class NET_EXPORT_PRIVATE QuicWriteBlockedList { | 20 class NET_EXPORT_PRIVATE QuicWriteBlockedList { |
21 private: | 21 private: |
22 typedef WriteBlockedList<QuicStreamId> QuicWriteBlockedListBase; | 22 typedef WriteBlockedList<QuicStreamId> QuicWriteBlockedListBase; |
23 | 23 |
24 public: | 24 public: |
25 static const QuicPriority kHighestPriority = | |
26 static_cast<QuicPriority>(net::kHighestPriority); | |
27 static const QuicPriority kLowestPriority = | |
28 static_cast<QuicPriority>(net::kLowestPriority); | |
29 | |
30 QuicWriteBlockedList(); | 25 QuicWriteBlockedList(); |
31 ~QuicWriteBlockedList(); | 26 ~QuicWriteBlockedList(); |
32 | 27 |
33 bool HasWriteBlockedDataStreams() const { | 28 bool HasWriteBlockedDataStreams() const { |
34 return base_write_blocked_list_.HasWriteBlockedStreams(); | 29 return base_write_blocked_list_.HasWriteBlockedStreams(); |
35 } | 30 } |
36 | 31 |
37 bool HasWriteBlockedCryptoOrHeadersStream() const { | 32 bool HasWriteBlockedCryptoOrHeadersStream() const { |
38 return crypto_stream_blocked_ || headers_stream_blocked_; | 33 return crypto_stream_blocked_ || headers_stream_blocked_; |
39 } | 34 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 batch_write_stream_id_[last_priority_popped_] == 0 || | 91 batch_write_stream_id_[last_priority_popped_] == 0 || |
97 bytes == 0); | 92 bytes == 0); |
98 } | 93 } |
99 } | 94 } |
100 } | 95 } |
101 | 96 |
102 // Pushes a stream to the back of the std::list for this priority level *unles
s* it | 97 // Pushes a stream to the back of the std::list for this priority level *unles
s* it |
103 // is latched for doing batched writes in which case it goes to the front of | 98 // is latched for doing batched writes in which case it goes to the front of |
104 // the std::list for this priority level. | 99 // the std::list for this priority level. |
105 // Headers and crypto streams are special cased to always resume first. | 100 // Headers and crypto streams are special cased to always resume first. |
106 void AddStream(QuicStreamId stream_id, QuicPriority priority) { | 101 void AddStream(QuicStreamId stream_id, SpdyPriority priority) { |
107 if (stream_id == kCryptoStreamId) { | 102 if (stream_id == kCryptoStreamId) { |
108 DCHECK_EQ(kHighestPriority, priority); | 103 DCHECK_EQ(net::kHighestPriority, priority); |
109 // TODO(avd) Add DCHECK(!crypto_stream_blocked_) | 104 // TODO(avd) Add DCHECK(!crypto_stream_blocked_) |
110 crypto_stream_blocked_ = true; | 105 crypto_stream_blocked_ = true; |
111 return; | 106 return; |
112 } | 107 } |
113 | 108 |
114 if (stream_id == kHeadersStreamId) { | 109 if (stream_id == kHeadersStreamId) { |
115 DCHECK_EQ(kHighestPriority, priority); | 110 DCHECK_EQ(net::kHighestPriority, priority); |
116 // TODO(avd) Add DCHECK(!headers_stream_blocked_); | 111 // TODO(avd) Add DCHECK(!headers_stream_blocked_); |
117 headers_stream_blocked_ = true; | 112 headers_stream_blocked_ = true; |
118 return; | 113 return; |
119 } | 114 } |
120 if (FLAGS_quic_batch_writes && | 115 if (FLAGS_quic_batch_writes && |
121 stream_id == batch_write_stream_id_[last_priority_popped_] && | 116 stream_id == batch_write_stream_id_[last_priority_popped_] && |
122 bytes_left_for_batch_write_[last_priority_popped_] > 0) { | 117 bytes_left_for_batch_write_[last_priority_popped_] > 0) { |
123 // If the batch write stream has more data to write, push it to the front | 118 // If the batch write stream has more data to write, push it to the front |
124 // for its priority level. | 119 // for its priority level. |
125 base_write_blocked_list_.PushFront( | 120 base_write_blocked_list_.PushFront(stream_id, priority); |
126 stream_id, static_cast<SpdyPriority>(priority)); | |
127 } else { | 121 } else { |
128 base_write_blocked_list_.PushBack( | 122 base_write_blocked_list_.PushBack(stream_id, priority); |
129 stream_id, static_cast<SpdyPriority>(priority)); | |
130 } | 123 } |
131 return; | 124 return; |
132 } | 125 } |
133 | 126 |
134 bool crypto_stream_blocked() const { return crypto_stream_blocked_; } | 127 bool crypto_stream_blocked() const { return crypto_stream_blocked_; } |
135 bool headers_stream_blocked() const { return headers_stream_blocked_; } | 128 bool headers_stream_blocked() const { return headers_stream_blocked_; } |
136 | 129 |
137 private: | 130 private: |
138 QuicWriteBlockedListBase base_write_blocked_list_; | 131 QuicWriteBlockedListBase base_write_blocked_list_; |
139 | 132 |
140 // If performing batch writes, this will be the stream ID of the stream doing | 133 // If performing batch writes, this will be the stream ID of the stream doing |
141 // batch writes for this priority level. We will allow this stream to write | 134 // batch writes for this priority level. We will allow this stream to write |
142 // until it has written kBatchWriteSize bytes, it has no more data to write, | 135 // until it has written kBatchWriteSize bytes, it has no more data to write, |
143 // or a higher priority stream preempts. | 136 // or a higher priority stream preempts. |
144 QuicStreamId batch_write_stream_id_[kLowestPriority + 1]; | 137 QuicStreamId batch_write_stream_id_[kLowestPriority + 1]; |
145 // Set to kBatchWriteSize when we set a new batch_write_stream_id_ for a given | 138 // Set to kBatchWriteSize when we set a new batch_write_stream_id_ for a given |
146 // priority. This is decremented with each write the stream does until it is | 139 // priority. This is decremented with each write the stream does until it is |
147 // done with its batch write. | 140 // done with its batch write. |
148 int32 bytes_left_for_batch_write_[kLowestPriority + 1]; | 141 int32 bytes_left_for_batch_write_[kLowestPriority + 1]; |
149 // Tracks the last priority popped for UpdateBytesForStream. | 142 // Tracks the last priority popped for UpdateBytesForStream. |
150 QuicPriority last_priority_popped_; | 143 SpdyPriority last_priority_popped_; |
151 | 144 |
152 bool crypto_stream_blocked_; | 145 bool crypto_stream_blocked_; |
153 bool headers_stream_blocked_; | 146 bool headers_stream_blocked_; |
154 | 147 |
155 DISALLOW_COPY_AND_ASSIGN(QuicWriteBlockedList); | 148 DISALLOW_COPY_AND_ASSIGN(QuicWriteBlockedList); |
156 }; | 149 }; |
157 | 150 |
158 } // namespace net | 151 } // namespace net |
159 | 152 |
160 | 153 |
161 #endif // NET_QUIC_QUIC_WRITE_BLOCKED_LIST_H_ | 154 #endif // NET_QUIC_QUIC_WRITE_BLOCKED_LIST_H_ |
OLD | NEW |