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

Side by Side Diff: net/websockets/websocket_deflate_stream.h

Issue 39193005: Introduce WebSocketDeflatePredictor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_WEBSOCKETS_WEBSOCKET_DEFLATE_STREAM_H_ 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_DEFLATE_STREAM_H_
6 #define NET_WEBSOCKETS_WEBSOCKET_DEFLATE_STREAM_H_ 6 #define NET_WEBSOCKETS_WEBSOCKET_DEFLATE_STREAM_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "net/base/completion_callback.h" 13 #include "net/base/completion_callback.h"
14 #include "net/base/net_export.h" 14 #include "net/base/net_export.h"
15 #include "net/websockets/websocket_deflate_predictor.h"
15 #include "net/websockets/websocket_deflater.h" 16 #include "net/websockets/websocket_deflater.h"
16 #include "net/websockets/websocket_frame.h" 17 #include "net/websockets/websocket_frame.h"
17 #include "net/websockets/websocket_inflater.h" 18 #include "net/websockets/websocket_inflater.h"
18 #include "net/websockets/websocket_stream.h" 19 #include "net/websockets/websocket_stream.h"
19 20
20 class GURL; 21 class GURL;
21 22
22 namespace net { 23 namespace net {
23 24
24 // WebSocketDeflateStream is a WebSocketStream subclass. 25 // WebSocketDeflateStream is a WebSocketStream subclass.
25 // WebSocketDeflateStream is for permessage-deflate WebSocket extension[1]. 26 // WebSocketDeflateStream is for permessage-deflate WebSocket extension[1].
26 // 27 //
27 // [1]: http://tools.ietf.org/html/draft-ietf-hybi-permessage-compression-12 28 // [1]: http://tools.ietf.org/html/draft-ietf-hybi-permessage-compression-12
28 class NET_EXPORT_PRIVATE WebSocketDeflateStream : public WebSocketStream { 29 class NET_EXPORT_PRIVATE WebSocketDeflateStream : public WebSocketStream {
29 public: 30 public:
30 WebSocketDeflateStream(scoped_ptr<WebSocketStream> stream, 31 WebSocketDeflateStream(scoped_ptr<WebSocketStream> stream,
31 WebSocketDeflater::ContextTakeOverMode mode); 32 WebSocketDeflater::ContextTakeOverMode mode,
33 scoped_ptr<WebSocketDeflatePredictor> predictor);
32 virtual ~WebSocketDeflateStream(); 34 virtual ~WebSocketDeflateStream();
33 35
34 // WebSocketStream functions. 36 // WebSocketStream functions.
35 virtual int ReadFrames(ScopedVector<WebSocketFrame>* frames, 37 virtual int ReadFrames(ScopedVector<WebSocketFrame>* frames,
36 const CompletionCallback& callback) OVERRIDE; 38 const CompletionCallback& callback) OVERRIDE;
37 virtual int WriteFrames(ScopedVector<WebSocketFrame>* frames, 39 virtual int WriteFrames(ScopedVector<WebSocketFrame>* frames,
38 const CompletionCallback& callback) OVERRIDE; 40 const CompletionCallback& callback) OVERRIDE;
39 virtual void Close() OVERRIDE; 41 virtual void Close() OVERRIDE;
40 virtual std::string GetSubProtocol() const OVERRIDE; 42 virtual std::string GetSubProtocol() const OVERRIDE;
41 virtual std::string GetExtensions() const OVERRIDE; 43 virtual std::string GetExtensions() const OVERRIDE;
42 44
43 private: 45 private:
44 enum ReadingState { 46 enum ReadingState {
45 READING_COMPRESSED_MESSAGE, 47 READING_COMPRESSED_MESSAGE,
46 READING_UNCOMPRESSED_MESSAGE, 48 READING_UNCOMPRESSED_MESSAGE,
47 NOT_READING, 49 NOT_READING,
48 }; 50 };
49 51
50 enum WritingState { 52 enum WritingState {
51 WRITING_COMPRESSED_MESSAGE, 53 WRITING_COMPRESSED_MESSAGE,
52 WRITING_UNCOMPRESSED_MESSAGE, 54 WRITING_UNCOMPRESSED_MESSAGE,
55 WRITING_POSSIBLY_COMPRESSED_MESSAGE,
53 NOT_WRITING, 56 NOT_WRITING,
54 }; 57 };
55 58
56 void OnReadComplete(ScopedVector<WebSocketFrame>* frames, 59 void OnReadComplete(ScopedVector<WebSocketFrame>* frames,
57 const CompletionCallback& callback, 60 const CompletionCallback& callback,
58 int result); 61 int result);
59 62
60 // This function deflates |frames| and stores the result to |frames| itself. 63 // This function deflates |frames| and stores the result to |frames| itself.
61 int Deflate(ScopedVector<WebSocketFrame>* frames); 64 int Deflate(ScopedVector<WebSocketFrame>* frames);
65 void OnMessageStart(const ScopedVector<WebSocketFrame>& frames, size_t index);
66 int AppendCompressedFrame(const WebSocketFrameHeader& header,
67 ScopedVector<WebSocketFrame>* frames_to_write);
68 int AppendPossiblyCompressedMessage(
69 ScopedVector<WebSocketFrame>* frames,
70 ScopedVector<WebSocketFrame>* frames_to_write);
62 71
63 // This function inflates |frames| and stores the result to |frames| itself. 72 // This function inflates |frames| and stores the result to |frames| itself.
64 int Inflate(ScopedVector<WebSocketFrame>* frames); 73 int Inflate(ScopedVector<WebSocketFrame>* frames);
65 74
66 int InflateAndReadIfNecessary(ScopedVector<WebSocketFrame>* frames, 75 int InflateAndReadIfNecessary(ScopedVector<WebSocketFrame>* frames,
67 const CompletionCallback& callback); 76 const CompletionCallback& callback);
68 77
69 const scoped_ptr<WebSocketStream> stream_; 78 const scoped_ptr<WebSocketStream> stream_;
70 WebSocketDeflater deflater_; 79 WebSocketDeflater deflater_;
71 WebSocketInflater inflater_; 80 WebSocketInflater inflater_;
72 ReadingState reading_state_; 81 ReadingState reading_state_;
73 WritingState writing_state_; 82 WritingState writing_state_;
74 WebSocketFrameHeader::OpCode current_reading_opcode_; 83 WebSocketFrameHeader::OpCode current_reading_opcode_;
75 WebSocketFrameHeader::OpCode current_writing_opcode_; 84 WebSocketFrameHeader::OpCode current_writing_opcode_;
85 scoped_ptr<WebSocketDeflatePredictor> predictor_;
76 86
77 DISALLOW_COPY_AND_ASSIGN(WebSocketDeflateStream); 87 DISALLOW_COPY_AND_ASSIGN(WebSocketDeflateStream);
78 }; 88 };
79 89
80 } // namespace net 90 } // namespace net
81 91
82 #endif // NET_WEBSOCKETS_WEBSOCKET_DEFLATE_STREAM_H_ 92 #endif // NET_WEBSOCKETS_WEBSOCKET_DEFLATE_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698