OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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_WEBSOCKETS_WEBSOCKET_DEFLATER_H_ | |
6 #define NET_WEBSOCKETS_WEBSOCKET_DEFLATER_H_ | |
7 | |
8 #include <deque> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "net/base/net_export.h" | |
14 #include "third_party/zlib/zlib.h" | |
15 | |
16 namespace net { | |
17 | |
18 class IOBufferWithSize; | |
19 | |
20 class NET_EXPORT_PRIVATE WebSocketDeflater { | |
21 public: | |
22 enum ContextTakeOverMode { | |
23 DO_NOT_TAKE_OVER_CONTEXT, | |
24 TAKE_OVER_CONTEXT, | |
25 }; | |
26 | |
27 // |window_bits| must be between 8 and 15 (both inclusive). | |
28 WebSocketDeflater(int window_bits, ContextTakeOverMode mode); | |
29 ~WebSocketDeflater(); | |
30 | |
31 // Adds bytes to |stream_|. | |
32 // Returns true if there is no error and false otherwise. | |
33 bool AddBytes(const char* data, size_t size); | |
34 | |
35 // Flushes the current processing data. | |
36 // Returns true if there is no error and false otherwise. | |
37 bool Finish(); | |
38 | |
39 // Returns the current deflated output. | |
40 // If the current output is larger than |size| bytes, | |
41 // returns the first |size| bytes of the current output. | |
42 // The returned bytes will be dropped from the current output and never be | |
43 // returned thereafter. | |
44 scoped_refptr<IOBufferWithSize> GetOutput(size_t size); | |
45 | |
46 // Returns the size of the current deflated output. | |
47 size_t CurrentOutputSize() const { return buffer_.size(); } | |
48 | |
49 private: | |
50 void Reset(); | |
51 int Deflate(size_t size, int flush); | |
52 | |
53 scoped_ptr<z_stream> stream_; | |
54 ContextTakeOverMode mode_; | |
55 std::deque<char> buffer_; | |
56 bool are_bytes_added_; | |
tyoshino (SeeGerritForStatus)
2013/09/06 07:09:24
write a comment explaining this variable's role
yhirano
2013/09/06 10:07:26
Done.
| |
57 | |
58 DISALLOW_COPY_AND_ASSIGN(WebSocketDeflater); | |
59 }; | |
60 | |
61 } // namespace net | |
62 | |
63 #endif // NET_WEBSOCKETS_WEBSOCKET_DEFLATER_H_ | |
OLD | NEW |