Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 18 matching lines...) Expand all Loading... | |
| 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. |
| 93 size_t WriteHeaders(SpdyHeaderBlock header_block, | 73 int WriteHeaders(SpdyHeaderBlock header_block, |
|
xunjieli
2017/05/31 00:25:22
Could you add a comment here mentioning that the r
Ryan Hamilton
2017/05/31 02:49:56
Done.
| |
| 94 bool fin, | 74 bool fin, |
| 95 QuicReferenceCountedPointer<QuicAckListenerInterface> | 75 QuicReferenceCountedPointer<QuicAckListenerInterface> |
| 96 ack_notifier_delegate); | 76 ack_notifier_delegate); |
| 97 | 77 |
| 98 // Writes |data| to the peer. Closes the write side if |fin| is true. | 78 // 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 | 79 // If the data could not be written immediately, returns ERR_IO_PENDING |
| 100 // and invokes |callback| asynchronously when the write completes. | 80 // and invokes |callback| asynchronously when the write completes. |
| 101 int WriteStreamData(base::StringPiece data, | 81 int WriteStreamData(base::StringPiece data, |
| 102 bool fin, | 82 bool fin, |
| 103 const CompletionCallback& callback); | 83 const CompletionCallback& callback); |
| 104 | 84 |
| 105 // Same as WriteStreamData except it writes data from a vector of IOBuffers, | 85 // 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|. | 86 // with the length of each buffer at the corresponding index in |lengths|. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 119 // Prevents the connection from migrating to a new network while this | 99 // Prevents the connection from migrating to a new network while this |
| 120 // stream is open. | 100 // stream is open. |
| 121 void DisableConnectionMigration(); | 101 void DisableConnectionMigration(); |
| 122 | 102 |
| 123 // Sets the priority of the stream to |priority|. | 103 // Sets the priority of the stream to |priority|. |
| 124 void SetPriority(SpdyPriority priority); | 104 void SetPriority(SpdyPriority priority); |
| 125 | 105 |
| 126 // Sends a RST_STREAM frame to the peer and closes the streams. | 106 // Sends a RST_STREAM frame to the peer and closes the streams. |
| 127 void Reset(QuicRstStreamErrorCode error_code); | 107 void Reset(QuicRstStreamErrorCode error_code); |
| 128 | 108 |
| 129 // Clears |delegate_| from this Handle, but does not disconnect the Handle | |
| 130 // from |stream_|. | |
| 131 void ClearDelegate(); | |
| 132 | |
| 133 QuicStreamId id() const; | 109 QuicStreamId id() const; |
| 134 QuicErrorCode connection_error() const; | 110 QuicErrorCode connection_error() const; |
| 135 QuicRstStreamErrorCode stream_error() const; | 111 QuicRstStreamErrorCode stream_error() const; |
| 136 bool fin_sent() const; | 112 bool fin_sent() const; |
| 137 bool fin_received() const; | 113 bool fin_received() const; |
| 138 uint64_t stream_bytes_read() const; | 114 uint64_t stream_bytes_read() const; |
| 139 uint64_t stream_bytes_written() const; | 115 uint64_t stream_bytes_written() const; |
| 140 size_t NumBytesConsumed() const; | 116 size_t NumBytesConsumed() const; |
| 141 bool IsDoneReading() const; | 117 bool IsDoneReading() const; |
| 142 bool IsFirstStream() const; | 118 bool IsFirstStream() const; |
| 143 | 119 |
| 144 // TODO(rch): Move these test-only methods to a peer, or else remove. | 120 // TODO(rch): Move these test-only methods to a peer, or else remove. |
| 145 void OnPromiseHeaderList(QuicStreamId promised_id, | 121 void OnPromiseHeaderList(QuicStreamId promised_id, |
| 146 size_t frame_len, | 122 size_t frame_len, |
| 147 const QuicHeaderList& header_list); | 123 const QuicHeaderList& header_list); |
| 148 SpdyPriority priority() const; | 124 SpdyPriority priority() const; |
| 149 bool can_migrate(); | 125 bool can_migrate(); |
| 150 | 126 |
| 151 Delegate* GetDelegate(); | |
| 152 | |
| 153 private: | 127 private: |
| 154 friend class QuicChromiumClientStream; | 128 friend class QuicChromiumClientStream; |
| 155 | 129 |
| 156 // Constucts a new Handle for |stream| with |delegate| set to receive | 130 // Constucts a new Handle for |stream|. |
| 157 // up calls on various events. | 131 explicit Handle(QuicChromiumClientStream* stream); |
| 158 Handle(QuicChromiumClientStream* stream, Delegate* delegate); | |
| 159 | 132 |
| 160 // Methods invoked by the stream. | 133 // Methods invoked by the stream. |
| 161 void OnInitialHeadersAvailable(); | 134 void OnInitialHeadersAvailable(); |
| 162 void OnTrailingHeadersAvailable(); | 135 void OnTrailingHeadersAvailable(); |
| 163 void OnDataAvailable(); | 136 void OnDataAvailable(); |
| 164 void OnCanWrite(); | 137 void OnCanWrite(); |
| 165 void OnClose(); | 138 void OnClose(); |
| 166 void OnError(int error); | 139 void OnError(int error); |
| 167 | 140 |
| 141 // Invokes async IO callbacks because of |error|. | |
| 142 void InvokeCallbacksOnError(int error); | |
| 143 | |
| 168 // Saves various fields from the stream before the stream goes away. | 144 // Saves various fields from the stream before the stream goes away. |
| 169 void SaveState(); | 145 void SaveState(); |
| 170 | 146 |
| 147 void SetCallback(CompletionCallback new_callback, | |
| 148 CompletionCallback* callback); | |
| 149 | |
| 150 void ResetAndRun(CompletionCallback* callback, int rv); | |
| 151 | |
| 152 int HandleIOComplete(int rv); | |
| 153 | |
| 171 QuicChromiumClientStream* stream_; // Unowned. | 154 QuicChromiumClientStream* stream_; // Unowned. |
| 172 Delegate* delegate_; // Owns this. | 155 |
| 156 bool may_invoke_callbacks_; // True when callbacks may be invoked. | |
| 173 | 157 |
| 174 // Callback to be invoked when ReadHeaders completes asynchronously. | 158 // Callback to be invoked when ReadHeaders completes asynchronously. |
| 175 CompletionCallback read_headers_callback_; | 159 CompletionCallback read_headers_callback_; |
| 176 SpdyHeaderBlock* read_headers_buffer_; | 160 SpdyHeaderBlock* read_headers_buffer_; |
| 177 | 161 |
| 178 // Callback to be invoked when ReadBody completes asynchronously. | 162 // Callback to be invoked when ReadBody completes asynchronously. |
| 179 CompletionCallback read_body_callback_; | 163 CompletionCallback read_body_callback_; |
| 180 IOBuffer* read_body_buffer_; | 164 IOBuffer* read_body_buffer_; |
| 181 int read_body_buffer_len_; | 165 int read_body_buffer_len_; |
| 182 | 166 |
| 183 // Callback to be invoked when WriteStreamData or WritevStreamData completes | 167 // Callback to be invoked when WriteStreamData or WritevStreamData completes |
| 184 // asynchronously. | 168 // asynchronously. |
| 185 CompletionCallback write_callback_; | 169 CompletionCallback write_callback_; |
| 186 | 170 |
| 187 QuicStreamId id_; | 171 QuicStreamId id_; |
| 188 QuicErrorCode connection_error_; | 172 QuicErrorCode connection_error_; |
| 189 QuicRstStreamErrorCode stream_error_; | 173 QuicRstStreamErrorCode stream_error_; |
| 190 bool fin_sent_; | 174 bool fin_sent_; |
| 191 bool fin_received_; | 175 bool fin_received_; |
| 192 uint64_t stream_bytes_read_; | 176 uint64_t stream_bytes_read_; |
| 193 uint64_t stream_bytes_written_; | 177 uint64_t stream_bytes_written_; |
| 194 bool is_done_reading_; | 178 bool is_done_reading_; |
| 195 bool is_first_stream_; | 179 bool is_first_stream_; |
| 196 size_t num_bytes_consumed_; | 180 size_t num_bytes_consumed_; |
| 197 SpdyPriority priority_; | 181 SpdyPriority priority_; |
| 198 | 182 |
| 183 int net_error_; | |
| 184 | |
| 185 base::WeakPtrFactory<Handle> weak_factory_; | |
| 186 | |
| 199 DISALLOW_COPY_AND_ASSIGN(Handle); | 187 DISALLOW_COPY_AND_ASSIGN(Handle); |
| 200 }; | 188 }; |
| 201 | 189 |
| 202 QuicChromiumClientStream(QuicStreamId id, | 190 QuicChromiumClientStream(QuicStreamId id, |
| 203 QuicClientSessionBase* session, | 191 QuicClientSessionBase* session, |
| 204 const NetLogWithSource& net_log); | 192 const NetLogWithSource& net_log); |
| 205 | 193 |
| 206 ~QuicChromiumClientStream() override; | 194 ~QuicChromiumClientStream() override; |
| 207 | 195 |
| 208 // QuicSpdyStream | 196 // QuicSpdyStream |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 231 // Writes |data| to the peer and closes the write side if |fin| is true. | 219 // 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 | 220 // 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. | 221 // written, returns false and OnCanWrite() will be invoked later. |
| 234 bool WriteStreamData(QuicStringPiece data, bool fin); | 222 bool WriteStreamData(QuicStringPiece data, bool fin); |
| 235 // Same as WriteStreamData except it writes data from a vector of IOBuffers, | 223 // 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|. | 224 // with the length of each buffer at the corresponding index in |lengths|. |
| 237 bool WritevStreamData(const std::vector<scoped_refptr<IOBuffer>>& buffers, | 225 bool WritevStreamData(const std::vector<scoped_refptr<IOBuffer>>& buffers, |
| 238 const std::vector<int>& lengths, | 226 const std::vector<int>& lengths, |
| 239 bool fin); | 227 bool fin); |
| 240 | 228 |
| 241 // Creates a new Handle for this stream and sets |delegate| on the handle. | 229 // Creates a new Handle for this stream. Must only be called once. |
| 242 // Must only be called once. | 230 std::unique_ptr<QuicChromiumClientStream::Handle> CreateHandle(); |
| 243 std::unique_ptr<QuicChromiumClientStream::Handle> CreateHandle( | |
| 244 QuicChromiumClientStream::Delegate* delegate); | |
| 245 | 231 |
| 246 // Clears |handle_| from this stream. | 232 // Clears |handle_| from this stream. |
| 247 void ClearHandle(); | 233 void ClearHandle(); |
| 248 | 234 |
| 249 void OnError(int error); | 235 void OnError(int error); |
| 250 | 236 |
| 251 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read. | 237 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read. |
| 252 int Read(IOBuffer* buf, int buf_len); | 238 int Read(IOBuffer* buf, int buf_len); |
| 253 | 239 |
| 254 const NetLogWithSource& net_log() const { return net_log_; } | 240 const NetLogWithSource& net_log() const { return net_log_; } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 283 bool headers_delivered_; | 269 bool headers_delivered_; |
| 284 | 270 |
| 285 // True when initial headers have been sent. | 271 // True when initial headers have been sent. |
| 286 bool initial_headers_sent_; | 272 bool initial_headers_sent_; |
| 287 | 273 |
| 288 QuicClientSessionBase* session_; | 274 QuicClientSessionBase* session_; |
| 289 | 275 |
| 290 // Set to false if this stream to not be migrated during connection migration. | 276 // Set to false if this stream to not be migrated during connection migration. |
| 291 bool can_migrate_; | 277 bool can_migrate_; |
| 292 | 278 |
| 293 // Stores the initial header if they arrive before the delegate. | 279 // Stores the initial header if they arrive before the handle. |
| 294 SpdyHeaderBlock initial_headers_; | 280 SpdyHeaderBlock initial_headers_; |
| 295 // Length of the HEADERS frame containing initial headers. | 281 // Length of the HEADERS frame containing initial headers. |
| 296 size_t initial_headers_frame_len_; | 282 size_t initial_headers_frame_len_; |
| 297 | 283 |
| 298 // Length of the HEADERS frame containing trailing headers. | 284 // Length of the HEADERS frame containing trailing headers. |
| 299 size_t trailing_headers_frame_len_; | 285 size_t trailing_headers_frame_len_; |
| 300 | 286 |
| 301 base::WeakPtrFactory<QuicChromiumClientStream> weak_factory_; | 287 base::WeakPtrFactory<QuicChromiumClientStream> weak_factory_; |
| 302 | 288 |
| 303 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientStream); | 289 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientStream); |
| 304 }; | 290 }; |
| 305 | 291 |
| 306 } // namespace net | 292 } // namespace net |
| 307 | 293 |
| 308 #endif // NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_STREAM_H_ | 294 #endif // NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_STREAM_H_ |
| OLD | NEW |