| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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_HTTP2_PRIORITY_DEPENDENCIES_H_ |
| 6 #define NET_HTTP2_PRIORITY_DEPENDENCIES_H_ |
| 7 |
| 8 #include <list> |
| 9 #include <map> |
| 10 |
| 11 #include "net/spdy/spdy_protocol.h" |
| 12 |
| 13 namespace net { |
| 14 |
| 15 // A helper class encapsulating the state and logic to set dependencies of |
| 16 // HTTP2 streams based on their SpdyPriority and the ordering |
| 17 // of creation and deletion of the streams. |
| 18 class NET_EXPORT_PRIVATE Http2PriorityDependencies { |
| 19 public: |
| 20 Http2PriorityDependencies(); |
| 21 ~Http2PriorityDependencies(); |
| 22 |
| 23 // Called when a stream SYN is sent to the server. Note that in the |
| 24 // case of server push, a stream may be created without this routine |
| 25 // being called. In such cases, the client ignores the stream's priority |
| 26 // (as the server is effectively overriding the client's notions of |
| 27 // priority anyway). |
| 28 // On return, |*dependent_stream_id| is set to the stream id that |
| 29 // this stream should be made dependent on, and |*exclusive| set to |
| 30 // whether that dependency should be exclusive. |
| 31 void OnStreamSynSent(SpdyStreamId id, |
| 32 SpdyPriority priority, |
| 33 SpdyStreamId* dependent_stream_id, |
| 34 bool* exclusive); |
| 35 |
| 36 void OnStreamDestruction(SpdyStreamId id); |
| 37 |
| 38 private: |
| 39 // The requirements for the internal data structure for this class are: |
| 40 // a) Constant time insertion of entries at the end of the list, |
| 41 // b) Fast removal of any entry based on its id. |
| 42 // c) Constant time lookup of the entry at the end of the list. |
| 43 // std::list would satisfy (a) & (c), but some form of map is |
| 44 // needed for (b). The priority must be included in the map |
| 45 // entries so that deletion can determine which list in id_priority_lists_ |
| 46 // to erase from. |
| 47 using IdList = std::list<std::pair<SpdyStreamId, SpdyPriority>>; |
| 48 using EntryMap = std::map<SpdyStreamId, IdList::iterator>; |
| 49 |
| 50 IdList id_priority_lists_[kV3LowestPriority + 1]; |
| 51 |
| 52 // Tracks the location of an id anywhere in the above vector of lists. |
| 53 // Iterators to list elements remain valid until those particular elements |
| 54 // are erased. |
| 55 EntryMap entry_by_stream_id_; |
| 56 }; |
| 57 |
| 58 } // namespace net |
| 59 |
| 60 #endif // NET_HTTP2_PRIORITY_DEPENDENCIES_H_ |
| OLD | NEW |