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

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

Issue 23604044: Replace WebSocketFrameChunk with WebSocketFrame (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Hasta la vista, baby 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 unified diff | Download patch
« no previous file with comments | « net/websockets/websocket_frame.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_STREAM_H_ 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_STREAM_H_
6 #define NET_WEBSOCKETS_WEBSOCKET_STREAM_H_ 6 #define NET_WEBSOCKETS_WEBSOCKET_STREAM_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback_forward.h" 12 #include "base/callback_forward.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h" 14 #include "base/memory/scoped_vector.h"
15 #include "net/base/completion_callback.h" 15 #include "net/base/completion_callback.h"
16 #include "net/base/net_export.h" 16 #include "net/base/net_export.h"
17 #include "net/websockets/websocket_stream_base.h" 17 #include "net/websockets/websocket_stream_base.h"
18 18
19 class GURL; 19 class GURL;
20 20
21 namespace net { 21 namespace net {
22 22
23 class BoundNetLog; 23 class BoundNetLog;
24 class HttpRequestHeaders; 24 class HttpRequestHeaders;
25 class HttpResponseInfo; 25 class HttpResponseInfo;
26 class URLRequestContext; 26 class URLRequestContext;
27 struct WebSocketFrameChunk; 27 struct WebSocketFrame;
28 28
29 // WebSocketStreamRequest is the caller's handle to the process of creation of a 29 // WebSocketStreamRequest is the caller's handle to the process of creation of a
30 // WebSocketStream. Deleting the object before the OnSuccess or OnFailure 30 // WebSocketStream. Deleting the object before the OnSuccess or OnFailure
31 // callbacks are called will cancel the request (and neither callback will be 31 // callbacks are called will cancel the request (and neither callback will be
32 // called). After OnSuccess or OnFailure have been called, this object may be 32 // called). After OnSuccess or OnFailure have been called, this object may be
33 // safely deleted without side-effects. 33 // safely deleted without side-effects.
34 class NET_EXPORT_PRIVATE WebSocketStreamRequest { 34 class NET_EXPORT_PRIVATE WebSocketStreamRequest {
35 public: 35 public:
36 virtual ~WebSocketStreamRequest(); 36 virtual ~WebSocketStreamRequest();
37 }; 37 };
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 const GURL& origin, 84 const GURL& origin,
85 URLRequestContext* url_request_context, 85 URLRequestContext* url_request_context,
86 const BoundNetLog& net_log, 86 const BoundNetLog& net_log,
87 scoped_ptr<ConnectDelegate> connect_delegate); 87 scoped_ptr<ConnectDelegate> connect_delegate);
88 88
89 // Derived classes must make sure Close() is called when the stream is not 89 // Derived classes must make sure Close() is called when the stream is not
90 // closed on destruction. 90 // closed on destruction.
91 virtual ~WebSocketStream(); 91 virtual ~WebSocketStream();
92 92
93 // Reads WebSocket frame data. This operation finishes when new frame data 93 // Reads WebSocket frame data. This operation finishes when new frame data
94 // becomes available. Each frame message might be chopped off in the middle 94 // becomes available.
95 // as specified in the description of the WebSocketFrameChunk struct. 95 //
96 // |frame_chunks| remains owned by the caller and must be valid until the 96 // |frames| remains owned by the caller and must be valid until the
97 // operation completes or Close() is called. |frame_chunks| must be empty on 97 // operation completes or Close() is called. |frames| must be empty on
98 // calling. 98 // calling.
99 // 99 //
100 // This function should not be called while the previous call of ReadFrames() 100 // This function should not be called while the previous call of ReadFrames()
101 // is still pending. 101 // is still pending.
102 // 102 //
103 // Returns net::OK or one of the net::ERR_* codes. 103 // Returns net::OK or one of the net::ERR_* codes.
104 // 104 //
105 // frame_chunks->size() >= 1 if the result is OK. 105 // frames->size() >= 1 if the result is OK.
106 // 106 //
107 // A frame with an incomplete header will never be inserted into 107 // Only frames with complete header information are inserted into |frames|. If
108 // |frame_chunks|. If the currently available bytes of a new frame do not form 108 // the currently available bytes of a new frame do not form a complete frame
109 // a complete frame header, then the implementation will buffer them until all 109 // header, then the implementation will buffer them until all the fields in
110 // the fields in the WebSocketFrameHeader object can be filled. If 110 // the WebSocketFrameHeader object can be filled. If ReadFrames() is freshly
111 // ReadFrames() is freshly called in this situation, it will return 111 // called in this situation, it will return ERR_IO_PENDING exactly as if no
112 // ERR_IO_PENDING exactly as if no data was available. 112 // data was available.
113 // 113 //
114 // Every WebSocketFrameChunk in the vector except the first and last is 114 // Original frame boundaries are not preserved. In particular, if only part of
115 // guaranteed to be a complete frame. The first chunk may be the final part 115 // a frame is available, then the frame will be split, and the available data
116 // of the previous frame. The last chunk may be the first part of a new 116 // will be returned immediately.
117 // frame. If there is only one chunk, then it may consist of data from the
118 // middle part of a frame.
119 // 117 //
120 // When the socket is closed on the remote side, this method will return 118 // When the socket is closed on the remote side, this method will return
121 // ERR_CONNECTION_CLOSED. It will not return OK with an empty vector. 119 // ERR_CONNECTION_CLOSED. It will not return OK with an empty vector.
122 // 120 //
123 // If the connection is closed in the middle of receiving an incomplete frame, 121 // If the connection is closed in the middle of receiving an incomplete frame,
124 // ReadFrames may discard the incomplete frame. Since the renderer will 122 // ReadFrames may discard the incomplete frame. Since the renderer will
125 // discard any incomplete messages when the connection is closed, this makes 123 // discard any incomplete messages when the connection is closed, this makes
126 // no difference to the overall semantics. 124 // no difference to the overall semantics.
127 virtual int ReadFrames(ScopedVector<WebSocketFrameChunk>* frame_chunks, 125 virtual int ReadFrames(ScopedVector<WebSocketFrame>* frames,
128 const CompletionCallback& callback) = 0; 126 const CompletionCallback& callback) = 0;
129 127
130 // Writes WebSocket frame data. |frame_chunks| must only contain complete 128 // Writes WebSocket frame data.
131 // frames. Every chunk must have a non-NULL |header| and the |final_chunk|
132 // boolean set to true.
133 // 129 //
134 // The |frame_chunks| pointer must remain valid until the operation completes 130 // |frames| must be valid until the operation completes or Close() is called.
135 // or Close() is called. WriteFrames() will modify the contents of
136 // |frame_chunks| in the process of sending the message. After WriteFrames()
137 // has completed it is safe to clear and then re-use the vector, but other
138 // than that the caller should make no assumptions about its contents.
139 // 131 //
140 // This function should not be called while a previous call to WriteFrames() 132 // This function must not be called while a previous call of WriteFrames() is
141 // on the same stream is pending. 133 // still pending.
142 //
143 // Frame boundaries may not be preserved. Frames may be split or
144 // coalesced. Message boundaries are preserved (as required by WebSocket API
145 // semantics).
146 // 134 //
147 // This method will only return OK if all frames were written completely. 135 // This method will only return OK if all frames were written completely.
148 // Otherwise it will return an appropriate net error code. 136 // Otherwise it will return an appropriate net error code.
149 virtual int WriteFrames(ScopedVector<WebSocketFrameChunk>* frame_chunks, 137 virtual int WriteFrames(ScopedVector<WebSocketFrame>* frames,
150 const CompletionCallback& callback) = 0; 138 const CompletionCallback& callback) = 0;
151 139
152 // Closes the stream. All pending I/O operations (if any) are cancelled 140 // Closes the stream. All pending I/O operations (if any) are cancelled
153 // at this point, so |frame_chunks| can be freed. 141 // at this point, so |frames| can be freed.
154 virtual void Close() = 0; 142 virtual void Close() = 0;
155 143
156 // The subprotocol that was negotiated for the stream. If no protocol was 144 // The subprotocol that was negotiated for the stream. If no protocol was
157 // negotiated, then the empty string is returned. 145 // negotiated, then the empty string is returned.
158 virtual std::string GetSubProtocol() const = 0; 146 virtual std::string GetSubProtocol() const = 0;
159 147
160 // The extensions that were negotiated for the stream. Since WebSocketStreams 148 // The extensions that were negotiated for the stream. Since WebSocketStreams
161 // can be layered, this may be different from what this particular 149 // can be layered, this may be different from what this particular
162 // WebSocketStream implements. The primary purpose of this accessor is to make 150 // WebSocketStream implements. The primary purpose of this accessor is to make
163 // the data available to Javascript. The format of the string is identical to 151 // the data available to Javascript. The format of the string is identical to
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 protected: 193 protected:
206 WebSocketStream(); 194 WebSocketStream();
207 195
208 private: 196 private:
209 DISALLOW_COPY_AND_ASSIGN(WebSocketStream); 197 DISALLOW_COPY_AND_ASSIGN(WebSocketStream);
210 }; 198 };
211 199
212 } // namespace net 200 } // namespace net
213 201
214 #endif // NET_WEBSOCKETS_WEBSOCKET_STREAM_H_ 202 #endif // NET_WEBSOCKETS_WEBSOCKET_STREAM_H_
OLDNEW
« no previous file with comments | « net/websockets/websocket_frame.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698