OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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-04 |
| 20 // . |
| 21 |
| 22 namespace net { |
| 23 |
| 24 // An encoding context is simply a header table and its associated |
| 25 // reference set and a static table. |
| 26 class NET_EXPORT_PRIVATE HpackEncodingContext { |
| 27 public: |
| 28 // The constant returned by GetTouchesAt() if the indexed entry |
| 29 // hasn't been touched (which is distinct from having a touch count |
| 30 // of 0). |
| 31 // |
| 32 // TODO(akalin): The distinction between untouched and having a |
| 33 // touch count of 0 is confusing. Think of a better way to represent |
| 34 // this state. |
| 35 static const uint32 kUntouched; |
| 36 |
| 37 HpackEncodingContext(); |
| 38 |
| 39 ~HpackEncodingContext(); |
| 40 |
| 41 uint32 GetEntryCount() const; |
| 42 |
| 43 // For all accessor below, index must be < GetEntryCount(). |
| 44 |
| 45 // The StringPieces returned by Get{Name,Value}At() live as long as |
| 46 // the next call to SetMaxSize() or the Process*() functions. |
| 47 |
| 48 base::StringPiece GetNameAt(uint32 index) const; |
| 49 |
| 50 base::StringPiece GetValueAt(uint32 index) const; |
| 51 |
| 52 bool IsReferencedAt(uint32 index) const; |
| 53 |
| 54 uint32 GetTouchCountAt(uint32 index) const; |
| 55 |
| 56 void SetReferencedAt(uint32 index, bool referenced); |
| 57 |
| 58 // Adds the given number of touches to the entry at the given |
| 59 // index. It is guaranteed that GetTouchCountAt(index) will not |
| 60 // equal kUntouched after this function is called (even if |
| 61 // touch_count == 0). |
| 62 void AddTouchesAt(uint32 index, uint32 touch_count); |
| 63 |
| 64 // Sets the touch count of the entry at the given index to |
| 65 // kUntouched. |
| 66 void ClearTouchesAt(uint32 index); |
| 67 |
| 68 // Sets the maximum size of the encoding text, evicting entries if |
| 69 // necessary. |
| 70 void SetMaxSize(uint32 max_size); |
| 71 |
| 72 // The Process*() functions below return true on success and false |
| 73 // if an error was encountered. |
| 74 |
| 75 // Tries to update the encoding context given an indexed header |
| 76 // opcode for the given index as described in 3.2.1. new_index is |
| 77 // filled in with the index of a mutable entry, or -1 if one was not |
| 78 // able to be created. removed_referenced_indices is filled in with |
| 79 // the indices of all entries removed from the reference set. |
| 80 bool ProcessIndexedHeader(uint32 index, |
| 81 int32* new_index, |
| 82 std::vector<uint32>* removed_referenced_indices); |
| 83 |
| 84 // Tries to update the encoding context given a literal header with |
| 85 // incremental indexing opcode for the given name and value as |
| 86 // described in 3.2.1. index is filled in with the index of the new |
| 87 // entry if the header was successfully indexed, or -1 if |
| 88 // not. removed_referenced_indices is filled in with the indices of |
| 89 // all entries removed from the reference set. |
| 90 bool ProcessLiteralHeaderWithIncrementalIndexing( |
| 91 base::StringPiece name, |
| 92 base::StringPiece value, |
| 93 int32* index, |
| 94 std::vector<uint32>* removed_referenced_indices); |
| 95 |
| 96 private: |
| 97 HpackHeaderTable header_table_; |
| 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(HpackEncodingContext); |
| 100 }; |
| 101 |
| 102 } // namespace net |
| 103 |
| 104 #endif // NET_SPDY_HPACK_ENCODING_CONTEXT_H_ |
OLD | NEW |