Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: net/spdy/write_blocked_list.h

Issue 822713002: Update from https://crrev.com/309415 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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_SPDY_WRITE_BLOCKED_LIST_H_ 5 #ifndef NET_SPDY_WRITE_BLOCKED_LIST_H_
6 #define NET_SPDY_WRITE_BLOCKED_LIST_H_ 6 #define NET_SPDY_WRITE_BLOCKED_LIST_H_
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <deque> 9 #include <deque>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "net/spdy/spdy_protocol.h" 12 #include "net/spdy/spdy_protocol.h"
13 13
14 namespace {
15 class WriteBlockedListPeer;
16 }
17
14 namespace net { 18 namespace net {
15 19
16 const int kHighestPriority = 0; 20 const int kHighestPriority = 0;
17 const int kLowestPriority = 7; 21 const int kLowestPriority = 7;
18 22
19 template <typename IdType> 23 template <typename IdType>
20 class WriteBlockedList { 24 class WriteBlockedList {
21 public: 25 public:
22 // 0(1) size lookup. 0(1) insert at front or back. 26 // 0(1) size lookup. 0(1) insert at front or back.
23 typedef std::deque<IdType> BlockedList; 27 typedef std::deque<IdType> BlockedList;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 return true; 73 return true;
70 } 74 }
71 } 75 }
72 return false; 76 return false;
73 } 77 }
74 78
75 void PushBack(IdType stream_id, SpdyPriority priority) { 79 void PushBack(IdType stream_id, SpdyPriority priority) {
76 write_blocked_lists_[ClampPriority(priority)].push_back(stream_id); 80 write_blocked_lists_[ClampPriority(priority)].push_back(stream_id);
77 } 81 }
78 82
79 void RemoveStreamFromWriteBlockedList(IdType stream_id, 83 bool RemoveStreamFromWriteBlockedList(IdType stream_id,
80 SpdyPriority priority) { 84 SpdyPriority priority) {
85 // We shouldn't really add a stream_id to a list multiple times,
86 // but under some conditions it does happen. Doing a check in PushBack
87 // would be too costly, so instead we check here to eliminate duplicates.
88 bool found = false;
81 iterator it = std::find(write_blocked_lists_[priority].begin(), 89 iterator it = std::find(write_blocked_lists_[priority].begin(),
82 write_blocked_lists_[priority].end(), 90 write_blocked_lists_[priority].end(),
83 stream_id); 91 stream_id);
84 while (it != write_blocked_lists_[priority].end()) { 92 while (it != write_blocked_lists_[priority].end()) {
85 write_blocked_lists_[priority].erase(it); 93 found = true;
86 it = std::find(write_blocked_lists_[priority].begin(), 94 iterator next_it = write_blocked_lists_[priority].erase(it);
87 write_blocked_lists_[priority].end(), 95 it = std::find(next_it, write_blocked_lists_[priority].end(), stream_id);
88 stream_id); 96 }
97 return found;
98 }
99
100 void UpdateStreamPriorityInWriteBlockedList(IdType stream_id,
101 SpdyPriority old_priority,
102 SpdyPriority new_priority) {
103 if (old_priority == new_priority) {
104 return;
105 }
106 bool found = RemoveStreamFromWriteBlockedList(stream_id, old_priority);
107 if (found) {
108 PushBack(stream_id, new_priority);
89 } 109 }
90 } 110 }
91 111
92 size_t NumBlockedStreams() const { 112 size_t NumBlockedStreams() const {
93 size_t num_blocked_streams = 0; 113 size_t num_blocked_streams = 0;
94 for (SpdyPriority i = kHighestPriority; i <= kLowestPriority; ++i) { 114 for (SpdyPriority i = kHighestPriority; i <= kLowestPriority; ++i) {
95 num_blocked_streams += write_blocked_lists_[i].size(); 115 num_blocked_streams += write_blocked_lists_[i].size();
96 } 116 }
97 return num_blocked_streams; 117 return num_blocked_streams;
98 } 118 }
99 119
100 private: 120 private:
121 friend WriteBlockedListPeer;
101 BlockedList write_blocked_lists_[kLowestPriority + 1]; 122 BlockedList write_blocked_lists_[kLowestPriority + 1];
102 }; 123 };
103 124
104 } // namespace net 125 } // namespace net
105 126
106 #endif // NET_SPDY_WRITE_BLOCKED_LIST_H_ 127 #endif // NET_SPDY_WRITE_BLOCKED_LIST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698