file_manager: Fix a bug where hosted documents could not be opened without active...
[chromium-blink-merge.git] / net / spdy / write_blocked_list.h
blobfe5668fae8aae610d31487b8577ec0cfd91b8d07
1 // Copyright 2013 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_SPDY_WRITE_BLOCKED_LIST_H_
6 #define NET_SPDY_WRITE_BLOCKED_LIST_H_
8 #include <algorithm>
9 #include <deque>
11 #include "base/logging.h"
13 namespace net {
15 const int kHighestPriority = 0;
16 const int kLowestPriority = 7;
18 template <typename IdType>
19 class WriteBlockedList {
20 public:
21 // 0(1) size lookup. 0(1) insert at front or back.
22 typedef std::deque<IdType> BlockedList;
23 typedef typename BlockedList::iterator iterator;
25 // Returns the priority of the highest priority list with sessions on it, or
26 // -1 if none of the lists have pending sessions.
27 int GetHighestPriorityWriteBlockedList() const {
28 for (int i = 0; i <= kLowestPriority; ++i) {
29 if (write_blocked_lists_[i].size() > 0)
30 return i;
32 return -1;
35 int PopFront(int priority) {
36 DCHECK(!write_blocked_lists_[priority].empty());
37 IdType stream_id = write_blocked_lists_[priority].front();
38 write_blocked_lists_[priority].pop_front();
39 return stream_id;
42 bool HasWriteBlockedStreamsGreaterThanPriority(int priority) const {
43 for (int i = kHighestPriority; i < priority; ++i) {
44 if (!write_blocked_lists_[i].empty()) {
45 return true;
48 return false;
51 bool HasWriteBlockedStreams() const {
52 return HasWriteBlockedStreamsGreaterThanPriority(kLowestPriority + 1);
55 void PushBack(IdType stream_id, int priority) {
56 write_blocked_lists_[priority].push_back(stream_id);
59 void RemoveStreamFromWriteBlockedList(IdType stream_id, int priority) {
60 iterator it = std::find(write_blocked_lists_[priority].begin(),
61 write_blocked_lists_[priority].end(),
62 stream_id);
63 while (it != write_blocked_lists_[priority].end()) {
64 write_blocked_lists_[priority].erase(it);
65 it = std::find(write_blocked_lists_[priority].begin(),
66 write_blocked_lists_[priority].end(),
67 stream_id);
71 int NumBlockedStreams() {
72 int num_blocked_streams = 0;
73 for (int i = kHighestPriority; i <= kLowestPriority; ++i) {
74 num_blocked_streams += write_blocked_lists_[i].size();
76 return num_blocked_streams;
79 private:
80 // Priority ranges from 0 to 7
81 BlockedList write_blocked_lists_[8];
84 } // namespace net
86 #endif // NET_SPDY_WRITE_BLOCKED_LIST_H_