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

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

Issue 23604044: Replace WebSocketFrameChunk with WebSocketFrame (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixes to debug printing. Created 7 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_FRAME_H_ 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_FRAME_H_
6 #define NET_WEBSOCKETS_WEBSOCKET_FRAME_H_ 6 #define NET_WEBSOCKETS_WEBSOCKET_FRAME_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "net/base/net_export.h" 13 #include "net/base/net_export.h"
14 14
15 namespace net { 15 namespace net {
16 16
17 class IOBuffer;
17 class IOBufferWithSize; 18 class IOBufferWithSize;
18 19
19 // Represents a WebSocket frame header. 20 // Represents a WebSocket frame header.
20 // 21 //
21 // Members of this class correspond to each element in WebSocket frame header 22 // Members of this class correspond to each element in WebSocket frame header
22 // (see http://tools.ietf.org/html/rfc6455#section-5.2). 23 // (see http://tools.ietf.org/html/rfc6455#section-5.2).
23 struct NET_EXPORT WebSocketFrameHeader { 24 struct NET_EXPORT WebSocketFrameHeader {
24 typedef int OpCode; 25 typedef int OpCode;
25 26
26 // Originally these constants were static const int, but to make it possible 27 // Originally these constants were static const int, but to make it possible
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 explicit WebSocketFrameHeader(OpCode opCode) 63 explicit WebSocketFrameHeader(OpCode opCode)
63 : final(false), 64 : final(false),
64 reserved1(false), 65 reserved1(false),
65 reserved2(false), 66 reserved2(false),
66 reserved3(false), 67 reserved3(false),
67 opcode(opCode), 68 opcode(opCode),
68 masked(false), 69 masked(false),
69 payload_length(0) {} 70 payload_length(0) {}
70 71
71 // Create a clone of this object on the heap. 72 // Create a clone of this object on the heap.
72 scoped_ptr<WebSocketFrameHeader> Clone(); 73 scoped_ptr<WebSocketFrameHeader> Clone() const;
74
75 // Overwrite this object with the fields from |source|.
76 void CopyFrom(const WebSocketFrameHeader& source);
73 77
74 // Members below correspond to each item in WebSocket frame header. 78 // Members below correspond to each item in WebSocket frame header.
75 // See <http://tools.ietf.org/html/rfc6455#section-5.2> for details. 79 // See <http://tools.ietf.org/html/rfc6455#section-5.2> for details.
76 bool final; 80 bool final;
77 bool reserved1; 81 bool reserved1;
78 bool reserved2; 82 bool reserved2;
79 bool reserved3; 83 bool reserved3;
80 OpCode opcode; 84 OpCode opcode;
81 bool masked; 85 bool masked;
82 uint64 payload_length; 86 uint64 payload_length;
83 87
84 private: 88 private:
85 DISALLOW_COPY_AND_ASSIGN(WebSocketFrameHeader); 89 DISALLOW_COPY_AND_ASSIGN(WebSocketFrameHeader);
86 }; 90 };
87 91
88 // Contains payload data of part of a WebSocket frame. 92 // Contains an entire WebSocket frame including payload. This is used by APIs
93 // that are not concerned about retaining the original frame boundaries (because
94 // frames may need to be split in order for the data to fit in memory).
95 struct NET_EXPORT_PRIVATE WebSocketFrame {
96 // A frame must always have an opcode, so this parameter is compulsory.
97 WebSocketFrame(WebSocketFrameHeader::OpCode opcode);
yhirano 2013/09/13 10:03:17 explicit
Adam Rice 2013/09/13 14:09:53 Sorry. It looks like I forgot to run cpplint.
98 ~WebSocketFrame();
99
100 // |header| is always present.
101 WebSocketFrameHeader header;
102
103 // |data| is always unmasked even if the frame is masked. The size of |data|
104 // |is given by |header.payload_length|.
105 scoped_refptr<IOBuffer> data;
106 };
107
108 // Structure describing one chunk of a WebSocket frame.
89 // 109 //
90 // Payload of a WebSocket frame may be divided into multiple chunks. 110 // The payload of a WebSocket frame may be divided into multiple chunks.
91 // You need to look at |final_chunk| member variable to detect the end of a 111 // You need to look at |final_chunk| member variable to detect the end of a
92 // series of chunk objects of a WebSocket frame. 112 // series of chunk objects of a WebSocket frame.
93 // 113 //
94 // Frame dissection is necessary to handle WebSocket frame stream containing 114 // Frame dissection is necessary to handle frames that are too large to store in
95 // abritrarily large frames in the browser process. Because the server may send 115 // the browser memory without losing information about the frame boundaries. In
96 // a huge frame that doesn't fit in the memory, we cannot store the entire 116 // practice, most code does not need to worry about the original frame
97 // payload data in the memory. 117 // boundaries and can use the WebSocketFrame type declared above.
98 // 118 //
99 // Users of this struct should treat WebSocket frames as a data stream; it's 119 // Users of this struct should treat WebSocket frames as a data stream; it's
100 // important to keep the frame data flowing, especially in the browser process. 120 // important to keep the frame data flowing, especially in the browser process.
101 // Users should not let the data stuck somewhere in the pipeline. 121 // Users should not let the data stuck somewhere in the pipeline.
102 // 122 //
103 // This struct is used for reading WebSocket frame data (created by 123 // This struct is used for reading WebSocket frame data (created by
104 // WebSocketFrameParser). To construct WebSocket frames, use functions below. 124 // WebSocketFrameParser). To construct WebSocket frames, use functions below.
105 struct NET_EXPORT WebSocketFrameChunk { 125 struct NET_EXPORT WebSocketFrameChunk {
106 WebSocketFrameChunk(); 126 WebSocketFrameChunk();
107 ~WebSocketFrameChunk(); 127 ~WebSocketFrameChunk();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // used for unmasking a WebSocket frame. 186 // used for unmasking a WebSocket frame.
167 NET_EXPORT void MaskWebSocketFramePayload( 187 NET_EXPORT void MaskWebSocketFramePayload(
168 const WebSocketMaskingKey& masking_key, 188 const WebSocketMaskingKey& masking_key,
169 uint64 frame_offset, 189 uint64 frame_offset,
170 char* data, 190 char* data,
171 int data_size); 191 int data_size);
172 192
173 } // namespace net 193 } // namespace net
174 194
175 #endif // NET_WEBSOCKETS_WEBSOCKET_FRAME_H_ 195 #endif // NET_WEBSOCKETS_WEBSOCKET_FRAME_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698