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

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

Issue 2868633002: Create a QuicChromiumClientStream::Handle class for allowing a stream (Closed)
Patch Set: Rebase Created 3 years, 7 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.
35 // Delegate handles protocol specific behavior of a quic stream. 37 // Delegate handles protocol specific behavior of a quic stream.
36 class NET_EXPORT_PRIVATE Delegate { 38 class NET_EXPORT_PRIVATE Delegate {
37 public: 39 public:
38 Delegate() {} 40 Delegate() {}
39 41
40 // Called when initial headers are available. 42 // Called when initial headers are available.
41 virtual void OnInitialHeadersAvailable(const SpdyHeaderBlock& headers, 43 virtual void OnInitialHeadersAvailable(const SpdyHeaderBlock& headers,
42 size_t frame_len) = 0; 44 size_t frame_len) = 0;
43 45
44 // Called when trailing headers are available. 46 // Called when trailing headers are available.
45 virtual void OnTrailingHeadersAvailable(const SpdyHeaderBlock& headers, 47 virtual void OnTrailingHeadersAvailable(const SpdyHeaderBlock& headers,
46 size_t frame_len) = 0; 48 size_t frame_len) = 0;
47 49
48 // Called when data is available to be read. 50 // Called when data is available to be read.
49 virtual void OnDataAvailable() = 0; 51 virtual void OnDataAvailable() = 0;
50 52
51 // Called when the stream is closed by the peer. 53 // Called when the stream is closed by the peer.
52 virtual void OnClose() = 0; 54 virtual void OnClose() = 0;
53 55
54 // Called when the stream is closed because of an error. 56 // Called when the stream is closed because of an error.
55 virtual void OnError(int error) = 0; 57 virtual void OnError(int error) = 0;
56 58
57 protected: 59 protected:
58 virtual ~Delegate() {} 60 virtual ~Delegate() {}
59 61
60 private: 62 private:
61 DISALLOW_COPY_AND_ASSIGN(Delegate); 63 DISALLOW_COPY_AND_ASSIGN(Delegate);
62 }; 64 };
63 65
66 // Wrapper for interacting with the session in a restricted fashion.
67 class NET_EXPORT_PRIVATE Handle {
68 public:
69 ~Handle();
70
71 // Returns true if the stream is still connected.
72 bool IsOpen() { return stream_ != nullptr; }
73
74 // 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
76 // headers are ACK'd by the peer.
77 size_t WriteHeaders(SpdyHeaderBlock header_block,
78 bool fin,
79 QuicReferenceCountedPointer<QuicAckListenerInterface>
80 ack_notifier_delegate);
81
82 // 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
84 // and invokes |callback| asynchronously when the write completes.
85 int WriteStreamData(base::StringPiece data,
86 bool fin,
87 const CompletionCallback& callback);
88
89 // Same as WriteStreamData except it writes data from a vector of IOBuffers,
90 // with the length of each buffer at the corresponding index in |lengths|.
91 int WritevStreamData(const std::vector<scoped_refptr<IOBuffer>>& buffers,
92 const std::vector<int>& lengths,
93 bool fin,
94 const CompletionCallback& callback);
95
96 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes
97 // read.
98 int Read(IOBuffer* buf, int buf_len);
99
100 // Called to notify the stream when the final incoming data is read.
101 void OnFinRead();
102
103 // Prevents the connection from migrating to a new network while this
104 // stream is open.
105 void DisableConnectionMigration();
106
107 // Sets the priority of the stream to |priority|.
108 void SetPriority(SpdyPriority priority);
109
110 // Sends a RST_STREAM frame to the peer and closes the streams.
111 void Reset(QuicRstStreamErrorCode error_code);
112
113 // Clears |delegate_| from this Handle, but does not disconnect the Handle
114 // from |stream_|.
115 void ClearDelegate();
116
117 QuicStreamId id() const;
118 QuicErrorCode connection_error() const;
119 QuicRstStreamErrorCode stream_error() const;
120 bool fin_sent() const;
121 bool fin_received() const;
122 uint64_t stream_bytes_read() const;
123 uint64_t stream_bytes_written() const;
124 size_t NumBytesConsumed() const;
125 bool IsDoneReading() const;
126 bool IsFirstStream() const;
127
128 // TODO(rch): Move these test-only methods to a peer, or else remove.
129 void OnPromiseHeaderList(QuicStreamId promised_id,
130 size_t frame_len,
131 const QuicHeaderList& header_list);
132 SpdyPriority priority() const;
133 bool can_migrate();
134
135 Delegate* GetDelegate();
136
137 private:
138 friend class QuicChromiumClientStream;
139
140 // Constucts a new Handle for |stream| with |delegate| set to receive
141 // up calls on various events.
142 Handle(QuicChromiumClientStream* stream, Delegate* delegate);
143
144 // Methods invoked by the stream.
145 void OnInitialHeadersAvailable(const SpdyHeaderBlock& headers,
146 size_t frame_len);
147 void OnTrailingHeadersAvailable(const SpdyHeaderBlock& headers,
148 size_t frame_len);
149 void OnDataAvailable();
150 void OnClose();
151 void OnError(int error);
152
153 // Saves various fields from the stream before the stream goes away.
154 void SaveState();
155
156 QuicChromiumClientStream* stream_; // Unowned.
157 Delegate* delegate_; // Owns this.
158
159 QuicStreamId id_;
160 QuicErrorCode connection_error_;
161 QuicRstStreamErrorCode stream_error_;
162 bool fin_sent_;
163 bool fin_received_;
164 uint64_t stream_bytes_read_;
165 uint64_t stream_bytes_written_;
166 bool is_done_reading_;
167 bool is_first_stream_;
168 size_t num_bytes_consumed_;
169 SpdyPriority priority_;
170
171 DISALLOW_COPY_AND_ASSIGN(Handle);
172 };
173
64 QuicChromiumClientStream(QuicStreamId id, 174 QuicChromiumClientStream(QuicStreamId id,
65 QuicClientSessionBase* session, 175 QuicClientSessionBase* session,
66 const NetLogWithSource& net_log); 176 const NetLogWithSource& net_log);
67 177
68 ~QuicChromiumClientStream() override; 178 ~QuicChromiumClientStream() override;
69 179
70 // QuicSpdyStream 180 // QuicSpdyStream
71 void OnInitialHeadersComplete(bool fin, 181 void OnInitialHeadersComplete(bool fin,
72 size_t frame_len, 182 size_t frame_len,
73 const QuicHeaderList& header_list) override; 183 const QuicHeaderList& header_list) override;
(...skipping 18 matching lines...) Expand all
92 202
93 int WriteStreamData(QuicStringPiece data, 203 int WriteStreamData(QuicStringPiece data,
94 bool fin, 204 bool fin,
95 const CompletionCallback& callback); 205 const CompletionCallback& callback);
96 // Same as WriteStreamData except it writes data from a vector of IOBuffers, 206 // Same as WriteStreamData except it writes data from a vector of IOBuffers,
97 // with the length of each buffer at the corresponding index in |lengths|. 207 // with the length of each buffer at the corresponding index in |lengths|.
98 int WritevStreamData(const std::vector<scoped_refptr<IOBuffer>>& buffers, 208 int WritevStreamData(const std::vector<scoped_refptr<IOBuffer>>& buffers,
99 const std::vector<int>& lengths, 209 const std::vector<int>& lengths,
100 bool fin, 210 bool fin,
101 const CompletionCallback& callback); 211 const CompletionCallback& callback);
102 // Set new |delegate|. |delegate| must not be NULL. 212
103 // If this stream has already received data, OnDataReceived() will be 213 // Creates a new Handle for this stream and sets |delegate| on the handle.
104 // called on the delegate. 214 // Must only be called once.
105 void SetDelegate(Delegate* delegate); 215 std::unique_ptr<QuicChromiumClientStream::Handle> CreateHandle(
106 Delegate* GetDelegate() { return delegate_; } 216 QuicChromiumClientStream::Delegate* delegate);
217
218 // Clears |handle_| from this stream.
219 void ClearHandle();
220
107 void OnError(int error); 221 void OnError(int error);
108 222
109 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read. 223 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read.
110 int Read(IOBuffer* buf, int buf_len); 224 int Read(IOBuffer* buf, int buf_len);
111 225
112 const NetLogWithSource& net_log() const { return net_log_; } 226 const NetLogWithSource& net_log() const { return net_log_; }
113 227
114 // Prevents this stream from migrating to a new network. May cause other 228 // Prevents this stream from migrating to a new network. May cause other
115 // concurrent streams within the session to also not migrate. 229 // concurrent streams within the session to also not migrate.
116 void DisableConnectionMigration(); 230 void DisableConnectionMigration();
117 231
118 bool can_migrate() { return can_migrate_; } 232 bool can_migrate() { return can_migrate_; }
119 233
120 // True if this stream is the first data stream created on this session. 234 // True if this stream is the first data stream created on this session.
121 bool IsFirstStream(); 235 bool IsFirstStream();
122 236
123 using QuicSpdyStream::HasBufferedData; 237 using QuicSpdyStream::HasBufferedData;
124 using QuicStream::sequencer; 238 using QuicStream::sequencer;
125 239
126 private: 240 private:
127 void NotifyDelegateOfInitialHeadersAvailableLater(SpdyHeaderBlock headers, 241 void NotifyHandleOfInitialHeadersAvailableLater(SpdyHeaderBlock headers,
128 size_t frame_len); 242 size_t frame_len);
129 void NotifyDelegateOfInitialHeadersAvailable(SpdyHeaderBlock headers, 243 void NotifyHandleOfInitialHeadersAvailable(SpdyHeaderBlock headers,
130 size_t frame_len); 244 size_t frame_len);
131 void NotifyDelegateOfTrailingHeadersAvailableLater(SpdyHeaderBlock headers, 245 void NotifyHandleOfTrailingHeadersAvailableLater(SpdyHeaderBlock headers,
132 size_t frame_len); 246 size_t frame_len);
133 void NotifyDelegateOfTrailingHeadersAvailable(SpdyHeaderBlock headers, 247 void NotifyHandleOfTrailingHeadersAvailable(SpdyHeaderBlock headers,
134 size_t frame_len); 248 size_t frame_len);
135 void NotifyDelegateOfDataAvailableLater(); 249 void NotifyHandleOfDataAvailableLater();
136 void NotifyDelegateOfDataAvailable(); 250 void NotifyHandleOfDataAvailable();
137 251
138 NetLogWithSource net_log_; 252 NetLogWithSource net_log_;
139 Delegate* delegate_; 253 Handle* handle_;
140 254
141 bool headers_delivered_; 255 bool headers_delivered_;
142 256
143 // True when initial headers have been sent. 257 // True when initial headers have been sent.
144 bool initial_headers_sent_; 258 bool initial_headers_sent_;
145 259
146 // Callback to be invoked when WriteStreamData or WritevStreamData completes 260 // Callback to be invoked when WriteStreamData or WritevStreamData completes
147 // asynchronously. 261 // asynchronously.
148 CompletionCallback write_callback_; 262 CompletionCallback write_callback_;
149 263
150 QuicClientSessionBase* session_; 264 QuicClientSessionBase* session_;
151 265
152 // Set to false if this stream to not be migrated during connection migration. 266 // Set to false if this stream to not be migrated during connection migration.
153 bool can_migrate_; 267 bool can_migrate_;
154 268
155 // Stores the initial header if they arrive before the delegate. 269 // Stores the initial header if they arrive before the delegate.
156 SpdyHeaderBlock initial_headers_; 270 SpdyHeaderBlock initial_headers_;
157 // Length of the HEADERS frame containing initial headers. 271 // Length of the HEADERS frame containing initial headers.
158 size_t initial_headers_frame_len_; 272 size_t initial_headers_frame_len_;
159 273
160 base::WeakPtrFactory<QuicChromiumClientStream> weak_factory_; 274 base::WeakPtrFactory<QuicChromiumClientStream> weak_factory_;
161 275
162 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientStream); 276 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientStream);
163 }; 277 };
164 278
165 } // namespace net 279 } // namespace net
166 280
167 #endif // NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_STREAM_H_ 281 #endif // NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_STREAM_H_
OLDNEW
« no previous file with comments | « net/quic/chromium/quic_chromium_client_session.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