OLD | NEW |
(Empty) | |
| 1 // Copyright 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_DEFLATE_PREDICTOR_H_ |
| 6 #define NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PREDICTOR_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_vector.h" |
| 10 #include "net/base/net_export.h" |
| 11 |
| 12 namespace net { |
| 13 |
| 14 struct WebSocketFrame; |
| 15 |
| 16 // WebSocketDeflatePredictor is an interface class used for judging whether |
| 17 // a WebSocketDeflateStream should compress a message or not. |
| 18 class NET_EXPORT_PRIVATE WebSocketDeflatePredictor { |
| 19 public: |
| 20 enum Result { |
| 21 // Deflate and send the message. |
| 22 DEFLATE, |
| 23 // Do not deflate and send the original message. |
| 24 DO_NOT_DEFLATE, |
| 25 // Try compressing the message and send the smaller one of the original |
| 26 // and the compressed message. |
| 27 // Returning this result implies that the deflater is running on |
| 28 // DoNotTakeOverContext mode and the entire message is visible. |
| 29 TRY_DEFLATE, |
| 30 }; |
| 31 |
| 32 virtual ~WebSocketDeflatePredictor() {} |
| 33 |
| 34 // Predicts and returns whether the deflater should deflate the message |
| 35 // which begins with |frames[frame_index]| or not. |
| 36 // |frames[(frame_index + 1):]| consists of future frames if any. |
| 37 // |frames[frame_index]| must be the first frame of a data message, |
| 38 // but future frames may contain control message frames. |
| 39 // |frames[frame_index]| cannot be recorded yet and all preceding |
| 40 // data frames have to be already recorded when this method is called. |
| 41 virtual Result Predict(const ScopedVector<WebSocketFrame>& frames, |
| 42 size_t frame_index) = 0; |
| 43 |
| 44 // Records frame data for future prediction. |
| 45 // Only data frames should be recorded. Do not pass control frames' data. |
| 46 // All input data frames for the stream must be recorded in order. |
| 47 virtual void RecordInputDataFrame(const WebSocketFrame* frame) = 0; |
| 48 |
| 49 // Records frame data for future prediction. |
| 50 // Only data frames should be recorded. Do not pass control frames' data. |
| 51 // All data frames written by the stream must be recorded in order |
| 52 // regardless of whether they are compressed or not. |
| 53 virtual void RecordWrittenDataFrame(const WebSocketFrame* frame) = 0; |
| 54 }; |
| 55 |
| 56 } // namespace net |
| 57 |
| 58 #endif // NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PREDICTOR_H_ |
OLD | NEW |