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 21 matching lines...) Expand all Loading... | |
| 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 | 35 // TODO(rch): Remove this class completely in favor of async methods |
| 36 // on the Handle. | 36 // on the Handle. |
| 37 // Delegate handles protocol specific behavior of a quic stream. | 37 // Delegate handles protocol specific behavior of a quic stream. |
| 38 class NET_EXPORT_PRIVATE Delegate { | 38 class NET_EXPORT_PRIVATE Delegate { |
| 39 public: | 39 public: |
| 40 Delegate() {} | 40 Delegate() {} |
| 41 | 41 |
| 42 // Called when initial headers are available. | |
| 43 virtual void OnInitialHeadersAvailable(const SpdyHeaderBlock& headers, | |
| 44 size_t frame_len) = 0; | |
| 45 | |
| 46 // Called when trailing headers are available. | 42 // Called when trailing headers are available. |
| 47 virtual void OnTrailingHeadersAvailable(const SpdyHeaderBlock& headers, | 43 virtual void OnTrailingHeadersAvailable(const SpdyHeaderBlock& headers, |
| 48 size_t frame_len) = 0; | 44 size_t frame_len) = 0; |
| 49 | 45 |
| 50 // Called when data is available to be read. | 46 // Called when data is available to be read. |
| 51 virtual void OnDataAvailable() = 0; | 47 virtual void OnDataAvailable() = 0; |
| 52 | 48 |
| 53 // Called when the stream is closed by the peer. | 49 // Called when the stream is closed by the peer. |
| 54 virtual void OnClose() = 0; | 50 virtual void OnClose() = 0; |
| 55 | 51 |
| 56 // Called when the stream is closed because of an error. | 52 // Called when the stream is closed because of an error. |
| 57 virtual void OnError(int error) = 0; | 53 virtual void OnError(int error) = 0; |
| 58 | 54 |
| 59 protected: | 55 protected: |
| 60 virtual ~Delegate() {} | 56 virtual ~Delegate() {} |
| 61 | 57 |
| 62 private: | 58 private: |
| 63 DISALLOW_COPY_AND_ASSIGN(Delegate); | 59 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 64 }; | 60 }; |
| 65 | 61 |
| 66 // Wrapper for interacting with the session in a restricted fashion. | 62 // Wrapper for interacting with the session in a restricted fashion. |
| 67 class NET_EXPORT_PRIVATE Handle { | 63 class NET_EXPORT_PRIVATE Handle { |
| 68 public: | 64 public: |
| 69 ~Handle(); | 65 ~Handle(); |
| 70 | 66 |
| 71 // Returns true if the stream is still connected. | 67 // Returns true if the stream is still connected. |
| 72 bool IsOpen() { return stream_ != nullptr; } | 68 bool IsOpen() { return stream_ != nullptr; } |
| 73 | 69 |
| 70 // Reads initial headers into |header_block| and returns the lenght of | |
|
xunjieli
2017/05/10 17:54:27
nit: typo in length
Ryan Hamilton
2017/05/10 18:26:40
Done.
| |
| 71 // the HEADERS frame which contained them. If headers are not available, | |
| 72 // returns ERR_IO_PENDING and will invokes |callback| asynchronously when | |
|
xunjieli
2017/05/10 17:54:27
nit: s/invokes/invoke
Ryan Hamilton
2017/05/10 18:26:40
Done.
| |
| 73 // the headers arrive. | |
| 74 // TODO(rch): Invoke |callback| when there is a stream or connection error | |
| 75 // instead of calling OnClose() or OnError(). | |
| 76 int ReadInitialHeaders(SpdyHeaderBlock* header_block, | |
| 77 const CompletionCallback& callback); | |
| 78 | |
| 74 // Writes |header_block| to the peer. Closes the write side if |fin| is | 79 // Writes |header_block| to the peer. Closes the write side if |fin| is |
| 75 // true. If non-null, |ack_notifier_delegate| will be notified when the | 80 // true. If non-null, |ack_notifier_delegate| will be notified when the |
| 76 // headers are ACK'd by the peer. | 81 // headers are ACK'd by the peer. |
| 77 size_t WriteHeaders(SpdyHeaderBlock header_block, | 82 size_t WriteHeaders(SpdyHeaderBlock header_block, |
| 78 bool fin, | 83 bool fin, |
| 79 QuicReferenceCountedPointer<QuicAckListenerInterface> | 84 QuicReferenceCountedPointer<QuicAckListenerInterface> |
| 80 ack_notifier_delegate); | 85 ack_notifier_delegate); |
| 81 | 86 |
| 82 // Writes |data| to the peer. Closes the write side if |fin| is true. | 87 // Writes |data| to the peer. Closes the write side if |fin| is true. |
| 83 // If the data could not be written immediately, returns ERR_IO_PENDING | 88 // If the data could not be written immediately, returns ERR_IO_PENDING |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 Delegate* GetDelegate(); | 140 Delegate* GetDelegate(); |
| 136 | 141 |
| 137 private: | 142 private: |
| 138 friend class QuicChromiumClientStream; | 143 friend class QuicChromiumClientStream; |
| 139 | 144 |
| 140 // Constucts a new Handle for |stream| with |delegate| set to receive | 145 // Constucts a new Handle for |stream| with |delegate| set to receive |
| 141 // up calls on various events. | 146 // up calls on various events. |
| 142 Handle(QuicChromiumClientStream* stream, Delegate* delegate); | 147 Handle(QuicChromiumClientStream* stream, Delegate* delegate); |
| 143 | 148 |
| 144 // Methods invoked by the stream. | 149 // Methods invoked by the stream. |
| 145 void OnInitialHeadersAvailable(const SpdyHeaderBlock& headers, | 150 void OnInitialHeadersAvailable(); |
| 146 size_t frame_len); | |
| 147 void OnTrailingHeadersAvailable(const SpdyHeaderBlock& headers, | 151 void OnTrailingHeadersAvailable(const SpdyHeaderBlock& headers, |
| 148 size_t frame_len); | 152 size_t frame_len); |
| 149 void OnDataAvailable(); | 153 void OnDataAvailable(); |
| 150 void OnClose(); | 154 void OnClose(); |
| 151 void OnError(int error); | 155 void OnError(int error); |
| 152 | 156 |
| 153 // Saves various fields from the stream before the stream goes away. | 157 // Saves various fields from the stream before the stream goes away. |
| 154 void SaveState(); | 158 void SaveState(); |
| 155 | 159 |
| 160 void SetCallback(CompletionCallback new_callback, | |
| 161 CompletionCallback* callback); | |
| 162 | |
| 156 QuicChromiumClientStream* stream_; // Unowned. | 163 QuicChromiumClientStream* stream_; // Unowned. |
| 157 Delegate* delegate_; // Owns this. | 164 Delegate* delegate_; // Owns this. |
| 158 | 165 |
| 166 // True when callbacks can be invoked, which means no synchronous | |
| 167 // method is in progress. | |
| 168 bool can_invoke_callbacks_; | |
| 169 CompletionCallback read_headers_callback_; | |
| 170 SpdyHeaderBlock* read_headers_buffer_; | |
| 171 | |
| 159 QuicStreamId id_; | 172 QuicStreamId id_; |
| 160 QuicErrorCode connection_error_; | 173 QuicErrorCode connection_error_; |
| 161 QuicRstStreamErrorCode stream_error_; | 174 QuicRstStreamErrorCode stream_error_; |
| 162 bool fin_sent_; | 175 bool fin_sent_; |
| 163 bool fin_received_; | 176 bool fin_received_; |
| 164 uint64_t stream_bytes_read_; | 177 uint64_t stream_bytes_read_; |
| 165 uint64_t stream_bytes_written_; | 178 uint64_t stream_bytes_written_; |
| 166 bool is_done_reading_; | 179 bool is_done_reading_; |
| 167 bool is_first_stream_; | 180 bool is_first_stream_; |
| 168 size_t num_bytes_consumed_; | 181 size_t num_bytes_consumed_; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 | 240 |
| 228 // Prevents this stream from migrating to a new network. May cause other | 241 // Prevents this stream from migrating to a new network. May cause other |
| 229 // concurrent streams within the session to also not migrate. | 242 // concurrent streams within the session to also not migrate. |
| 230 void DisableConnectionMigration(); | 243 void DisableConnectionMigration(); |
| 231 | 244 |
| 232 bool can_migrate() { return can_migrate_; } | 245 bool can_migrate() { return can_migrate_; } |
| 233 | 246 |
| 234 // True if this stream is the first data stream created on this session. | 247 // True if this stream is the first data stream created on this session. |
| 235 bool IsFirstStream(); | 248 bool IsFirstStream(); |
| 236 | 249 |
| 250 bool DeliverInitialHeaders(SpdyHeaderBlock* header_block, int* frame_len); | |
| 251 | |
| 237 using QuicSpdyStream::HasBufferedData; | 252 using QuicSpdyStream::HasBufferedData; |
| 238 using QuicStream::sequencer; | 253 using QuicStream::sequencer; |
| 239 | 254 |
| 240 private: | 255 private: |
| 241 void NotifyHandleOfInitialHeadersAvailableLater(SpdyHeaderBlock headers, | 256 void NotifyHandleOfInitialHeadersAvailableLater(); |
| 242 size_t frame_len); | 257 void NotifyHandleOfInitialHeadersAvailable(); |
| 243 void NotifyHandleOfInitialHeadersAvailable(SpdyHeaderBlock headers, | |
| 244 size_t frame_len); | |
| 245 void NotifyHandleOfTrailingHeadersAvailableLater(SpdyHeaderBlock headers, | 258 void NotifyHandleOfTrailingHeadersAvailableLater(SpdyHeaderBlock headers, |
| 246 size_t frame_len); | 259 size_t frame_len); |
| 247 void NotifyHandleOfTrailingHeadersAvailable(SpdyHeaderBlock headers, | 260 void NotifyHandleOfTrailingHeadersAvailable(SpdyHeaderBlock headers, |
| 248 size_t frame_len); | 261 size_t frame_len); |
| 249 void NotifyHandleOfDataAvailableLater(); | 262 void NotifyHandleOfDataAvailableLater(); |
| 250 void NotifyHandleOfDataAvailable(); | 263 void NotifyHandleOfDataAvailable(); |
| 251 | 264 |
| 252 NetLogWithSource net_log_; | 265 NetLogWithSource net_log_; |
| 253 Handle* handle_; | 266 Handle* handle_; |
| 254 | 267 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 272 size_t initial_headers_frame_len_; | 285 size_t initial_headers_frame_len_; |
| 273 | 286 |
| 274 base::WeakPtrFactory<QuicChromiumClientStream> weak_factory_; | 287 base::WeakPtrFactory<QuicChromiumClientStream> weak_factory_; |
| 275 | 288 |
| 276 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientStream); | 289 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientStream); |
| 277 }; | 290 }; |
| 278 | 291 |
| 279 } // namespace net | 292 } // namespace net |
| 280 | 293 |
| 281 #endif // NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_STREAM_H_ | 294 #endif // NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_STREAM_H_ |
| OLD | NEW |