Index: net/websockets/websocket_deflate_predictor.h |
diff --git a/net/websockets/websocket_deflate_predictor.h b/net/websockets/websocket_deflate_predictor.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ab345b6724e4f7a66ae25d044959f2d2685f91bf |
--- /dev/null |
+++ b/net/websockets/websocket_deflate_predictor.h |
@@ -0,0 +1,93 @@ |
+// Copyright 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_DEFLATE_PREDICTOR_H_ |
+#define NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PREDICTOR_H_ |
+ |
+#include <deque> |
+#include <vector> |
+ |
+#include "base/basictypes.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/scoped_vector.h" |
+ |
+namespace net { |
+ |
+class WebSocketFrame; |
+ |
+class NET_EXPORT_PRIVATE WebSocketDeflatePredictor { |
+ public: |
+ enum Result { |
+ // Deflate and send the message. |
+ DEFLATE, |
+ // Do not deflate and send the original message. |
+ DO_NOT_DEFLATE, |
+ // Try compressing the message and send the smaller one of the original |
+ // and the compressed message. |
+ // Returning this result implies that the deflater is running on |
+ // DoNotTakeOverContext mode and the entire message is visible. |
+ TRY_DEFLATE, |
+ }; |
+ |
+ virtual ~WebSocketDeflatePredictor() {} |
+ |
+ // Predicts and returns whether the deflater should deflate |target_frame| |
+ // or not. |frames[next_frame_index:]| consists of future frames. |
+ // |target_frame| must be a data frame, but future frames can contain control |
+ // frames. |
Adam Rice
2013/10/24 07:59:23
Maybe |target_frame| should also be passed as an i
|
+ virtual Result predict(const WebSocketFrame* target_frame, |
+ const ScopedVector<WebSocketFrame>& frames, |
+ size_t next_frame_index) = 0; |
+ |
+ // Records processed frame data for future prediction. |
+ // Only data frames should be recorded. Do not pass control frames' data. |
+ virtual void RecordProcessedFrame(bool was_compressed, |
+ size_t original_size, |
+ size_t compressed_size, |
+ bool fin) = 0; |
+}; |
+ |
+class NET_EXPORT_PRIVATE WebSocketAlwaysDeflatePredictor |
+ : public WeSocketDeflatePredictor { |
+ public: |
+ virtual ~WebSocketAlwaysDeflatePredictor() {} |
+ |
+ virtual Result predict(const WebSocketFrame* target_frame, |
+ const ScopedVector<WebSocketFrame>& frames, |
+ size_t next_frame_index) OVERRIDE { |
+ return Deflate; |
+ } |
+ |
+ virtual void RecordProcessedFrame(bool was_compressed, |
+ size_t original_size, |
+ size_t compressed_size, |
+ bool fin) OVERRIDE {} |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(WebSocketAlwaysDeflatePredictor); |
+}; |
+ |
+class NET_EXPORT_PRIVATE WebSocketNeverDeflatePredictor |
+ : public WeSocketDeflatePredictor { |
+ public: |
+ virtual ~WebSocketNeverDeflatePredictor() {} |
+ |
+ virtual Result predict(const WebSocketFrame* target_frame, |
+ const ScopedVector<WebSocketFrame>& frames, |
+ size_t next_frame_index) OVERRIDE { |
+ return DoNotDeflate; |
Adam Rice
2013/10/24 07:59:23
DO_NOT_DEFLATE ?
|
+ } |
+ |
+ virtual void RecordProcessedFrame(bool was_compressed, |
+ size_t original_size, |
+ size_t compressed_size, |
+ bool fin) OVERRIDE {} |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(WebSocketNeverDeflatePredictor); |
+}; |
+ |
+} // namespace net |
+ |
+#endif // NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PREDICTOR_H_ |