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

Unified 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, 4 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 side-by-side diff with in-line comments
Download patch
Index: net/websockets/websocket_deflater.h
diff --git a/net/websockets/websocket_deflater.h b/net/websockets/websocket_deflater.h
new file mode 100644
index 0000000000000000000000000000000000000000..6c77d595ccf67ddb4c4fbe320455c32114cb99b4
--- /dev/null
+++ b/net/websockets/websocket_deflater.h
@@ -0,0 +1,51 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_WEBSOCKETS_WEBSOCKET_DEFLATER_H_
+#define NET_WEBSOCKETS_WEBSOCKET_DEFLATER_H_
+
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "third_party/zlib/zlib.h"
+
+namespace net {
+
+class IOBufferWithSize;
+
+class WebSocketDeflater {
+ public:
+ enum ContextTakeOverMode {
+ DO_NOT_TAKE_OVER_CONTEXT,
+ TAKE_OVER_CONTEXT,
+ };
+
+ // |window_bits| must be between 8 and 15 (both inclusive).
+ WebSocketDeflater(int window_bits, ContextTakeOverMode mode);
+ ~WebSocketDeflater();
+
+ // Adds bytes to |stream_|.
+ // Returns true if there is no error and false otherwise.
+ bool AddBytes(const char* data, size_t size);
+
+ // Flushes and returns deflated result.
+ // Returns null if there is an error.
+ scoped_refptr<IOBufferWithSize> Finish();
+
+ private:
+ void Reset();
+
+ scoped_ptr<z_stream> stream_;
+ ContextTakeOverMode mode_;
+ std::vector<char> buffer_;
+ bool are_bytes_added_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebSocketDeflater);
+};
+
+} // namespace net
+
+#endif // NET_WEBSOCKETS_WEBSOCKET_DEFLATER_H_

Powered by Google App Engine
This is Rietveld 408576698