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 <set> | 10 #include <set> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "net/base/net_export.h" | 14 #include "net/base/net_export.h" |
15 #include "net/spdy/hpack_entry.h" | 15 #include "net/spdy/hpack_entry.h" |
16 | 16 |
17 // All section references below are to | 17 // All section references below are to |
18 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08 | 18 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-08 |
19 | 19 |
20 namespace net { | 20 namespace net { |
21 | 21 |
22 namespace test { | 22 namespace test { |
23 class HpackHeaderTablePeer; | 23 class HpackHeaderTablePeer; |
24 } // namespace test | 24 } // namespace test |
25 | 25 |
26 // A data structure for both the header table (described in 3.2) and | 26 // A data structure for the static table (3.3.1) and the header table (3.3.2). |
27 // the reference set (3.3). | |
28 class NET_EXPORT_PRIVATE HpackHeaderTable { | 27 class NET_EXPORT_PRIVATE HpackHeaderTable { |
29 public: | 28 public: |
30 friend class test::HpackHeaderTablePeer; | 29 friend class test::HpackHeaderTablePeer; |
31 | 30 |
32 // HpackHeaderTable takes advantage of the deque property that references | 31 // HpackHeaderTable takes advantage of the deque property that references |
33 // remain valid, so long as insertions & deletions are at the head & tail. | 32 // remain valid, so long as insertions & deletions are at the head & tail. |
34 // If this changes (eg we start to drop entries from the middle of the table), | 33 // If this changes (eg we start to drop entries from the middle of the table), |
35 // this needs to be a std::list, in which case |index_| can be trivially | 34 // this needs to be a std::list, in which case |index_| can be trivially |
36 // extended to map to list iterators. | 35 // extended to map to list iterators. |
37 typedef std::deque<HpackEntry> EntryTable; | 36 typedef std::deque<HpackEntry> EntryTable; |
(...skipping 18 matching lines...) Expand all Loading... |
56 ~HpackHeaderTable(); | 55 ~HpackHeaderTable(); |
57 | 56 |
58 // Last-aknowledged value of SETTINGS_HEADER_TABLE_SIZE. | 57 // Last-aknowledged value of SETTINGS_HEADER_TABLE_SIZE. |
59 size_t settings_size_bound() { return settings_size_bound_; } | 58 size_t settings_size_bound() { return settings_size_bound_; } |
60 | 59 |
61 // Current and maximum estimated byte size of the table, as described in | 60 // Current and maximum estimated byte size of the table, as described in |
62 // 5.1. Notably, this is /not/ the number of entries in the table. | 61 // 5.1. Notably, this is /not/ the number of entries in the table. |
63 size_t size() const { return size_; } | 62 size_t size() const { return size_; } |
64 size_t max_size() const { return max_size_; } | 63 size_t max_size() const { return max_size_; } |
65 | 64 |
66 const OrderedEntrySet& reference_set() { | |
67 return reference_set_; | |
68 } | |
69 | |
70 // Returns the entry matching the index, or NULL. | 65 // Returns the entry matching the index, or NULL. |
71 HpackEntry* GetByIndex(size_t index); | 66 HpackEntry* GetByIndex(size_t index); |
72 | 67 |
73 // Returns the lowest-value entry having |name|, or NULL. | 68 // Returns the lowest-value entry having |name|, or NULL. |
74 HpackEntry* GetByName(base::StringPiece name); | 69 HpackEntry* GetByName(base::StringPiece name); |
75 | 70 |
76 // Returns the lowest-index matching entry, or NULL. | 71 // Returns the lowest-index matching entry, or NULL. |
77 HpackEntry* GetByNameAndValue(base::StringPiece name, | 72 HpackEntry* GetByNameAndValue(base::StringPiece name, |
78 base::StringPiece value); | 73 base::StringPiece value); |
79 | 74 |
(...skipping 14 matching lines...) Expand all Loading... |
94 void EvictionSet(base::StringPiece name, base::StringPiece value, | 89 void EvictionSet(base::StringPiece name, base::StringPiece value, |
95 EntryTable::iterator* begin_out, | 90 EntryTable::iterator* begin_out, |
96 EntryTable::iterator* end_out); | 91 EntryTable::iterator* end_out); |
97 | 92 |
98 // Adds an entry for the representation, evicting entries as needed. |name| | 93 // Adds an entry for the representation, evicting entries as needed. |name| |
99 // and |value| must not be owned by an entry which could be evicted. The | 94 // and |value| must not be owned by an entry which could be evicted. The |
100 // added HpackEntry is returned, or NULL is returned if all entries were | 95 // added HpackEntry is returned, or NULL is returned if all entries were |
101 // evicted and the empty table is of insufficent size for the representation. | 96 // evicted and the empty table is of insufficent size for the representation. |
102 HpackEntry* TryAddEntry(base::StringPiece name, base::StringPiece value); | 97 HpackEntry* TryAddEntry(base::StringPiece name, base::StringPiece value); |
103 | 98 |
104 // Toggles the presence of a dynamic entry in the reference set. Returns | |
105 // true if the entry was added, or false if removed. It is an error to | |
106 // Toggle(entry) if |entry->state()| != 0. | |
107 bool Toggle(HpackEntry* entry); | |
108 | |
109 // Removes all entries from the reference set. Sets the state of each removed | |
110 // entry to zero. | |
111 void ClearReferenceSet(); | |
112 | |
113 void DebugLogTableState() const; | 99 void DebugLogTableState() const; |
114 | 100 |
115 private: | 101 private: |
116 // Returns number of evictions required to enter |name| & |value|. | 102 // Returns number of evictions required to enter |name| & |value|. |
117 size_t EvictionCountForEntry(base::StringPiece name, | 103 size_t EvictionCountForEntry(base::StringPiece name, |
118 base::StringPiece value) const; | 104 base::StringPiece value) const; |
119 | 105 |
120 // Returns number of evictions required to reclaim |reclaim_size| table size. | 106 // Returns number of evictions required to reclaim |reclaim_size| table size. |
121 size_t EvictionCountToReclaim(size_t reclaim_size) const; | 107 size_t EvictionCountToReclaim(size_t reclaim_size) const; |
122 | 108 |
123 // Evicts |count| oldest entries from the table. | 109 // Evicts |count| oldest entries from the table. |
124 void Evict(size_t count); | 110 void Evict(size_t count); |
125 | 111 |
126 EntryTable dynamic_entries_; | 112 EntryTable dynamic_entries_; |
127 EntryTable static_entries_; | 113 EntryTable static_entries_; |
128 | 114 |
129 // Full table index, over |dynamic_entries_| and |static_entries_|. | 115 // Full table index, over |dynamic_entries_| and |static_entries_|. |
130 OrderedEntrySet index_; | 116 OrderedEntrySet index_; |
131 // The reference set is strictly a subset of |dynamic_entries_|. | |
132 OrderedEntrySet reference_set_; | |
133 | 117 |
134 // Last acknowledged value for SETTINGS_HEADER_TABLE_SIZE. | 118 // Last acknowledged value for SETTINGS_HEADER_TABLE_SIZE. |
135 size_t settings_size_bound_; | 119 size_t settings_size_bound_; |
136 | 120 |
137 // Estimated current and maximum byte size of the table. | 121 // Estimated current and maximum byte size of the table. |
138 // |max_size_| <= |settings_header_table_size_| | 122 // |max_size_| <= |settings_header_table_size_| |
139 size_t size_; | 123 size_t size_; |
140 size_t max_size_; | 124 size_t max_size_; |
141 | 125 |
142 // Total number of table insertions which have occurred. Referenced by | 126 // Total number of table insertions which have occurred. Referenced by |
143 // IndexOf() for determination of an HpackEntry's table index. | 127 // IndexOf() for determination of an HpackEntry's table index. |
144 size_t total_insertions_; | 128 size_t total_insertions_; |
145 | 129 |
146 DISALLOW_COPY_AND_ASSIGN(HpackHeaderTable); | 130 DISALLOW_COPY_AND_ASSIGN(HpackHeaderTable); |
147 }; | 131 }; |
148 | 132 |
149 } // namespace net | 133 } // namespace net |
150 | 134 |
151 #endif // NET_SPDY_HPACK_HEADER_TABLE_H_ | 135 #endif // NET_SPDY_HPACK_HEADER_TABLE_H_ |
OLD | NEW |