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/hpack_entry.h" | 15 #include "net/spdy/hpack/hpack_entry.h" |
16 | 16 |
17 // All section references below are to http://tools.ietf.org/html/rfc7541. | 17 // All section references below are to http://tools.ietf.org/html/rfc7541. |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 | 20 |
21 using base::StringPiece; | |
22 | |
23 namespace test { | 21 namespace test { |
24 class HpackHeaderTablePeer; | 22 class HpackHeaderTablePeer; |
25 } // namespace test | 23 } // namespace test |
26 | 24 |
27 // A data structure for the static table (2.3.1) and the dynamic table (2.3.2). | 25 // A data structure for the static table (2.3.1) and the dynamic table (2.3.2). |
28 class NET_EXPORT_PRIVATE HpackHeaderTable { | 26 class NET_EXPORT_PRIVATE HpackHeaderTable { |
29 public: | 27 public: |
30 friend class test::HpackHeaderTablePeer; | 28 friend class test::HpackHeaderTablePeer; |
31 | 29 |
32 // HpackHeaderTable takes advantage of the deque property that references | 30 // HpackHeaderTable takes advantage of the deque property that references |
(...skipping 22 matching lines...) Expand all Loading... |
55 | 53 |
56 // Current and maximum estimated byte size of the table, as described in | 54 // Current and maximum estimated byte size of the table, as described in |
57 // 4.1. Notably, this is /not/ the number of entries in the table. | 55 // 4.1. Notably, this is /not/ the number of entries in the table. |
58 size_t size() const { return size_; } | 56 size_t size() const { return size_; } |
59 size_t max_size() const { return max_size_; } | 57 size_t max_size() const { return max_size_; } |
60 | 58 |
61 // Returns the entry matching the index, or NULL. | 59 // Returns the entry matching the index, or NULL. |
62 const HpackEntry* GetByIndex(size_t index); | 60 const HpackEntry* GetByIndex(size_t index); |
63 | 61 |
64 // Returns the lowest-value entry having |name|, or NULL. | 62 // Returns the lowest-value entry having |name|, or NULL. |
65 const HpackEntry* GetByName(StringPiece name); | 63 const HpackEntry* GetByName(base::StringPiece name); |
66 | 64 |
67 // Returns the lowest-index matching entry, or NULL. | 65 // Returns the lowest-index matching entry, or NULL. |
68 const HpackEntry* GetByNameAndValue(StringPiece name, StringPiece value); | 66 const HpackEntry* GetByNameAndValue(base::StringPiece name, |
| 67 base::StringPiece value); |
69 | 68 |
70 // Returns the index of an entry within this header table. | 69 // Returns the index of an entry within this header table. |
71 size_t IndexOf(const HpackEntry* entry) const; | 70 size_t IndexOf(const HpackEntry* entry) const; |
72 | 71 |
73 // Sets the maximum size of the header table, evicting entries if | 72 // Sets the maximum size of the header table, evicting entries if |
74 // necessary as described in 5.2. | 73 // necessary as described in 5.2. |
75 void SetMaxSize(size_t max_size); | 74 void SetMaxSize(size_t max_size); |
76 | 75 |
77 // Sets the SETTINGS_HEADER_TABLE_SIZE bound of the table. Will call | 76 // Sets the SETTINGS_HEADER_TABLE_SIZE bound of the table. Will call |
78 // SetMaxSize() as needed to preserve max_size() <= settings_size_bound(). | 77 // SetMaxSize() as needed to preserve max_size() <= settings_size_bound(). |
79 void SetSettingsHeaderTableSize(size_t settings_size); | 78 void SetSettingsHeaderTableSize(size_t settings_size); |
80 | 79 |
81 // Determine the set of entries which would be evicted by the insertion | 80 // Determine the set of entries which would be evicted by the insertion |
82 // of |name| & |value| into the table, as per section 4.4. No eviction | 81 // of |name| & |value| into the table, as per section 4.4. No eviction |
83 // actually occurs. The set is returned via range [begin_out, end_out). | 82 // actually occurs. The set is returned via range [begin_out, end_out). |
84 void EvictionSet(StringPiece name, | 83 void EvictionSet(base::StringPiece name, |
85 StringPiece value, | 84 base::StringPiece value, |
86 EntryTable::iterator* begin_out, | 85 EntryTable::iterator* begin_out, |
87 EntryTable::iterator* end_out); | 86 EntryTable::iterator* end_out); |
88 | 87 |
89 // Adds an entry for the representation, evicting entries as needed. |name| | 88 // Adds an entry for the representation, evicting entries as needed. |name| |
90 // and |value| must not be owned by an entry which could be evicted. The | 89 // and |value| must not be owned by an entry which could be evicted. The |
91 // added HpackEntry is returned, or NULL is returned if all entries were | 90 // added HpackEntry is returned, or NULL is returned if all entries were |
92 // evicted and the empty table is of insufficent size for the representation. | 91 // evicted and the empty table is of insufficent size for the representation. |
93 const HpackEntry* TryAddEntry(StringPiece name, StringPiece value); | 92 const HpackEntry* TryAddEntry(base::StringPiece name, |
| 93 base::StringPiece value); |
94 | 94 |
95 void DebugLogTableState() const; | 95 void DebugLogTableState() const; |
96 | 96 |
97 private: | 97 private: |
98 // Returns number of evictions required to enter |name| & |value|. | 98 // Returns number of evictions required to enter |name| & |value|. |
99 size_t EvictionCountForEntry(StringPiece name, StringPiece value) const; | 99 size_t EvictionCountForEntry(base::StringPiece name, |
| 100 base::StringPiece value) const; |
100 | 101 |
101 // Returns number of evictions required to reclaim |reclaim_size| table size. | 102 // Returns number of evictions required to reclaim |reclaim_size| table size. |
102 size_t EvictionCountToReclaim(size_t reclaim_size) const; | 103 size_t EvictionCountToReclaim(size_t reclaim_size) const; |
103 | 104 |
104 // Evicts |count| oldest entries from the table. | 105 // Evicts |count| oldest entries from the table. |
105 void Evict(size_t count); | 106 void Evict(size_t count); |
106 | 107 |
107 // |static_entries_| and |static_index_| are owned by HpackStaticTable | 108 // |static_entries_| and |static_index_| are owned by HpackStaticTable |
108 // singleton. | 109 // singleton. |
109 const EntryTable& static_entries_; | 110 const EntryTable& static_entries_; |
(...skipping 13 matching lines...) Expand all Loading... |
123 // Total number of table insertions which have occurred. Referenced by | 124 // Total number of table insertions which have occurred. Referenced by |
124 // IndexOf() for determination of an HpackEntry's table index. | 125 // IndexOf() for determination of an HpackEntry's table index. |
125 size_t total_insertions_; | 126 size_t total_insertions_; |
126 | 127 |
127 DISALLOW_COPY_AND_ASSIGN(HpackHeaderTable); | 128 DISALLOW_COPY_AND_ASSIGN(HpackHeaderTable); |
128 }; | 129 }; |
129 | 130 |
130 } // namespace net | 131 } // namespace net |
131 | 132 |
132 #endif // NET_SPDY_HPACK_HEADER_TABLE_H_ | 133 #endif // NET_SPDY_HPACK_HEADER_TABLE_H_ |
OLD | NEW |