Fix infinite recursion on hiding panel when created during fullscreen mode.
[chromium-blink-merge.git] / net / spdy / hpack_output_stream.h
bloba88e5223702ecccd9477632060dc6a45349bffbb
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.
5 #ifndef NET_SPDY_HPACK_OUTPUT_STREAM_H_
6 #define NET_SPDY_HPACK_OUTPUT_STREAM_H_
8 #include <map>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/macros.h"
13 #include "base/strings/string_piece.h"
14 #include "net/base/net_export.h"
15 #include "net/spdy/hpack_constants.h" // For HpackPrefix.
16 #include "net/spdy/hpack_encoding_context.h"
18 // All section references below are to
19 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-06
21 namespace net {
23 // An HpackOutputStream handles all the low-level details of encoding
24 // header fields.
25 class NET_EXPORT_PRIVATE HpackOutputStream {
26 public:
27 // |max_string_literal_size| is the largest that any one string
28 // |literal (header name or header value) can be.
29 explicit HpackOutputStream(uint32 max_string_literal_size);
30 ~HpackOutputStream();
32 // Corresponds to 4.2.
33 void AppendIndexedHeader(uint32 index_or_zero);
35 // Corresponds to 4.3.1 (second form). Returns whether or not the
36 // append was successful; if the append was unsuccessful, no other
37 // member function may be called.
38 bool AppendLiteralHeaderNoIndexingWithName(base::StringPiece name,
39 base::StringPiece value);
41 // Moves the internal buffer to the given string and clears all
42 // internal state.
43 void TakeString(std::string* output);
45 // Appends the lower |bit_size| bits of |bits| to the internal buffer.
47 // |bit_size| must be > 0 and <= 8. |bits| must not have any bits
48 // set other than the lower |bit_size| bits.
49 void AppendBits(uint8 bits, size_t bit_size);
51 // Accessors for testing.
53 void AppendBitsForTest(uint8 bits, size_t size) {
54 AppendBits(bits, size);
57 void AppendUint32ForTest(uint32 I) {
58 AppendUint32(I);
61 bool AppendStringLiteralForTest(base::StringPiece str) {
62 return AppendStringLiteral(str);
65 private:
66 // Simply forwards to AppendBits(prefix.bits, prefix.bit-size).
67 void AppendPrefix(HpackPrefix prefix);
69 // Appends the given integer using the representation described in
70 // 4.1.1. If the internal buffer ends on a byte boundary, the prefix
71 // length N is taken to be 8; otherwise, it is taken to be the
72 // number of bits to the next byte boundary.
74 // It is guaranteed that the internal buffer will end on a byte
75 // boundary after this function is called.
76 void AppendUint32(uint32 I);
78 // Appends the given string using the representation described in
79 // 4.1.2. The internal buffer must end on a byte boundary, and it is
80 // guaranteed that the internal buffer will end on a byte boundary
81 // after this function is called. Returns whether or not the append
82 // was successful; if the append was unsuccessful, no other member
83 // function may be called.
84 bool AppendStringLiteral(base::StringPiece str);
86 const uint32 max_string_literal_size_;
88 // The internal bit buffer.
89 std::string buffer_;
91 // If 0, the buffer ends on a byte boundary. If non-zero, the buffer
92 // ends on the most significant nth bit. Guaranteed to be < 8.
93 size_t bit_offset_;
95 DISALLOW_COPY_AND_ASSIGN(HpackOutputStream);
98 } // namespace net
100 #endif // NET_SPDY_HPACK_OUTPUT_STREAM_H_