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

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 SpdyPriority priority() const;
130 bool can_migrate();
131 void OnPromiseHeaderList(QuicStreamId promised_id,
xunjieli 2017/05/08 19:51:00 This one doesn't seem to be test-only.
Ryan Hamilton 2017/05/08 20:58:06 I made it private, and the only error is from quic
xunjieli 2017/05/09 15:03:46 Acknowledged. I think I mistakenly assumed that th
Ryan Hamilton 2017/05/09 16:48:19 I so know the feeling! I keep going back and forth
132 size_t frame_len,
133 const QuicHeaderList& header_list);
134 Delegate* GetDelegate();
135
136 private:
137 friend class QuicChromiumClientStream;
138
139 // Constucts a new Handle for |stream| with |delegate| set to receive
140 // up calls on various events.
141 Handle(QuicChromiumClientStream* stream, Delegate* delegate);
142
143 // Methods invoked by the stream.
144 void OnInitialHeadersAvailable(const SpdyHeaderBlock& headers,
145 size_t frame_len);
146 void OnTrailingHeadersAvailable(const SpdyHeaderBlock& headers,
147 size_t frame_len);
148 void OnDataAvailable();
149 void OnClose();
150 void OnError(int error);
151
152 // Saves various fields from the stream before the stream goes away.
153 void SaveState();
154
155 QuicChromiumClientStream* stream_; // Unowned.
156 Delegate* delegate_; // Owns this.
xunjieli 2017/05/08 19:51:00 optional: I only see this commenting style in QUIC
Ryan Hamilton 2017/05/08 20:58:05 It appears to be used in other places in net too.
xunjieli 2017/05/09 15:03:46 Acknowledged. Good point.
157
158 QuicStreamId id_;
159 QuicErrorCode connection_error_;
160 QuicRstStreamErrorCode stream_error_;
161 bool fin_sent_;
162 bool fin_received_;
163 uint64_t stream_bytes_read_;
164 uint64_t stream_bytes_written_;
165 bool is_done_reading_;
166 bool is_first_stream_;
167 size_t num_bytes_consumed_;
168
169 DISALLOW_COPY_AND_ASSIGN(Handle);
170 };
171
64 QuicChromiumClientStream(QuicStreamId id, 172 QuicChromiumClientStream(QuicStreamId id,
65 QuicClientSessionBase* session, 173 QuicClientSessionBase* session,
66 const NetLogWithSource& net_log); 174 const NetLogWithSource& net_log);
67 175
68 ~QuicChromiumClientStream() override; 176 ~QuicChromiumClientStream() override;
69 177
70 // QuicSpdyStream 178 // QuicSpdyStream
71 void OnInitialHeadersComplete(bool fin, 179 void OnInitialHeadersComplete(bool fin,
72 size_t frame_len, 180 size_t frame_len,
73 const QuicHeaderList& header_list) override; 181 const QuicHeaderList& header_list) override;
(...skipping 18 matching lines...) Expand all
92 200
93 int WriteStreamData(QuicStringPiece data, 201 int WriteStreamData(QuicStringPiece data,
94 bool fin, 202 bool fin,
95 const CompletionCallback& callback); 203 const CompletionCallback& callback);
96 // Same as WriteStreamData except it writes data from a vector of IOBuffers, 204 // 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|. 205 // with the length of each buffer at the corresponding index in |lengths|.
98 int WritevStreamData(const std::vector<scoped_refptr<IOBuffer>>& buffers, 206 int WritevStreamData(const std::vector<scoped_refptr<IOBuffer>>& buffers,
99 const std::vector<int>& lengths, 207 const std::vector<int>& lengths,
100 bool fin, 208 bool fin,
101 const CompletionCallback& callback); 209 const CompletionCallback& callback);
102 // Set new |delegate|. |delegate| must not be NULL. 210
103 // If this stream has already received data, OnDataReceived() will be 211 // Creates a new Handle for this stream and sets |delegate| on the handle.
104 // called on the delegate. 212 // Must only be called once.
105 void SetDelegate(Delegate* delegate); 213 std::unique_ptr<QuicChromiumClientStream::Handle> CreateHandle(
106 Delegate* GetDelegate() { return delegate_; } 214 QuicChromiumClientStream::Delegate* delegate);
215
216 // Clears |handle_| from this stream.
217 void ClearHandle();
218
107 void OnError(int error); 219 void OnError(int error);
108 220
109 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read. 221 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read.
110 int Read(IOBuffer* buf, int buf_len); 222 int Read(IOBuffer* buf, int buf_len);
111 223
112 const NetLogWithSource& net_log() const { return net_log_; } 224 const NetLogWithSource& net_log() const { return net_log_; }
113 225
114 // Prevents this stream from migrating to a new network. May cause other 226 // Prevents this stream from migrating to a new network. May cause other
115 // concurrent streams within the session to also not migrate. 227 // concurrent streams within the session to also not migrate.
116 void DisableConnectionMigration(); 228 void DisableConnectionMigration();
117 229
118 bool can_migrate() { return can_migrate_; } 230 bool can_migrate() { return can_migrate_; }
119 231
120 // True if this stream is the first data stream created on this session. 232 // True if this stream is the first data stream created on this session.
121 bool IsFirstStream(); 233 bool IsFirstStream();
122 234
123 using QuicSpdyStream::HasBufferedData; 235 using QuicSpdyStream::HasBufferedData;
124 using QuicStream::sequencer; 236 using QuicStream::sequencer;
125 237
126 private: 238 private:
127 void NotifyDelegateOfInitialHeadersAvailableLater(SpdyHeaderBlock headers, 239 void NotifyHandleOfInitialHeadersAvailableLater(SpdyHeaderBlock headers,
128 size_t frame_len); 240 size_t frame_len);
129 void NotifyDelegateOfInitialHeadersAvailable(SpdyHeaderBlock headers, 241 void NotifyHandleOfInitialHeadersAvailable(SpdyHeaderBlock headers,
130 size_t frame_len); 242 size_t frame_len);
131 void NotifyDelegateOfTrailingHeadersAvailableLater(SpdyHeaderBlock headers, 243 void NotifyHandleOfTrailingHeadersAvailableLater(SpdyHeaderBlock headers,
132 size_t frame_len); 244 size_t frame_len);
133 void NotifyDelegateOfTrailingHeadersAvailable(SpdyHeaderBlock headers, 245 void NotifyHandleOfTrailingHeadersAvailable(SpdyHeaderBlock headers,
134 size_t frame_len); 246 size_t frame_len);
135 void NotifyDelegateOfDataAvailableLater(); 247 void NotifyHandleOfDataAvailableLater();
136 void NotifyDelegateOfDataAvailable(); 248 void NotifyHandleOfDataAvailable();
137 249
138 NetLogWithSource net_log_; 250 NetLogWithSource net_log_;
139 Delegate* delegate_; 251 Handle* handle_;
140 252
141 bool headers_delivered_; 253 bool headers_delivered_;
142 254
143 // True when initial headers have been sent. 255 // True when initial headers have been sent.
144 bool initial_headers_sent_; 256 bool initial_headers_sent_;
145 257
146 // Callback to be invoked when WriteStreamData or WritevStreamData completes 258 // Callback to be invoked when WriteStreamData or WritevStreamData completes
147 // asynchronously. 259 // asynchronously.
148 CompletionCallback write_callback_; 260 CompletionCallback write_callback_;
149 261
150 QuicClientSessionBase* session_; 262 QuicClientSessionBase* session_;
151 263
152 // Set to false if this stream to not be migrated during connection migration. 264 // Set to false if this stream to not be migrated during connection migration.
153 bool can_migrate_; 265 bool can_migrate_;
154 266
155 // Stores the initial header if they arrive before the delegate. 267 // Stores the initial header if they arrive before the delegate.
156 SpdyHeaderBlock initial_headers_; 268 SpdyHeaderBlock initial_headers_;
157 // Length of the HEADERS frame containing initial headers. 269 // Length of the HEADERS frame containing initial headers.
158 size_t initial_headers_frame_len_; 270 size_t initial_headers_frame_len_;
159 271
160 base::WeakPtrFactory<QuicChromiumClientStream> weak_factory_; 272 base::WeakPtrFactory<QuicChromiumClientStream> weak_factory_;
161 273
162 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientStream); 274 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientStream);
163 }; 275 };
164 276
165 } // namespace net 277 } // namespace net
166 278
167 #endif // NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_STREAM_H_ 279 #endif // NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698