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

Side by Side Diff: net/quic/chromium/quic_chromium_client_stream.h

Issue 2908243002: Remove QuicChromiumClientStream::Delegate in favor of async methods. (Closed)
Patch Set: No expect_trailers_ Created 3 years, 6 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 // NOTE: This code is not shared between Google and Chrome. 5 // NOTE: This code is not shared between Google and Chrome.
6 6
7 #ifndef NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_STREAM_H_ 7 #ifndef NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_STREAM_H_
8 #define NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_STREAM_H_ 8 #define NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_STREAM_H_
9 9
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 14 matching lines...) Expand all
25 #include "net/quic/platform/api/quic_string_piece.h" 25 #include "net/quic/platform/api/quic_string_piece.h"
26 26
27 namespace net { 27 namespace net {
28 28
29 class QuicClientSessionBase; 29 class QuicClientSessionBase;
30 30
31 // A client-initiated ReliableQuicStream. Instances of this class 31 // A client-initiated ReliableQuicStream. Instances of this class
32 // are owned by the QuicClientSession which created them. 32 // are owned by the QuicClientSession which created them.
33 class NET_EXPORT_PRIVATE QuicChromiumClientStream : public QuicSpdyStream { 33 class NET_EXPORT_PRIVATE QuicChromiumClientStream : public QuicSpdyStream {
34 public: 34 public:
35 // TODO(rch): Remove this class completely in favor of async methods
36 // on the Handle.
37 // Delegate handles protocol specific behavior of a quic stream.
38 class NET_EXPORT_PRIVATE Delegate {
39 public:
40 Delegate() {}
41
42 // Called when the stream is closed by the peer.
43 virtual void OnClose() = 0;
44
45 // Called when the stream is closed because of an error.
46 virtual void OnError(int error) = 0;
47
48 protected:
49 virtual ~Delegate() {}
50
51 private:
52 DISALLOW_COPY_AND_ASSIGN(Delegate);
53 };
54
55 // Wrapper for interacting with the session in a restricted fashion. 35 // Wrapper for interacting with the session in a restricted fashion.
56 class NET_EXPORT_PRIVATE Handle { 36 class NET_EXPORT_PRIVATE Handle {
57 public: 37 public:
58 ~Handle(); 38 ~Handle();
59 39
60 // Returns true if the stream is still connected. 40 // Returns true if the stream is still connected.
61 bool IsOpen() { return stream_ != nullptr; } 41 bool IsOpen() { return stream_ != nullptr; }
62 42
63 // Reads initial headers into |header_block| and returns the length of 43 // Reads initial headers into |header_block| and returns the length of
64 // the HEADERS frame which contained them. If headers are not available, 44 // the HEADERS frame which contained them. If headers are not available,
(...skipping 17 matching lines...) Expand all
82 // the HEADERS frame which contained them. If headers are not available, 62 // the HEADERS frame which contained them. If headers are not available,
83 // returns ERR_IO_PENDING and will invoke |callback| asynchronously when 63 // returns ERR_IO_PENDING and will invoke |callback| asynchronously when
84 // the headers arrive. 64 // the headers arrive.
85 // TODO(rch): Invoke |callback| when there is a stream or connection error 65 // TODO(rch): Invoke |callback| when there is a stream or connection error
86 // instead of calling OnClose() or OnError(). 66 // instead of calling OnClose() or OnError().
87 int ReadTrailingHeaders(SpdyHeaderBlock* header_block, 67 int ReadTrailingHeaders(SpdyHeaderBlock* header_block,
88 const CompletionCallback& callback); 68 const CompletionCallback& callback);
89 69
90 // Writes |header_block| to the peer. Closes the write side if |fin| is 70 // Writes |header_block| to the peer. Closes the write side if |fin| is
91 // true. If non-null, |ack_notifier_delegate| will be notified when the 71 // true. If non-null, |ack_notifier_delegate| will be notified when the
92 // headers are ACK'd by the peer. 72 // headers are ACK'd by the peer. Returns a net error code if there is
93 size_t WriteHeaders(SpdyHeaderBlock header_block, 73 // an error writing the headers, or the number of bytes written on
94 bool fin, 74 // success. Will not return ERR_IO_PENDING.
95 QuicReferenceCountedPointer<QuicAckListenerInterface> 75 int WriteHeaders(SpdyHeaderBlock header_block,
96 ack_notifier_delegate); 76 bool fin,
77 QuicReferenceCountedPointer<QuicAckListenerInterface>
78 ack_notifier_delegate);
97 79
98 // Writes |data| to the peer. Closes the write side if |fin| is true. 80 // Writes |data| to the peer. Closes the write side if |fin| is true.
99 // If the data could not be written immediately, returns ERR_IO_PENDING 81 // If the data could not be written immediately, returns ERR_IO_PENDING
100 // and invokes |callback| asynchronously when the write completes. 82 // and invokes |callback| asynchronously when the write completes.
101 int WriteStreamData(base::StringPiece data, 83 int WriteStreamData(base::StringPiece data,
102 bool fin, 84 bool fin,
103 const CompletionCallback& callback); 85 const CompletionCallback& callback);
104 86
105 // Same as WriteStreamData except it writes data from a vector of IOBuffers, 87 // Same as WriteStreamData except it writes data from a vector of IOBuffers,
106 // with the length of each buffer at the corresponding index in |lengths|. 88 // with the length of each buffer at the corresponding index in |lengths|.
(...skipping 12 matching lines...) Expand all
119 // Prevents the connection from migrating to a new network while this 101 // Prevents the connection from migrating to a new network while this
120 // stream is open. 102 // stream is open.
121 void DisableConnectionMigration(); 103 void DisableConnectionMigration();
122 104
123 // Sets the priority of the stream to |priority|. 105 // Sets the priority of the stream to |priority|.
124 void SetPriority(SpdyPriority priority); 106 void SetPriority(SpdyPriority priority);
125 107
126 // Sends a RST_STREAM frame to the peer and closes the streams. 108 // Sends a RST_STREAM frame to the peer and closes the streams.
127 void Reset(QuicRstStreamErrorCode error_code); 109 void Reset(QuicRstStreamErrorCode error_code);
128 110
129 // Clears |delegate_| from this Handle, but does not disconnect the Handle
130 // from |stream_|.
131 void ClearDelegate();
132
133 QuicStreamId id() const; 111 QuicStreamId id() const;
134 QuicErrorCode connection_error() const; 112 QuicErrorCode connection_error() const;
135 QuicRstStreamErrorCode stream_error() const; 113 QuicRstStreamErrorCode stream_error() const;
136 bool fin_sent() const; 114 bool fin_sent() const;
137 bool fin_received() const; 115 bool fin_received() const;
138 uint64_t stream_bytes_read() const; 116 uint64_t stream_bytes_read() const;
139 uint64_t stream_bytes_written() const; 117 uint64_t stream_bytes_written() const;
140 size_t NumBytesConsumed() const; 118 size_t NumBytesConsumed() const;
141 bool IsDoneReading() const; 119 bool IsDoneReading() const;
142 bool IsFirstStream() const; 120 bool IsFirstStream() const;
143 121
144 // TODO(rch): Move these test-only methods to a peer, or else remove. 122 // TODO(rch): Move these test-only methods to a peer, or else remove.
145 void OnPromiseHeaderList(QuicStreamId promised_id, 123 void OnPromiseHeaderList(QuicStreamId promised_id,
146 size_t frame_len, 124 size_t frame_len,
147 const QuicHeaderList& header_list); 125 const QuicHeaderList& header_list);
148 SpdyPriority priority() const; 126 SpdyPriority priority() const;
149 bool can_migrate(); 127 bool can_migrate();
150 128
151 Delegate* GetDelegate();
152
153 private: 129 private:
154 friend class QuicChromiumClientStream; 130 friend class QuicChromiumClientStream;
155 131
156 // Constucts a new Handle for |stream| with |delegate| set to receive 132 // Constucts a new Handle for |stream|.
157 // up calls on various events. 133 explicit Handle(QuicChromiumClientStream* stream);
158 Handle(QuicChromiumClientStream* stream, Delegate* delegate);
159 134
160 // Methods invoked by the stream. 135 // Methods invoked by the stream.
161 void OnInitialHeadersAvailable(); 136 void OnInitialHeadersAvailable();
162 void OnTrailingHeadersAvailable(); 137 void OnTrailingHeadersAvailable();
163 void OnDataAvailable(); 138 void OnDataAvailable();
164 void OnCanWrite(); 139 void OnCanWrite();
165 void OnClose(); 140 void OnClose();
166 void OnError(int error); 141 void OnError(int error);
167 142
143 // Invokes async IO callbacks because of |error|.
144 void InvokeCallbacksOnClose(int error);
145
168 // Saves various fields from the stream before the stream goes away. 146 // Saves various fields from the stream before the stream goes away.
169 void SaveState(); 147 void SaveState();
170 148
149 void SetCallback(const CompletionCallback& new_callback,
150 CompletionCallback* callback);
151
152 void ResetAndRun(CompletionCallback* callback, int rv);
153
154 int HandleIOComplete(int rv);
155
171 QuicChromiumClientStream* stream_; // Unowned. 156 QuicChromiumClientStream* stream_; // Unowned.
172 Delegate* delegate_; // Owns this. 157
158 bool may_invoke_callbacks_; // True when callbacks may be invoked.
173 159
174 // Callback to be invoked when ReadHeaders completes asynchronously. 160 // Callback to be invoked when ReadHeaders completes asynchronously.
175 CompletionCallback read_headers_callback_; 161 CompletionCallback read_headers_callback_;
176 SpdyHeaderBlock* read_headers_buffer_; 162 SpdyHeaderBlock* read_headers_buffer_;
177 163
178 // Callback to be invoked when ReadBody completes asynchronously. 164 // Callback to be invoked when ReadBody completes asynchronously.
179 CompletionCallback read_body_callback_; 165 CompletionCallback read_body_callback_;
180 IOBuffer* read_body_buffer_; 166 IOBuffer* read_body_buffer_;
181 int read_body_buffer_len_; 167 int read_body_buffer_len_;
182 168
183 // Callback to be invoked when WriteStreamData or WritevStreamData completes 169 // Callback to be invoked when WriteStreamData or WritevStreamData completes
184 // asynchronously. 170 // asynchronously.
185 CompletionCallback write_callback_; 171 CompletionCallback write_callback_;
186 172
187 QuicStreamId id_; 173 QuicStreamId id_;
188 QuicErrorCode connection_error_; 174 QuicErrorCode connection_error_;
189 QuicRstStreamErrorCode stream_error_; 175 QuicRstStreamErrorCode stream_error_;
190 bool fin_sent_; 176 bool fin_sent_;
191 bool fin_received_; 177 bool fin_received_;
192 uint64_t stream_bytes_read_; 178 uint64_t stream_bytes_read_;
193 uint64_t stream_bytes_written_; 179 uint64_t stream_bytes_written_;
194 bool is_done_reading_; 180 bool is_done_reading_;
195 bool is_first_stream_; 181 bool is_first_stream_;
196 size_t num_bytes_consumed_; 182 size_t num_bytes_consumed_;
197 SpdyPriority priority_; 183 SpdyPriority priority_;
198 184
185 int net_error_;
186
187 base::WeakPtrFactory<Handle> weak_factory_;
188
199 DISALLOW_COPY_AND_ASSIGN(Handle); 189 DISALLOW_COPY_AND_ASSIGN(Handle);
200 }; 190 };
201 191
202 QuicChromiumClientStream(QuicStreamId id, 192 QuicChromiumClientStream(QuicStreamId id,
203 QuicClientSessionBase* session, 193 QuicClientSessionBase* session,
204 const NetLogWithSource& net_log); 194 const NetLogWithSource& net_log);
205 195
206 ~QuicChromiumClientStream() override; 196 ~QuicChromiumClientStream() override;
207 197
208 // QuicSpdyStream 198 // QuicSpdyStream
(...skipping 22 matching lines...) Expand all
231 // Writes |data| to the peer and closes the write side if |fin| is true. 221 // Writes |data| to the peer and closes the write side if |fin| is true.
232 // Returns true if the data have been fully written. If the data was not fully 222 // Returns true if the data have been fully written. If the data was not fully
233 // written, returns false and OnCanWrite() will be invoked later. 223 // written, returns false and OnCanWrite() will be invoked later.
234 bool WriteStreamData(QuicStringPiece data, bool fin); 224 bool WriteStreamData(QuicStringPiece data, bool fin);
235 // Same as WriteStreamData except it writes data from a vector of IOBuffers, 225 // Same as WriteStreamData except it writes data from a vector of IOBuffers,
236 // with the length of each buffer at the corresponding index in |lengths|. 226 // with the length of each buffer at the corresponding index in |lengths|.
237 bool WritevStreamData(const std::vector<scoped_refptr<IOBuffer>>& buffers, 227 bool WritevStreamData(const std::vector<scoped_refptr<IOBuffer>>& buffers,
238 const std::vector<int>& lengths, 228 const std::vector<int>& lengths,
239 bool fin); 229 bool fin);
240 230
241 // Creates a new Handle for this stream and sets |delegate| on the handle. 231 // Creates a new Handle for this stream. Must only be called once.
242 // Must only be called once. 232 std::unique_ptr<QuicChromiumClientStream::Handle> CreateHandle();
243 std::unique_ptr<QuicChromiumClientStream::Handle> CreateHandle(
244 QuicChromiumClientStream::Delegate* delegate);
245 233
246 // Clears |handle_| from this stream. 234 // Clears |handle_| from this stream.
247 void ClearHandle(); 235 void ClearHandle();
248 236
249 void OnError(int error); 237 void OnError(int error);
250 238
251 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read. 239 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read.
252 int Read(IOBuffer* buf, int buf_len); 240 int Read(IOBuffer* buf, int buf_len);
253 241
254 const NetLogWithSource& net_log() const { return net_log_; } 242 const NetLogWithSource& net_log() const { return net_log_; }
(...skipping 28 matching lines...) Expand all
283 bool headers_delivered_; 271 bool headers_delivered_;
284 272
285 // True when initial headers have been sent. 273 // True when initial headers have been sent.
286 bool initial_headers_sent_; 274 bool initial_headers_sent_;
287 275
288 QuicClientSessionBase* session_; 276 QuicClientSessionBase* session_;
289 277
290 // Set to false if this stream to not be migrated during connection migration. 278 // Set to false if this stream to not be migrated during connection migration.
291 bool can_migrate_; 279 bool can_migrate_;
292 280
293 // Stores the initial header if they arrive before the delegate. 281 // Stores the initial header if they arrive before the handle.
294 SpdyHeaderBlock initial_headers_; 282 SpdyHeaderBlock initial_headers_;
295 // Length of the HEADERS frame containing initial headers. 283 // Length of the HEADERS frame containing initial headers.
296 size_t initial_headers_frame_len_; 284 size_t initial_headers_frame_len_;
297 285
298 // Length of the HEADERS frame containing trailing headers. 286 // Length of the HEADERS frame containing trailing headers.
299 size_t trailing_headers_frame_len_; 287 size_t trailing_headers_frame_len_;
300 288
301 base::WeakPtrFactory<QuicChromiumClientStream> weak_factory_; 289 base::WeakPtrFactory<QuicChromiumClientStream> weak_factory_;
302 290
303 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientStream); 291 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientStream);
304 }; 292 };
305 293
306 } // namespace net 294 } // namespace net
307 295
308 #endif // NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_STREAM_H_ 296 #endif // NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_STREAM_H_
OLDNEW
« no previous file with comments | « net/quic/chromium/quic_chromium_client_session_test.cc ('k') | net/quic/chromium/quic_chromium_client_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698