Chromium Code Reviews| 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..498aa825f3be8295b8c194d837d76baf09425427 |
| --- /dev/null |
| +++ b/net/websockets/websocket_deflater.h |
| @@ -0,0 +1,63 @@ |
| +// 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 <deque> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "net/base/net_export.h" |
| +#include "third_party/zlib/zlib.h" |
| + |
| +namespace net { |
| + |
| +class IOBufferWithSize; |
| + |
| +class NET_EXPORT_PRIVATE 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 the current processing data. |
| + // Returns true if there is no error and false otherwise. |
| + bool Finish(); |
| + |
| + // Returns the current deflated output. |
| + // If the current output is larger than |size| bytes, |
| + // returns the first |size| bytes of the current output. |
| + // The returned bytes will be dropped from the current output and never be |
| + // returned thereafter. |
| + scoped_refptr<IOBufferWithSize> GetOutput(size_t size); |
| + |
| + // Returns the size of the current deflated output. |
| + size_t CurrentOutputSize() const { return buffer_.size(); } |
| + |
| + private: |
| + void Reset(); |
| + int Deflate(size_t size, int flush); |
| + |
| + scoped_ptr<z_stream> stream_; |
| + ContextTakeOverMode mode_; |
| + std::deque<char> buffer_; |
| + 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.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(WebSocketDeflater); |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_WEBSOCKETS_WEBSOCKET_DEFLATER_H_ |