| 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> |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 public: | 29 public: |
| 30 friend class test::HpackHeaderTablePeer; | 30 friend class test::HpackHeaderTablePeer; |
| 31 | 31 |
| 32 // HpackHeaderTable takes advantage of the deque property that references | 32 // HpackHeaderTable takes advantage of the deque property that references |
| 33 // remain valid, so long as insertions & deletions are at the head & tail. | 33 // 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), | 34 // 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 | 35 // this needs to be a std::list, in which case |index_| can be trivially |
| 36 // extended to map to list iterators. | 36 // extended to map to list iterators. |
| 37 typedef std::deque<HpackEntry> EntryTable; | 37 typedef std::deque<HpackEntry> EntryTable; |
| 38 | 38 |
| 39 // Implements a total ordering of HpackEntry on name(), value(), then index |
| 40 // ascending. Note that index may change over the lifetime of an HpackEntry, |
| 41 // but the relative index order of two entries will not. This comparator is |
| 42 // composed with the 'lookup' HpackEntry constructor to allow for efficient |
| 43 // lower-bounding of matching entries. |
| 44 struct NET_EXPORT_PRIVATE EntryComparator { |
| 45 explicit EntryComparator(HpackHeaderTable* table) : table_(table) {} |
| 46 |
| 47 bool operator() (const HpackEntry* lhs, const HpackEntry* rhs) const; |
| 48 |
| 49 private: |
| 50 HpackHeaderTable* table_; |
| 51 }; |
| 52 typedef std::set<HpackEntry*, EntryComparator> OrderedEntrySet; |
| 53 |
| 39 HpackHeaderTable(); | 54 HpackHeaderTable(); |
| 40 | 55 |
| 41 ~HpackHeaderTable(); | 56 ~HpackHeaderTable(); |
| 42 | 57 |
| 43 // Last-aknowledged value of SETTINGS_HEADER_TABLE_SIZE. | 58 // Last-aknowledged value of SETTINGS_HEADER_TABLE_SIZE. |
| 44 size_t settings_size_bound() { return settings_size_bound_; } | 59 size_t settings_size_bound() { return settings_size_bound_; } |
| 45 | 60 |
| 46 // Current and maximum estimated byte size of the table, as described in | 61 // Current and maximum estimated byte size of the table, as described in |
| 47 // 3.3.1. Notably, this is /not/ the number of entries in the table. | 62 // 3.3.1. Notably, this is /not/ the number of entries in the table. |
| 48 size_t size() const { return size_; } | 63 size_t size() const { return size_; } |
| 49 size_t max_size() const { return max_size_; } | 64 size_t max_size() const { return max_size_; } |
| 50 | 65 |
| 51 const HpackEntry::OrderedSet& reference_set() { | 66 const OrderedEntrySet& reference_set() { |
| 52 return reference_set_; | 67 return reference_set_; |
| 53 } | 68 } |
| 54 | 69 |
| 55 // Returns the entry matching the index, or NULL. | 70 // Returns the entry matching the index, or NULL. |
| 56 HpackEntry* GetByIndex(size_t index); | 71 HpackEntry* GetByIndex(size_t index); |
| 57 | 72 |
| 58 // Returns the lowest-value entry having |name|, or NULL. | 73 // Returns the lowest-value entry having |name|, or NULL. |
| 59 HpackEntry* GetByName(base::StringPiece name); | 74 HpackEntry* GetByName(base::StringPiece name); |
| 60 | 75 |
| 61 // Returns the lowest-index matching entry, or NULL. | 76 // Returns the lowest-index matching entry, or NULL. |
| 62 HpackEntry* GetByNameAndValue(base::StringPiece name, | 77 HpackEntry* GetByNameAndValue(base::StringPiece name, |
| 63 base::StringPiece value); | 78 base::StringPiece value); |
| 64 | 79 |
| 80 // Returns the index of an entry within this header table. |
| 81 size_t IndexOf(const HpackEntry* entry) const; |
| 82 |
| 65 // Sets the maximum size of the header table, evicting entries if | 83 // Sets the maximum size of the header table, evicting entries if |
| 66 // necessary as described in 3.3.2. | 84 // necessary as described in 3.3.2. |
| 67 void SetMaxSize(size_t max_size); | 85 void SetMaxSize(size_t max_size); |
| 68 | 86 |
| 69 // Sets the SETTINGS_HEADER_TABLE_SIZE bound of the table. Will call | 87 // Sets the SETTINGS_HEADER_TABLE_SIZE bound of the table. Will call |
| 70 // SetMaxSize() as needed to preserve max_size() <= settings_size_bound(). | 88 // SetMaxSize() as needed to preserve max_size() <= settings_size_bound(). |
| 71 void SetSettingsHeaderTableSize(size_t settings_size); | 89 void SetSettingsHeaderTableSize(size_t settings_size); |
| 72 | 90 |
| 73 // Determine the set of entries which would be evicted by the insertion | 91 // Determine the set of entries which would be evicted by the insertion |
| 74 // of |name| & |value| into the table, as per section 3.3.3. No eviction | 92 // of |name| & |value| into the table, as per section 3.3.3. No eviction |
| (...skipping 27 matching lines...) Expand all Loading... |
| 102 // Returns number of evictions required to reclaim |reclaim_size| table size. | 120 // Returns number of evictions required to reclaim |reclaim_size| table size. |
| 103 size_t EvictionCountToReclaim(size_t reclaim_size) const; | 121 size_t EvictionCountToReclaim(size_t reclaim_size) const; |
| 104 | 122 |
| 105 // Evicts |count| oldest entries from the table. | 123 // Evicts |count| oldest entries from the table. |
| 106 void Evict(size_t count); | 124 void Evict(size_t count); |
| 107 | 125 |
| 108 EntryTable dynamic_entries_; | 126 EntryTable dynamic_entries_; |
| 109 EntryTable static_entries_; | 127 EntryTable static_entries_; |
| 110 | 128 |
| 111 // Full table index, over |dynamic_entries_| and |static_entries_|. | 129 // Full table index, over |dynamic_entries_| and |static_entries_|. |
| 112 HpackEntry::OrderedSet index_; | 130 OrderedEntrySet index_; |
| 113 // The reference set is strictly a subset of |dynamic_entries_|. | 131 // The reference set is strictly a subset of |dynamic_entries_|. |
| 114 HpackEntry::OrderedSet reference_set_; | 132 OrderedEntrySet reference_set_; |
| 115 | 133 |
| 116 // Last acknowledged value for SETTINGS_HEADER_TABLE_SIZE. | 134 // Last acknowledged value for SETTINGS_HEADER_TABLE_SIZE. |
| 117 size_t settings_size_bound_; | 135 size_t settings_size_bound_; |
| 118 | 136 |
| 119 // Estimated current and maximum byte size of the table. | 137 // Estimated current and maximum byte size of the table. |
| 120 // |max_size_| <= |settings_header_table_size_| | 138 // |max_size_| <= |settings_header_table_size_| |
| 121 size_t size_; | 139 size_t size_; |
| 122 size_t max_size_; | 140 size_t max_size_; |
| 123 | 141 |
| 124 // Total number of table insertions which have occurred. Referenced by | 142 // Total number of table insertions which have occurred. Referenced by |
| 125 // dynamic HpackEntry instances for determination of table index. | 143 // IndexOf() for determination of an HpackEntry's table index. |
| 126 size_t total_insertions_; | 144 size_t total_insertions_; |
| 127 | 145 |
| 128 // Current number of dynamic entries. Referenced by static HpackEntry | |
| 129 // instances for determination of table index. | |
| 130 size_t dynamic_entries_count_; | |
| 131 | |
| 132 DISALLOW_COPY_AND_ASSIGN(HpackHeaderTable); | 146 DISALLOW_COPY_AND_ASSIGN(HpackHeaderTable); |
| 133 }; | 147 }; |
| 134 | 148 |
| 135 } // namespace net | 149 } // namespace net |
| 136 | 150 |
| 137 #endif // NET_SPDY_HPACK_HEADER_TABLE_H_ | 151 #endif // NET_SPDY_HPACK_HEADER_TABLE_H_ |
| OLD | NEW |