OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_SPDY_HPACK_ENCODING_CONTEXT_H_ | |
6 #define NET_SPDY_HPACK_ENCODING_CONTEXT_H_ | |
7 | |
8 #include <cstddef> | |
9 #include <deque> | |
10 #include <vector> | |
11 | |
12 #include "base/basictypes.h" | |
13 #include "base/macros.h" | |
14 #include "base/strings/string_piece.h" | |
15 #include "net/base/net_export.h" | |
16 #include "net/spdy/hpack_header_table.h" | |
17 | |
18 // All section references below are to | |
19 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-06 | |
20 | |
21 namespace net { | |
22 | |
23 namespace test { | |
24 class HpackEncodingContextPeer; | |
25 } // namespace test | |
26 | |
27 // An encoding context is simply a header table and its associated | |
28 // reference set and a static table. | |
29 class NET_EXPORT_PRIVATE HpackEncodingContext { | |
30 public: | |
31 friend class test::HpackEncodingContextPeer; | |
32 | |
33 // The constant returned by GetTouchesAt() if the indexed entry | |
34 // hasn't been touched (which is distinct from having a touch count | |
35 // of 0). | |
36 // | |
37 // TODO(akalin): The distinction between untouched and having a | |
38 // touch count of 0 is confusing. Think of a better way to represent | |
39 // this state. | |
40 static const uint32 kUntouched; | |
41 | |
42 HpackEncodingContext(); | |
43 | |
44 ~HpackEncodingContext(); | |
45 | |
46 uint32 GetMutableEntryCount() const; | |
47 | |
48 uint32 GetEntryCount() const; | |
49 | |
50 // For all read accessors below, index must be >= 1 and <= | |
51 // GetEntryCount(). For all mutating accessors below, index must be | |
52 // >= 1 and <= GetMutableEntryCount(). | |
53 | |
54 // The StringPieces returned by Get{Name,Value}At() live as long as | |
55 // the next call to SetMaxSize() or the Process*() functions. | |
56 | |
57 base::StringPiece GetNameAt(uint32 index) const; | |
58 | |
59 base::StringPiece GetValueAt(uint32 index) const; | |
60 | |
61 bool IsReferencedAt(uint32 index) const; | |
62 | |
63 uint32 GetTouchCountAt(uint32 index) const; | |
64 | |
65 void SetReferencedAt(uint32 index, bool referenced); | |
66 | |
67 // Adds the given number of touches to the entry at the given | |
68 // index. It is guaranteed that GetTouchCountAt(index) will not | |
69 // equal kUntouched after this function is called (even if | |
70 // touch_count == 0). | |
71 void AddTouchesAt(uint32 index, uint32 touch_count); | |
72 | |
73 // Sets the touch count of the entry at the given index to | |
74 // kUntouched. | |
75 void ClearTouchesAt(uint32 index); | |
76 | |
77 // Called upon acknowledgement of SETTINGS_HEADER_TABLE_SIZE. | |
78 // If |max_size| is smaller than the current header table size, the change | |
79 // is treated as an implicit maximum-size context update. | |
80 void ApplyHeaderTableSizeSetting(uint32 max_size); | |
81 | |
82 // The Process*() functions below return true on success and false | |
83 // if an error was encountered. | |
84 | |
85 // Section 4.4. Sets the maximum size of the header table, evicting entries | |
86 // as needed. Fails if |max_size| is larger than SETTINGS_HEADER_TABLE_SIZE. | |
87 bool ProcessContextUpdateNewMaximumSize(uint32 max_size); | |
88 | |
89 // Section 4.4. Drops all headers from the reference set. | |
90 bool ProcessContextUpdateEmptyReferenceSet(); | |
91 | |
92 // Tries to update the encoding context given an indexed header | |
93 // opcode for the given index as described in section 3.2.1. | |
94 // new_index is filled in with the index of a mutable entry, | |
95 // or 0 if one was not created. removed_referenced_indices is filled | |
96 // in with the indices of all entries removed from the reference set. | |
97 bool ProcessIndexedHeader(uint32 nonzero_index, | |
98 uint32* new_index, | |
99 std::vector<uint32>* removed_referenced_indices); | |
100 | |
101 // Tries to update the encoding context given a literal header with | |
102 // incremental indexing opcode for the given name and value as | |
103 // described in 3.2.1. index is filled in with the index of the new | |
104 // entry if the header was successfully indexed, or 0 if | |
105 // not. removed_referenced_indices is filled in with the indices of | |
106 // all entries removed from the reference set. | |
107 bool ProcessLiteralHeaderWithIncrementalIndexing( | |
108 base::StringPiece name, | |
109 base::StringPiece value, | |
110 uint32* index, | |
111 std::vector<uint32>* removed_referenced_indices); | |
112 | |
113 private: | |
114 // Last acknowledged value for SETTINGS_HEADER_TABLE_SIZE. | |
115 uint32 settings_header_table_size_; | |
116 | |
117 HpackHeaderTable header_table_; | |
118 | |
119 DISALLOW_COPY_AND_ASSIGN(HpackEncodingContext); | |
120 }; | |
121 | |
122 } // namespace net | |
123 | |
124 #endif // NET_SPDY_HPACK_ENCODING_CONTEXT_H_ | |
OLD | NEW |