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

Unified Diff: net/websockets/websocket_deflate_predictor.h

Issue 39193005: Introduce WebSocketDeflatePredictor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 2 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_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..791b934c9ab7f2365f28f1f1e5c401557c8c57af
--- /dev/null
+++ b/net/websockets/websocket_deflate_predictor.h
@@ -0,0 +1,57 @@
+// 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 "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/scoped_vector.h"
+#include "net/base/net_export.h"
+
+namespace net {
+
+struct WebSocketFrame;
+
+// WebSocketDeflatePredictor is an interface class used for judging whether
+// a WebSocketDeflateStream should compress a message or not.
+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 the message
+ // which begins with |frames[frame_index]| or not.
+ // frames[(frame_index + 1):] consists of future frames.
+ // |frames[frame_index]| must be the first frame of a data message,
+ // but future frames may contain control message frames.
Adam Rice 2013/10/25 13:05:25 You might want to mention that if frame_index is t
yhirano 2013/10/28 01:42:46 I intended to use Python notation which will work
+ virtual Result Predict(const ScopedVector<WebSocketFrame>& frames,
+ size_t frame_index) = 0;
+
+ // Records frame data for future prediction.
+ // Only data frames should be recorded. Do not pass control frames' data.
+ // All input data frames must be recorded in order.
+ virtual void RecordProcessedDataFrame(const WebSocketFrame* frame) = 0;
+
+ // Records frame data for future prediction.
+ // Only data frames should be recorded. Do not pass control frames' data.
+ // All sent data frames must be recorded in order regardless of whether
+ // they are compressed or not.
+ virtual void RecordSentDataFrame(const WebSocketFrame* frame) = 0;
+};
+
+} // namespace net
+
+#endif // NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PREDICTOR_H_

Powered by Google App Engine
This is Rietveld 408576698