Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: net/websockets/websocket_deflater.h

Issue 23623008: Implement WebSocketDeflater. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/websockets/README ('k') | net/websockets/websocket_deflater.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "net/base/net_export.h"
15 #include "third_party/zlib/zlib.h"
szym 2013/09/10 06:54:07 Replace this include with forward declaration: st
yhirano 2013/09/10 06:58:58 I once implemented so, but I fixed that in respons
yhirano 2013/09/10 07:48:40 Done.
16
17 namespace net {
18
19 class IOBufferWithSize;
20
21 class NET_EXPORT_PRIVATE WebSocketDeflater {
22 public:
23 enum ContextTakeOverMode {
24 DO_NOT_TAKE_OVER_CONTEXT,
25 TAKE_OVER_CONTEXT,
26 };
27
28 explicit WebSocketDeflater(ContextTakeOverMode mode);
29 ~WebSocketDeflater();
30
31 // Returns true if there is no error and false otherwise.
32 // This function must be called exactly once before calling any of
33 // following methods.
34 // |window_bits| must be between 8 and 15 (both inclusive).
35 bool Initialize(int window_bits);
36
37 // Adds bytes to |stream_|.
38 // Returns true if there is no error and false otherwise.
39 bool AddBytes(const char* data, size_t size);
40
41 // Flushes the current processing data.
42 // Returns true if there is no error and false otherwise.
43 bool Finish();
44
45 // Pushes "\x00\x00\xff\xff" to the end of the buffer.
46 void PushSyncMark();
47
48 // Returns the current deflated output.
49 // If the current output is larger than |size| bytes,
50 // returns the first |size| bytes of the current output.
51 // The returned bytes will be dropped from the current output and never be
52 // returned thereafter.
53 scoped_refptr<IOBufferWithSize> GetOutput(size_t size);
54
55 // Returns the size of the current deflated output.
56 size_t CurrentOutputSize() const { return buffer_.size(); }
57
58 private:
59 void ResetContext();
60 int Deflate(int flush);
61
62 scoped_ptr<z_stream> stream_;
63 ContextTakeOverMode mode_;
64 std::deque<char> buffer_;
65 std::vector<char> fixed_buffer_;
66 // true if bytes were added after last Finish().
67 bool are_bytes_added_;
68
69 DISALLOW_COPY_AND_ASSIGN(WebSocketDeflater);
70 };
71
72 } // namespace net
73
74 #endif // NET_WEBSOCKETS_WEBSOCKET_DEFLATER_H_
OLDNEW
« no previous file with comments | « net/websockets/README ('k') | net/websockets/websocket_deflater.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698