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_SPDY_HPACK_HEADER_TABLE_H_ | 5 #ifndef NET_SPDY_HPACK_HEADER_TABLE_H_ |
6 #define NET_SPDY_HPACK_HEADER_TABLE_H_ | 6 #define NET_SPDY_HPACK_HEADER_TABLE_H_ |
7 | 7 |
8 #include <cstddef> | 8 #include <cstddef> |
9 #include <deque> | 9 #include <deque> |
| 10 #include <memory> |
10 #include <unordered_map> | 11 #include <unordered_map> |
11 #include <unordered_set> | 12 #include <unordered_set> |
12 | 13 |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
15 #include "net/base/net_export.h" | 16 #include "net/base/net_export.h" |
16 #include "net/spdy/hpack/hpack_entry.h" | 17 #include "net/spdy/hpack/hpack_entry.h" |
17 | 18 |
18 // All section references below are to http://tools.ietf.org/html/rfc7541. | 19 // All section references below are to http://tools.ietf.org/html/rfc7541. |
19 | 20 |
20 namespace net { | 21 namespace net { |
21 | 22 |
22 namespace test { | 23 namespace test { |
23 class HpackHeaderTablePeer; | 24 class HpackHeaderTablePeer; |
24 } // namespace test | 25 } // namespace test |
25 | 26 |
26 // A data structure for the static table (2.3.1) and the dynamic table (2.3.2). | 27 // A data structure for the static table (2.3.1) and the dynamic table (2.3.2). |
27 class NET_EXPORT_PRIVATE HpackHeaderTable { | 28 class NET_EXPORT_PRIVATE HpackHeaderTable { |
28 public: | 29 public: |
29 friend class test::HpackHeaderTablePeer; | 30 friend class test::HpackHeaderTablePeer; |
30 | 31 |
| 32 // Debug visitor my be used to extract debug/internal information |
| 33 // about the HpackHeaderTable as it operates. |
| 34 // |
| 35 // Most HpackHeaderTable implementations do not need to bother with |
| 36 // this interface at all. |
| 37 class DebugVisitorInterface { |
| 38 public: |
| 39 virtual ~DebugVisitorInterface() {} |
| 40 |
| 41 // |OnNewEntry()| and |OnUseEntry()| can be used together to |
| 42 // gather data about the distribution of time intervals between |
| 43 // creation and reference of entries in the dynamic table. The |
| 44 // data is desired to sanity check a proposed extension to HPACK |
| 45 // for QUIC that would eliminate inter-stream head of line |
| 46 // blocking (due to standard HPACK). The visitor should return |
| 47 // the current time from |OnNewEntry()|, which will be passed |
| 48 // to |OnUseEntry()| each time that particular entry is used to |
| 49 // emit an indexed representation. |
| 50 virtual int64_t OnNewEntry(const HpackEntry& entry) = 0; |
| 51 virtual void OnUseEntry(const HpackEntry& entry) = 0; |
| 52 }; |
| 53 |
31 // HpackHeaderTable takes advantage of the deque property that references | 54 // HpackHeaderTable takes advantage of the deque property that references |
32 // remain valid, so long as insertions & deletions are at the head & tail. | 55 // remain valid, so long as insertions & deletions are at the head & tail. |
33 // If this changes (eg we start to drop entries from the middle of the table), | 56 // If this changes (eg we start to drop entries from the middle of the table), |
34 // this needs to be a std::list, in which case |*_index_| can be trivially | 57 // this needs to be a std::list, in which case |*_index_| can be trivially |
35 // extended to map to list iterators. | 58 // extended to map to list iterators. |
36 typedef std::deque<HpackEntry> EntryTable; | 59 typedef std::deque<HpackEntry> EntryTable; |
37 | 60 |
38 struct NET_EXPORT_PRIVATE EntryHasher { | 61 struct NET_EXPORT_PRIVATE EntryHasher { |
39 size_t operator()(const HpackEntry* entry) const; | 62 size_t operator()(const HpackEntry* entry) const; |
40 }; | 63 }; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 114 |
92 // Adds an entry for the representation, evicting entries as needed. |name| | 115 // Adds an entry for the representation, evicting entries as needed. |name| |
93 // and |value| must not be owned by an entry which could be evicted. The | 116 // and |value| must not be owned by an entry which could be evicted. The |
94 // added HpackEntry is returned, or NULL is returned if all entries were | 117 // added HpackEntry is returned, or NULL is returned if all entries were |
95 // evicted and the empty table is of insufficent size for the representation. | 118 // evicted and the empty table is of insufficent size for the representation. |
96 const HpackEntry* TryAddEntry(base::StringPiece name, | 119 const HpackEntry* TryAddEntry(base::StringPiece name, |
97 base::StringPiece value); | 120 base::StringPiece value); |
98 | 121 |
99 void DebugLogTableState() const; | 122 void DebugLogTableState() const; |
100 | 123 |
| 124 void set_debug_visitor(std::unique_ptr<DebugVisitorInterface> visitor) { |
| 125 debug_visitor_ = std::move(visitor); |
| 126 } |
| 127 |
101 private: | 128 private: |
102 // Returns number of evictions required to enter |name| & |value|. | 129 // Returns number of evictions required to enter |name| & |value|. |
103 size_t EvictionCountForEntry(base::StringPiece name, | 130 size_t EvictionCountForEntry(base::StringPiece name, |
104 base::StringPiece value) const; | 131 base::StringPiece value) const; |
105 | 132 |
106 // Returns number of evictions required to reclaim |reclaim_size| table size. | 133 // Returns number of evictions required to reclaim |reclaim_size| table size. |
107 size_t EvictionCountToReclaim(size_t reclaim_size) const; | 134 size_t EvictionCountToReclaim(size_t reclaim_size) const; |
108 | 135 |
109 // Evicts |count| oldest entries from the table. | 136 // Evicts |count| oldest entries from the table. |
110 void Evict(size_t count); | 137 void Evict(size_t count); |
(...skipping 21 matching lines...) Expand all Loading... |
132 | 159 |
133 // Estimated current and maximum byte size of the table. | 160 // Estimated current and maximum byte size of the table. |
134 // |max_size_| <= |settings_size_bound_| | 161 // |max_size_| <= |settings_size_bound_| |
135 size_t size_; | 162 size_t size_; |
136 size_t max_size_; | 163 size_t max_size_; |
137 | 164 |
138 // Total number of table insertions which have occurred. Referenced by | 165 // Total number of table insertions which have occurred. Referenced by |
139 // IndexOf() for determination of an HpackEntry's table index. | 166 // IndexOf() for determination of an HpackEntry's table index. |
140 size_t total_insertions_; | 167 size_t total_insertions_; |
141 | 168 |
| 169 std::unique_ptr<DebugVisitorInterface> debug_visitor_; |
| 170 |
142 DISALLOW_COPY_AND_ASSIGN(HpackHeaderTable); | 171 DISALLOW_COPY_AND_ASSIGN(HpackHeaderTable); |
143 }; | 172 }; |
144 | 173 |
145 } // namespace net | 174 } // namespace net |
146 | 175 |
147 #endif // NET_SPDY_HPACK_HEADER_TABLE_H_ | 176 #endif // NET_SPDY_HPACK_HEADER_TABLE_H_ |
OLD | NEW |