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 length of |
| 71 // the HEADERS frame which contained them. If headers are not available, |
| 72 // returns ERR_IO_PENDING and will invoke |callback| asynchronously when |
| 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 |
156 QuicChromiumClientStream* stream_; // Unowned. | 160 QuicChromiumClientStream* stream_; // Unowned. |
157 Delegate* delegate_; // Owns this. | 161 Delegate* delegate_; // Owns this. |
158 | 162 |
| 163 CompletionCallback read_headers_callback_; |
| 164 SpdyHeaderBlock* read_headers_buffer_; |
| 165 |
159 QuicStreamId id_; | 166 QuicStreamId id_; |
160 QuicErrorCode connection_error_; | 167 QuicErrorCode connection_error_; |
161 QuicRstStreamErrorCode stream_error_; | 168 QuicRstStreamErrorCode stream_error_; |
162 bool fin_sent_; | 169 bool fin_sent_; |
163 bool fin_received_; | 170 bool fin_received_; |
164 uint64_t stream_bytes_read_; | 171 uint64_t stream_bytes_read_; |
165 uint64_t stream_bytes_written_; | 172 uint64_t stream_bytes_written_; |
166 bool is_done_reading_; | 173 bool is_done_reading_; |
167 bool is_first_stream_; | 174 bool is_first_stream_; |
168 size_t num_bytes_consumed_; | 175 size_t num_bytes_consumed_; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 234 |
228 // Prevents this stream from migrating to a new network. May cause other | 235 // Prevents this stream from migrating to a new network. May cause other |
229 // concurrent streams within the session to also not migrate. | 236 // concurrent streams within the session to also not migrate. |
230 void DisableConnectionMigration(); | 237 void DisableConnectionMigration(); |
231 | 238 |
232 bool can_migrate() { return can_migrate_; } | 239 bool can_migrate() { return can_migrate_; } |
233 | 240 |
234 // True if this stream is the first data stream created on this session. | 241 // True if this stream is the first data stream created on this session. |
235 bool IsFirstStream(); | 242 bool IsFirstStream(); |
236 | 243 |
| 244 bool DeliverInitialHeaders(SpdyHeaderBlock* header_block, int* frame_len); |
| 245 |
237 using QuicSpdyStream::HasBufferedData; | 246 using QuicSpdyStream::HasBufferedData; |
238 using QuicStream::sequencer; | 247 using QuicStream::sequencer; |
239 | 248 |
240 private: | 249 private: |
241 void NotifyHandleOfInitialHeadersAvailableLater(SpdyHeaderBlock headers, | 250 void NotifyHandleOfInitialHeadersAvailableLater(); |
242 size_t frame_len); | 251 void NotifyHandleOfInitialHeadersAvailable(); |
243 void NotifyHandleOfInitialHeadersAvailable(SpdyHeaderBlock headers, | |
244 size_t frame_len); | |
245 void NotifyHandleOfTrailingHeadersAvailableLater(SpdyHeaderBlock headers, | 252 void NotifyHandleOfTrailingHeadersAvailableLater(SpdyHeaderBlock headers, |
246 size_t frame_len); | 253 size_t frame_len); |
247 void NotifyHandleOfTrailingHeadersAvailable(SpdyHeaderBlock headers, | 254 void NotifyHandleOfTrailingHeadersAvailable(SpdyHeaderBlock headers, |
248 size_t frame_len); | 255 size_t frame_len); |
249 void NotifyHandleOfDataAvailableLater(); | 256 void NotifyHandleOfDataAvailableLater(); |
250 void NotifyHandleOfDataAvailable(); | 257 void NotifyHandleOfDataAvailable(); |
251 | 258 |
252 NetLogWithSource net_log_; | 259 NetLogWithSource net_log_; |
253 Handle* handle_; | 260 Handle* handle_; |
254 | 261 |
(...skipping 17 matching lines...) Expand all Loading... |
272 size_t initial_headers_frame_len_; | 279 size_t initial_headers_frame_len_; |
273 | 280 |
274 base::WeakPtrFactory<QuicChromiumClientStream> weak_factory_; | 281 base::WeakPtrFactory<QuicChromiumClientStream> weak_factory_; |
275 | 282 |
276 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientStream); | 283 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientStream); |
277 }; | 284 }; |
278 | 285 |
279 } // namespace net | 286 } // namespace net |
280 | 287 |
281 #endif // NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_STREAM_H_ | 288 #endif // NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_STREAM_H_ |
OLD | NEW |