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 <deque> | |
9 #include <vector> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/memory/scoped_vector.h" | |
14 | |
15 namespace net { | |
16 | |
17 class WebSocketFrame; | |
18 | |
19 class NET_EXPORT_PRIVATE WebSocketDeflatePredictor { | |
20 public: | |
21 enum Result { | |
22 // Deflate and send the message. | |
23 DEFLATE, | |
24 // Do not deflate and send the original message. | |
25 DO_NOT_DEFLATE, | |
26 // Try compressing the message and send the smaller one of the original | |
27 // and the compressed message. | |
28 // Returning this result implies that the deflater is running on | |
29 // DoNotTakeOverContext mode and the entire message is visible. | |
30 TRY_DEFLATE, | |
31 }; | |
32 | |
33 virtual ~WebSocketDeflatePredictor() {} | |
34 | |
35 // Predicts and returns whether the deflater should deflate |target_frame| | |
36 // or not. |frames[next_frame_index:]| consists of future frames. | |
37 // |target_frame| must be a data frame, but future frames can contain control | |
38 // frames. | |
Adam Rice
2013/10/24 07:59:23
Maybe |target_frame| should also be passed as an i
| |
39 virtual Result predict(const WebSocketFrame* target_frame, | |
40 const ScopedVector<WebSocketFrame>& frames, | |
41 size_t next_frame_index) = 0; | |
42 | |
43 // Records processed frame data for future prediction. | |
44 // Only data frames should be recorded. Do not pass control frames' data. | |
45 virtual void RecordProcessedFrame(bool was_compressed, | |
46 size_t original_size, | |
47 size_t compressed_size, | |
48 bool fin) = 0; | |
49 }; | |
50 | |
51 class NET_EXPORT_PRIVATE WebSocketAlwaysDeflatePredictor | |
52 : public WeSocketDeflatePredictor { | |
53 public: | |
54 virtual ~WebSocketAlwaysDeflatePredictor() {} | |
55 | |
56 virtual Result predict(const WebSocketFrame* target_frame, | |
57 const ScopedVector<WebSocketFrame>& frames, | |
58 size_t next_frame_index) OVERRIDE { | |
59 return Deflate; | |
60 } | |
61 | |
62 virtual void RecordProcessedFrame(bool was_compressed, | |
63 size_t original_size, | |
64 size_t compressed_size, | |
65 bool fin) OVERRIDE {} | |
66 | |
67 private: | |
68 DISALLOW_COPY_AND_ASSIGN(WebSocketAlwaysDeflatePredictor); | |
69 }; | |
70 | |
71 class NET_EXPORT_PRIVATE WebSocketNeverDeflatePredictor | |
72 : public WeSocketDeflatePredictor { | |
73 public: | |
74 virtual ~WebSocketNeverDeflatePredictor() {} | |
75 | |
76 virtual Result predict(const WebSocketFrame* target_frame, | |
77 const ScopedVector<WebSocketFrame>& frames, | |
78 size_t next_frame_index) OVERRIDE { | |
79 return DoNotDeflate; | |
Adam Rice
2013/10/24 07:59:23
DO_NOT_DEFLATE ?
| |
80 } | |
81 | |
82 virtual void RecordProcessedFrame(bool was_compressed, | |
83 size_t original_size, | |
84 size_t compressed_size, | |
85 bool fin) OVERRIDE {} | |
86 | |
87 private: | |
88 DISALLOW_COPY_AND_ASSIGN(WebSocketNeverDeflatePredictor); | |
89 }; | |
90 | |
91 } // namespace net | |
92 | |
93 #endif // NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PREDICTOR_H_ | |
OLD | NEW |