| 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-07 | 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.1.2) and | 26 // A data structure for both the header table (described in 3.2) and |
| 27 // the reference set (3.1.3). | 27 // the reference set (3.3). |
| 28 class NET_EXPORT_PRIVATE HpackHeaderTable { | 28 class NET_EXPORT_PRIVATE HpackHeaderTable { |
| 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; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 52 typedef std::set<HpackEntry*, EntryComparator> OrderedEntrySet; | 52 typedef std::set<HpackEntry*, EntryComparator> OrderedEntrySet; |
| 53 | 53 |
| 54 HpackHeaderTable(); | 54 HpackHeaderTable(); |
| 55 | 55 |
| 56 ~HpackHeaderTable(); | 56 ~HpackHeaderTable(); |
| 57 | 57 |
| 58 // Last-aknowledged value of SETTINGS_HEADER_TABLE_SIZE. | 58 // Last-aknowledged value of SETTINGS_HEADER_TABLE_SIZE. |
| 59 size_t settings_size_bound() { return settings_size_bound_; } | 59 size_t settings_size_bound() { return settings_size_bound_; } |
| 60 | 60 |
| 61 // 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 |
| 62 // 3.3.1. Notably, this is /not/ the number of entries in the table. | 62 // 5.1. Notably, this is /not/ the number of entries in the table. |
| 63 size_t size() const { return size_; } | 63 size_t size() const { return size_; } |
| 64 size_t max_size() const { return max_size_; } | 64 size_t max_size() const { return max_size_; } |
| 65 | 65 |
| 66 const OrderedEntrySet& reference_set() { | 66 const OrderedEntrySet& reference_set() { |
| 67 return reference_set_; | 67 return reference_set_; |
| 68 } | 68 } |
| 69 | 69 |
| 70 // Returns the entry matching the index, or NULL. | 70 // Returns the entry matching the index, or NULL. |
| 71 HpackEntry* GetByIndex(size_t index); | 71 HpackEntry* GetByIndex(size_t index); |
| 72 | 72 |
| 73 // Returns the lowest-value entry having |name|, or NULL. | 73 // Returns the lowest-value entry having |name|, or NULL. |
| 74 HpackEntry* GetByName(base::StringPiece name); | 74 HpackEntry* GetByName(base::StringPiece name); |
| 75 | 75 |
| 76 // Returns the lowest-index matching entry, or NULL. | 76 // Returns the lowest-index matching entry, or NULL. |
| 77 HpackEntry* GetByNameAndValue(base::StringPiece name, | 77 HpackEntry* GetByNameAndValue(base::StringPiece name, |
| 78 base::StringPiece value); | 78 base::StringPiece value); |
| 79 | 79 |
| 80 // Returns the index of an entry within this header table. | 80 // Returns the index of an entry within this header table. |
| 81 size_t IndexOf(const HpackEntry* entry) const; | 81 size_t IndexOf(const HpackEntry* entry) const; |
| 82 | 82 |
| 83 // Sets the maximum size of the header table, evicting entries if | 83 // Sets the maximum size of the header table, evicting entries if |
| 84 // necessary as described in 3.3.2. | 84 // necessary as described in 5.2. |
| 85 void SetMaxSize(size_t max_size); | 85 void SetMaxSize(size_t max_size); |
| 86 | 86 |
| 87 // 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 |
| 88 // SetMaxSize() as needed to preserve max_size() <= settings_size_bound(). | 88 // SetMaxSize() as needed to preserve max_size() <= settings_size_bound(). |
| 89 void SetSettingsHeaderTableSize(size_t settings_size); | 89 void SetSettingsHeaderTableSize(size_t settings_size); |
| 90 | 90 |
| 91 // 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 |
| 92 // 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 |
| 93 // actually occurs. The set is returned via range [begin_out, end_out). | 93 // actually occurs. The set is returned via range [begin_out, end_out). |
| 94 void EvictionSet(base::StringPiece name, base::StringPiece value, | 94 void EvictionSet(base::StringPiece name, base::StringPiece value, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 // Total number of table insertions which have occurred. Referenced by | 142 // Total number of table insertions which have occurred. Referenced by |
| 143 // IndexOf() for determination of an HpackEntry's table index. | 143 // IndexOf() for determination of an HpackEntry's table index. |
| 144 size_t total_insertions_; | 144 size_t total_insertions_; |
| 145 | 145 |
| 146 DISALLOW_COPY_AND_ASSIGN(HpackHeaderTable); | 146 DISALLOW_COPY_AND_ASSIGN(HpackHeaderTable); |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 } // namespace net | 149 } // namespace net |
| 150 | 150 |
| 151 #endif // NET_SPDY_HPACK_HEADER_TABLE_H_ | 151 #endif // NET_SPDY_HPACK_HEADER_TABLE_H_ |
| OLD | NEW |